pythagix 0.1.4__py3-none-any.whl → 0.1.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pythagix/__init__.py +1 -1
- pythagix/core.py +93 -77
- pythagix-0.1.7.dist-info/METADATA +103 -0
- pythagix-0.1.7.dist-info/RECORD +7 -0
- pythagix-0.1.4.dist-info/METADATA +0 -56
- pythagix-0.1.4.dist-info/RECORD +0 -7
- {pythagix-0.1.4.dist-info → pythagix-0.1.7.dist-info}/WHEEL +0 -0
- {pythagix-0.1.4.dist-info → pythagix-0.1.7.dist-info}/licenses/LICENSE +0 -0
- {pythagix-0.1.4.dist-info → pythagix-0.1.7.dist-info}/top_level.txt +0 -0
pythagix/__init__.py
CHANGED
pythagix/core.py
CHANGED
@@ -1,93 +1,101 @@
|
|
1
|
-
|
1
|
+
from math import isqrt
|
2
|
+
from functools import reduce
|
3
|
+
from typing import List
|
4
|
+
import math
|
5
|
+
|
6
|
+
__all__ = [
|
7
|
+
"is_prime",
|
8
|
+
"filter_primes",
|
9
|
+
"nth_prime",
|
10
|
+
"gcd",
|
11
|
+
"is_perfect_square",
|
12
|
+
"count_factors",
|
13
|
+
"triangle_number",
|
14
|
+
]
|
15
|
+
|
16
|
+
|
17
|
+
def is_prime(number: int) -> bool:
|
2
18
|
"""
|
3
|
-
|
19
|
+
Check whether a given integer is a prime number.
|
4
20
|
|
5
21
|
Args:
|
6
|
-
|
22
|
+
number (int): The number to check.
|
7
23
|
|
8
24
|
Returns:
|
9
|
-
|
25
|
+
bool: True if number is prime, False otherwise.
|
10
26
|
"""
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
return
|
27
|
+
if number <= 1:
|
28
|
+
return False
|
29
|
+
if number == 2:
|
30
|
+
return True
|
31
|
+
if number % 2 == 0:
|
32
|
+
return False
|
33
|
+
for i in range(3, isqrt(number) + 1, 2):
|
34
|
+
if number % i == 0:
|
35
|
+
return False
|
36
|
+
return True
|
21
37
|
|
22
38
|
|
23
|
-
def
|
39
|
+
def filter_primes(values: List[int]) -> List[int]:
|
24
40
|
"""
|
25
|
-
|
41
|
+
Filter and return the prime numbers from a list.
|
26
42
|
|
27
43
|
Args:
|
28
|
-
|
44
|
+
values (List[int]): A list of integers.
|
29
45
|
|
30
46
|
Returns:
|
31
|
-
|
47
|
+
List[int]: A list containing only the prime numbers.
|
32
48
|
"""
|
33
|
-
for
|
34
|
-
if number % y == 0:
|
35
|
-
return False
|
36
|
-
else:
|
37
|
-
return True
|
49
|
+
return [num for num in values if is_prime(num)]
|
38
50
|
|
39
51
|
|
40
|
-
def nth_prime(
|
52
|
+
def nth_prime(position: int) -> int:
|
41
53
|
"""
|
42
|
-
|
54
|
+
Get the N-th prime number (1-based index).
|
43
55
|
|
44
56
|
Args:
|
45
|
-
|
57
|
+
position (int): The index (1-based) of the prime number to find.
|
46
58
|
|
47
59
|
Returns:
|
48
|
-
int: The
|
60
|
+
int: The N-th prime number.
|
49
61
|
|
50
62
|
Raises:
|
51
|
-
ValueError: If
|
63
|
+
ValueError: If position < 1.
|
52
64
|
"""
|
53
|
-
if
|
54
|
-
raise ValueError("
|
65
|
+
if position < 1:
|
66
|
+
raise ValueError("Position must be >= 1")
|
55
67
|
|
56
|
-
count
|
57
|
-
|
68
|
+
count = 0
|
69
|
+
candidate = 2
|
58
70
|
while True:
|
59
|
-
if is_prime(
|
71
|
+
if is_prime(candidate):
|
60
72
|
count += 1
|
61
|
-
if count ==
|
62
|
-
return
|
63
|
-
|
73
|
+
if count == position:
|
74
|
+
return candidate
|
75
|
+
candidate += 1
|
64
76
|
|
65
77
|
|
66
|
-
def gcd(
|
78
|
+
def gcd(values: List[int]) -> int:
|
67
79
|
"""
|
68
|
-
|
80
|
+
Compute the greatest common divisor (GCD) of a list of integers.
|
69
81
|
|
70
82
|
Args:
|
71
|
-
|
83
|
+
values (List[int]): A list of integers.
|
72
84
|
|
73
85
|
Returns:
|
74
|
-
int: The
|
86
|
+
int: The GCD of the numbers.
|
87
|
+
|
88
|
+
Raises:
|
89
|
+
ValueError: If the list is empty.
|
75
90
|
"""
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
for number in number_list:
|
80
|
-
if number % num != 0:
|
81
|
-
break
|
82
|
-
else:
|
83
|
-
highest = num
|
84
|
-
num += 1
|
85
|
-
return highest
|
91
|
+
if not values:
|
92
|
+
raise ValueError("Input list must not be empty")
|
93
|
+
return reduce(math.gcd, values)
|
86
94
|
|
87
95
|
|
88
96
|
def is_perfect_square(number: int) -> bool:
|
89
97
|
"""
|
90
|
-
|
98
|
+
Check whether a number is a perfect square.
|
91
99
|
|
92
100
|
Args:
|
93
101
|
number (int): The number to check.
|
@@ -95,50 +103,58 @@ def is_perfect_square(number: int) -> bool:
|
|
95
103
|
Returns:
|
96
104
|
bool: True if the number is a perfect square, False otherwise.
|
97
105
|
"""
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
num += 1
|
103
|
-
return False
|
106
|
+
if number < 0:
|
107
|
+
return False
|
108
|
+
root = isqrt(number)
|
109
|
+
return root * root == number
|
104
110
|
|
105
111
|
|
106
|
-
def count_factors(number: int) ->
|
112
|
+
def count_factors(number: int) -> List[int]:
|
107
113
|
"""
|
108
|
-
|
114
|
+
Return all positive factors of a number.
|
109
115
|
|
110
116
|
Args:
|
111
|
-
number (int): The number to
|
117
|
+
number (int): The number whose factors are to be found.
|
112
118
|
|
113
119
|
Returns:
|
114
|
-
|
120
|
+
List[int]: A sorted list of factors.
|
121
|
+
|
122
|
+
Raises:
|
123
|
+
ValueError: If number is not positive.
|
115
124
|
"""
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
125
|
+
if number <= 0:
|
126
|
+
raise ValueError("Number must be positive")
|
127
|
+
|
128
|
+
factors = set()
|
129
|
+
for i in range(1, isqrt(number) + 1):
|
130
|
+
if number % i == 0:
|
131
|
+
factors.add(i)
|
132
|
+
factors.add(number // i)
|
133
|
+
return sorted(factors)
|
123
134
|
|
124
135
|
|
125
|
-
def triangle_number(
|
136
|
+
def triangle_number(index: int) -> int:
|
126
137
|
"""
|
127
|
-
|
138
|
+
Calculate the N-th triangular number.
|
128
139
|
|
129
140
|
Args:
|
130
|
-
|
141
|
+
index (int): The position (starting from 0) in the triangular number sequence.
|
131
142
|
|
132
143
|
Returns:
|
133
|
-
int: The
|
144
|
+
int: The N-th triangular number.
|
145
|
+
|
146
|
+
Raises:
|
147
|
+
ValueError: If index is negative.
|
134
148
|
"""
|
135
|
-
|
149
|
+
if index < 0:
|
150
|
+
raise ValueError("Index must be >= 0")
|
151
|
+
return index * (index + 1) // 2
|
136
152
|
|
137
153
|
|
138
|
-
|
154
|
+
def main() -> None:
|
155
|
+
"""Tester Function."""
|
156
|
+
...
|
139
157
|
|
140
|
-
def main():
|
141
|
-
"""Runs a quick test of any function."""
|
142
|
-
print(triangle_number(10))
|
143
158
|
|
159
|
+
if __name__ == "__main__":
|
144
160
|
main()
|
@@ -0,0 +1,103 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: pythagix
|
3
|
+
Version: 0.1.7
|
4
|
+
Summary: A mathy Python package with utilities like LCM, triangle numbers, etc.
|
5
|
+
Author: UltraQuantumScriptor
|
6
|
+
License: MIT
|
7
|
+
Keywords: math,prime,LCM,triangle numbers,gcd,utilities
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Requires-Python: >=3.6
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
License-File: LICENSE
|
13
|
+
Dynamic: license-file
|
14
|
+
Dynamic: requires-python
|
15
|
+
|
16
|
+
---
|
17
|
+
|
18
|
+
# 📦 Pythagix
|
19
|
+
|
20
|
+
**Pythagix** is a lightweight and dependency-free Python library designed for number theory operations.
|
21
|
+
It provides a clean, efficient interface to common mathematical utilities such as prime number checks, greatest common divisor computation, triangular numbers, and more.
|
22
|
+
|
23
|
+
---
|
24
|
+
|
25
|
+
## 📥 Installation
|
26
|
+
|
27
|
+
Install Pythagix using pip:
|
28
|
+
|
29
|
+
```bash
|
30
|
+
pip install pythagix
|
31
|
+
```
|
32
|
+
|
33
|
+
---
|
34
|
+
|
35
|
+
## Features
|
36
|
+
|
37
|
+
* `is_prime(number: int) -> bool`
|
38
|
+
Determine whether a number is a prime number.
|
39
|
+
|
40
|
+
* `filter_primes(numbers: List[int]) -> List[int]`
|
41
|
+
Return all prime numbers from a list of integers.
|
42
|
+
|
43
|
+
* `nth_prime(position: int) -> int`
|
44
|
+
Retrieve the *n*-th prime number (1-based indexing).
|
45
|
+
|
46
|
+
* `gcd(values: List[int]) -> int`
|
47
|
+
Compute the greatest common divisor (GCD) of a list of integers.
|
48
|
+
|
49
|
+
* `is_perfect_square(number: int) -> bool`
|
50
|
+
Check whether a number is a perfect square.
|
51
|
+
|
52
|
+
* `count_factors(number: int) -> List[int]`
|
53
|
+
Return a sorted list of all positive factors of a number.
|
54
|
+
|
55
|
+
* `triangle_number(index: int) -> int`
|
56
|
+
Compute the *n*-th triangular number.
|
57
|
+
|
58
|
+
---
|
59
|
+
|
60
|
+
## Example Usage
|
61
|
+
|
62
|
+
```python
|
63
|
+
from pythagix import is_prime, nth_prime, gcd, triangle_number
|
64
|
+
|
65
|
+
print(is_prime(13)) # Output: True
|
66
|
+
|
67
|
+
print(nth_prime(10)) # Output: 29
|
68
|
+
|
69
|
+
print(gcd([12, 18, 24])) # Output: 6
|
70
|
+
|
71
|
+
print(triangle_number(7)) # Output: 28
|
72
|
+
```
|
73
|
+
|
74
|
+
---
|
75
|
+
|
76
|
+
## Use Cases
|
77
|
+
|
78
|
+
Pythagix is ideal for:
|
79
|
+
|
80
|
+
* Educational platforms and math-related tools
|
81
|
+
|
82
|
+
* Prototyping algorithms and number-theoretic computations
|
83
|
+
|
84
|
+
* Teaching foundational concepts in discrete mathematics and number theory
|
85
|
+
|
86
|
+
* Lightweight CLI utilities and academic scripting
|
87
|
+
|
88
|
+
---
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
Pythagix is released under the [MIT License](LICENSE), making it free to use, modify, and distribute.
|
93
|
+
|
94
|
+
---
|
95
|
+
|
96
|
+
## Contributing
|
97
|
+
|
98
|
+
Contributions are welcome!
|
99
|
+
If you'd like to add features, report bugs, or improve documentation, please open an issue or submit a pull request on the [GitHub repository](https://github.com/your-username/pythagix).
|
100
|
+
|
101
|
+
---
|
102
|
+
|
103
|
+
If you want me to tailor this even more (e.g. add badges, GitHub Actions, versioning, or PyPI metadata snippets), I can assist with that too.
|
@@ -0,0 +1,7 @@
|
|
1
|
+
pythagix/__init__.py,sha256=6tpiGil3VFdLrZ9fUZ41YY7qAkNyWOC74fiUNCuXzAE,175
|
2
|
+
pythagix/core.py,sha256=-zmDFcEsfqL8G-cEY8CCfw1YA0_fDnRrLv4g-bxeews,3534
|
3
|
+
pythagix-0.1.7.dist-info/licenses/LICENSE,sha256=Qv2ilebwoUtMJnRsZwRy729xS5JZQzLauJ0tQzkAkTA,1088
|
4
|
+
pythagix-0.1.7.dist-info/METADATA,sha256=8vrKYFwTC1aKvY9_pmd9yLwK8E70qP7mFnfLe9wRz5Q,2679
|
5
|
+
pythagix-0.1.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
+
pythagix-0.1.7.dist-info/top_level.txt,sha256=U3rm-YGObQkL0gSuVWFPZTakILlqyAd7pUVvtJiMlsE,9
|
7
|
+
pythagix-0.1.7.dist-info/RECORD,,
|
@@ -1,56 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: pythagix
|
3
|
-
Version: 0.1.4
|
4
|
-
Summary: A mathy Python package with utilities like LCM, triangle numbers, etc.
|
5
|
-
Author: UltraQuantumScriptor
|
6
|
-
License: MIT
|
7
|
-
Classifier: Programming Language :: Python :: 3
|
8
|
-
Classifier: License :: OSI Approved :: MIT License
|
9
|
-
Requires-Python: >=3.6
|
10
|
-
Description-Content-Type: text/markdown
|
11
|
-
License-File: LICENSE
|
12
|
-
Dynamic: license-file
|
13
|
-
Dynamic: requires-python
|
14
|
-
|
15
|
-
# 🧠 pythagix
|
16
|
-
|
17
|
-
Math utilities for number nerds.
|
18
|
-
Check primes, compute triangle numbers, find GCDs — all in one lightweight package.
|
19
|
-
Because math shouldn't be a pain 🧮✨
|
20
|
-
|
21
|
-
---
|
22
|
-
|
23
|
-
## 📦 Installation
|
24
|
-
|
25
|
-
```bash
|
26
|
-
pip install pythagix
|
27
|
-
```
|
28
|
-
|
29
|
-
⚙️ Features
|
30
|
-
|
31
|
-
🔢 is_prime(number) — Check if a number is prime
|
32
|
-
|
33
|
-
📜 prime_list([list]) — Return all primes in a list
|
34
|
-
|
35
|
-
🔎 nth_prime(n) — Get the n-th prime number
|
36
|
-
|
37
|
-
🤝 gcd([list]) — Greatest common divisor of a list
|
38
|
-
|
39
|
-
📏 is_perfect_square(n) — Check if n is a perfect square
|
40
|
-
|
41
|
-
🧱 count_factors(n) — Get all factors of a number
|
42
|
-
|
43
|
-
🔺 triangle_number(n) — Get the n-th triangle number
|
44
|
-
|
45
|
-
🧪 Examples
|
46
|
-
```python
|
47
|
-
from pythagix import is_prime, nth_prime, gcd, triangle_number
|
48
|
-
|
49
|
-
print(is_prime(13)) # True
|
50
|
-
print(nth_prime(10)) # 29
|
51
|
-
print(gcd([12, 18, 24])) # 6
|
52
|
-
print(triangle_number(7)) # 28
|
53
|
-
```
|
54
|
-
|
55
|
-
📚 Why?
|
56
|
-
pythagix was built to give math students, coders, and tinkerers a fast and fun way to explore number theory in Python. No heavy dependencies. Just pure mathy goodness.
|
pythagix-0.1.4.dist-info/RECORD
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
pythagix/__init__.py,sha256=A9cw-DpCoP2SUMlHar8PK0OAUSiFLQwoApZzx7oMslg,172
|
2
|
-
pythagix/core.py,sha256=b5qw5ejc3-MsiNu4b4G6E-ILxaj8DyUI2tQwX1XP0bs,3395
|
3
|
-
pythagix-0.1.4.dist-info/licenses/LICENSE,sha256=Qv2ilebwoUtMJnRsZwRy729xS5JZQzLauJ0tQzkAkTA,1088
|
4
|
-
pythagix-0.1.4.dist-info/METADATA,sha256=THDZACzNVrTeErOXrlU8Z2aDg6_jsfDfwXV9lLljqbo,1513
|
5
|
-
pythagix-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
-
pythagix-0.1.4.dist-info/top_level.txt,sha256=U3rm-YGObQkL0gSuVWFPZTakILlqyAd7pUVvtJiMlsE,9
|
7
|
-
pythagix-0.1.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|