pythagix 0.1.6__py3-none-any.whl → 0.1.8__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/core.py +108 -46
- pythagix-0.1.8.dist-info/METADATA +103 -0
- pythagix-0.1.8.dist-info/RECORD +7 -0
- pythagix-0.1.6.dist-info/METADATA +0 -56
- pythagix-0.1.6.dist-info/RECORD +0 -7
- {pythagix-0.1.6.dist-info → pythagix-0.1.8.dist-info}/WHEEL +0 -0
- {pythagix-0.1.6.dist-info → pythagix-0.1.8.dist-info}/licenses/LICENSE +0 -0
- {pythagix-0.1.6.dist-info → pythagix-0.1.8.dist-info}/top_level.txt +0 -0
pythagix/core.py
CHANGED
@@ -14,85 +14,147 @@ __all__ = [
|
|
14
14
|
]
|
15
15
|
|
16
16
|
|
17
|
-
def is_prime(
|
18
|
-
"""
|
19
|
-
|
17
|
+
def is_prime(number: int) -> bool:
|
18
|
+
"""
|
19
|
+
Check whether a given integer is a prime number.
|
20
|
+
|
21
|
+
Args:
|
22
|
+
number (int): The number to check.
|
23
|
+
|
24
|
+
Returns:
|
25
|
+
bool: True if number is prime, False otherwise.
|
26
|
+
"""
|
27
|
+
if number <= 1:
|
20
28
|
return False
|
21
|
-
if
|
29
|
+
if number == 2:
|
22
30
|
return True
|
23
|
-
if
|
31
|
+
if number % 2 == 0:
|
24
32
|
return False
|
25
|
-
for i in range(3, isqrt(
|
26
|
-
if
|
33
|
+
for i in range(3, isqrt(number) + 1, 2):
|
34
|
+
if number % i == 0:
|
27
35
|
return False
|
28
36
|
return True
|
29
37
|
|
30
38
|
|
31
|
-
def filter_primes(
|
32
|
-
"""
|
33
|
-
|
39
|
+
def filter_primes(values: List[int]) -> List[int]:
|
40
|
+
"""
|
41
|
+
Filter and return the prime numbers from a list.
|
42
|
+
|
43
|
+
Args:
|
44
|
+
values (List[int]): A list of integers.
|
45
|
+
|
46
|
+
Returns:
|
47
|
+
List[int]: A list containing only the prime numbers.
|
48
|
+
"""
|
49
|
+
return [num for num in values if is_prime(num)]
|
50
|
+
|
34
51
|
|
52
|
+
def nth_prime(position: int) -> int:
|
53
|
+
"""
|
54
|
+
Get the N-th prime number (1-based index).
|
35
55
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
56
|
+
Args:
|
57
|
+
position (int): The index (1-based) of the prime number to find.
|
58
|
+
|
59
|
+
Returns:
|
60
|
+
int: The N-th prime number.
|
61
|
+
|
62
|
+
Raises:
|
63
|
+
ValueError: If position < 1.
|
64
|
+
"""
|
65
|
+
if position < 1:
|
66
|
+
raise ValueError("Position must be >= 1")
|
40
67
|
|
41
68
|
count = 0
|
42
69
|
candidate = 2
|
43
70
|
while True:
|
44
71
|
if is_prime(candidate):
|
45
72
|
count += 1
|
46
|
-
if count ==
|
73
|
+
if count == position:
|
47
74
|
return candidate
|
48
75
|
candidate += 1
|
49
76
|
|
50
77
|
|
51
|
-
def gcd(
|
52
|
-
"""
|
53
|
-
|
54
|
-
|
55
|
-
|
78
|
+
def gcd(values: List[int]) -> int:
|
79
|
+
"""
|
80
|
+
Compute the greatest common divisor (GCD) of a list of integers.
|
81
|
+
|
82
|
+
Args:
|
83
|
+
values (List[int]): A list of integers.
|
84
|
+
|
85
|
+
Returns:
|
86
|
+
int: The GCD of the numbers.
|
87
|
+
|
88
|
+
Raises:
|
89
|
+
ValueError: If the list is empty.
|
90
|
+
"""
|
91
|
+
if not values:
|
92
|
+
raise ValueError("Input list must not be empty")
|
93
|
+
return reduce(math.gcd, values)
|
56
94
|
|
57
95
|
|
58
|
-
def is_perfect_square(
|
59
|
-
"""
|
60
|
-
|
96
|
+
def is_perfect_square(number: int) -> bool:
|
97
|
+
"""
|
98
|
+
Check whether a number is a perfect square.
|
99
|
+
|
100
|
+
Args:
|
101
|
+
number (int): The number to check.
|
102
|
+
|
103
|
+
Returns:
|
104
|
+
bool: True if the number is a perfect square, False otherwise.
|
105
|
+
"""
|
106
|
+
if number < 0:
|
61
107
|
return False
|
62
|
-
root = isqrt(
|
63
|
-
return root * root ==
|
108
|
+
root = isqrt(number)
|
109
|
+
return root * root == number
|
110
|
+
|
111
|
+
|
112
|
+
def count_factors(number: int) -> List[int]:
|
113
|
+
"""
|
114
|
+
Return all positive factors of a number.
|
115
|
+
|
116
|
+
Args:
|
117
|
+
number (int): The number whose factors are to be found.
|
64
118
|
|
119
|
+
Returns:
|
120
|
+
List[int]: A sorted list of factors.
|
65
121
|
|
66
|
-
|
67
|
-
|
68
|
-
|
122
|
+
Raises:
|
123
|
+
ValueError: If number is not positive.
|
124
|
+
"""
|
125
|
+
if number <= 0:
|
69
126
|
raise ValueError("Number must be positive")
|
70
127
|
|
71
128
|
factors = set()
|
72
|
-
for i in range(1, isqrt(
|
73
|
-
if
|
129
|
+
for i in range(1, isqrt(number) + 1):
|
130
|
+
if number % i == 0:
|
74
131
|
factors.add(i)
|
75
|
-
factors.add(
|
132
|
+
factors.add(number // i)
|
76
133
|
return sorted(factors)
|
77
134
|
|
78
135
|
|
79
|
-
def triangle_number(
|
80
|
-
"""
|
81
|
-
|
82
|
-
raise ValueError("n must be >= 0")
|
83
|
-
return n * (n + 1) // 2
|
136
|
+
def triangle_number(index: int) -> int:
|
137
|
+
"""
|
138
|
+
Calculate the N-th triangular number.
|
84
139
|
|
140
|
+
Args:
|
141
|
+
index (int): The position (starting from 0) in the triangular number sequence.
|
142
|
+
|
143
|
+
Returns:
|
144
|
+
int: The N-th triangular number.
|
145
|
+
|
146
|
+
Raises:
|
147
|
+
ValueError: If index is negative.
|
148
|
+
"""
|
149
|
+
if index < 0:
|
150
|
+
raise ValueError("Index must be >= 0")
|
151
|
+
return index * (index + 1) // 2
|
85
152
|
|
86
|
-
# Quick test zone
|
87
|
-
if __name__ == "__main__":
|
88
153
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
print("5th Prime:", nth_prime(5))
|
93
|
-
print("GCD of [12, 18, 24]:", gcd([12, 18, 24]))
|
94
|
-
print("Is 49 perfect square?", is_perfect_square(49))
|
95
|
-
print("Factors of 28:", count_factors(28))
|
96
|
-
print("7th triangle number:", triangle_number(7))
|
154
|
+
def main() -> None:
|
155
|
+
"""Tester Function."""
|
156
|
+
...
|
97
157
|
|
158
|
+
|
159
|
+
if __name__ == "__main__":
|
98
160
|
main()
|
@@ -0,0 +1,103 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: pythagix
|
3
|
+
Version: 0.1.8
|
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.8.dist-info/licenses/LICENSE,sha256=Qv2ilebwoUtMJnRsZwRy729xS5JZQzLauJ0tQzkAkTA,1088
|
4
|
+
pythagix-0.1.8.dist-info/METADATA,sha256=9PwgsSy98be7P03BuTsAXC0jES0pufTSQ2kQxTU2JQU,2669
|
5
|
+
pythagix-0.1.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
+
pythagix-0.1.8.dist-info/top_level.txt,sha256=U3rm-YGObQkL0gSuVWFPZTakILlqyAd7pUVvtJiMlsE,9
|
7
|
+
pythagix-0.1.8.dist-info/RECORD,,
|
@@ -1,56 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: pythagix
|
3
|
-
Version: 0.1.6
|
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
|
-
Pythagix
|
17
|
-
|
18
|
-
Pythagix is a lightweight Python utility library for working with number theory.
|
19
|
-
It offers essential math functions like checking primes, computing triangle numbers, finding GCDs, and more — all in a fast, dependency-free package.
|
20
|
-
|
21
|
-
Installation
|
22
|
-
|
23
|
-
```bash
|
24
|
-
pip install pythagix
|
25
|
-
```
|
26
|
-
Features
|
27
|
-
|
28
|
-
is_prime(number) — Check if a number is prime
|
29
|
-
|
30
|
-
prime_list(numbers: list) — Return all prime numbers from a list
|
31
|
-
|
32
|
-
nth_prime(n) — Get the n-th prime number
|
33
|
-
|
34
|
-
gcd(numbers: list) — Compute the greatest common divisor of a list
|
35
|
-
|
36
|
-
is_perfect_square(n) — Check if a number is a perfect square
|
37
|
-
|
38
|
-
count_factors(n) — Count the total number of factors of a number
|
39
|
-
|
40
|
-
triangle_number(n) — Compute the n-th triangle number
|
41
|
-
|
42
|
-
Example Usage
|
43
|
-
|
44
|
-
```python
|
45
|
-
from pythagix import is_prime, nth_prime, gcd, triangle_number
|
46
|
-
|
47
|
-
print(is_prime(13)) # True
|
48
|
-
print(nth_prime(10)) # 29
|
49
|
-
print(gcd([12, 18, 24])) # 6
|
50
|
-
print(triangle_number(7)) # 28
|
51
|
-
```
|
52
|
-
|
53
|
-
About
|
54
|
-
|
55
|
-
Pythagix was built to give students, developers, and math enthusiasts a clean and simple way to explore number theory in Python.
|
56
|
-
It is ideal for learning, prototyping, or educational tools.
|
pythagix-0.1.6.dist-info/RECORD
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
pythagix/__init__.py,sha256=6tpiGil3VFdLrZ9fUZ41YY7qAkNyWOC74fiUNCuXzAE,175
|
2
|
-
pythagix/core.py,sha256=RSL6W9NgMGRR3rVkPubpem7errcUFD5RrHF1mdTmDJ8,2425
|
3
|
-
pythagix-0.1.6.dist-info/licenses/LICENSE,sha256=Qv2ilebwoUtMJnRsZwRy729xS5JZQzLauJ0tQzkAkTA,1088
|
4
|
-
pythagix-0.1.6.dist-info/METADATA,sha256=GiOg5JBsM7Kv7vj1G7EDDUYcOe1PRNaIIj5F9f_W0Do,1659
|
5
|
-
pythagix-0.1.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
-
pythagix-0.1.6.dist-info/top_level.txt,sha256=U3rm-YGObQkL0gSuVWFPZTakILlqyAd7pUVvtJiMlsE,9
|
7
|
-
pythagix-0.1.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|