pythagix 0.1.9__tar.gz → 0.2.2__tar.gz

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.
@@ -0,0 +1,100 @@
1
+ Metadata-Version: 2.4
2
+ Name: pythagix
3
+ Version: 0.2.2
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, dependency-free Python library for number theory operations.
19
+ It provides a clean and efficient interface for common mathematical utilities such as prime checking, greatest common divisor, triangular numbers, and more.
20
+
21
+ ---
22
+
23
+
24
+ Installation
25
+
26
+ You can install Pythagix using pip:
27
+
28
+ ```bash
29
+ pip install pythagix
30
+ ```
31
+
32
+
33
+ Features
34
+
35
+ count_factors(number: int) -> List[int]
36
+ Returns a sorted list of all positive factors of the given number.
37
+
38
+ digit_sum(number: int) -> int
39
+ Returns the sum of all digits in the given number.
40
+
41
+ filter_primes(values: List[int]) -> List[int]
42
+ Filters and returns prime numbers from a list of integers.
43
+
44
+ gcd(values: List[int]) -> int
45
+ Computes the greatest common divisor (GCD) of a list of integers.
46
+
47
+ is_perfect_square(number: int) -> bool
48
+ Determines whether a number is a perfect square.
49
+
50
+ is_prime(number: int) -> bool
51
+ Checks whether a number is prime.
52
+
53
+ is_multiple(number: int, base: int) -> bool
54
+ Checks if one number is a multiple of another.
55
+
56
+ lcm(values: List[int]) -> int
57
+ Computes the least common multiple (LCM) of a list of integers.
58
+
59
+ mean(values: List[int | float]) -> float
60
+ Calculates the arithmetic mean (average) of a list of numbers.
61
+
62
+ median(values: List[int | float]) -> float
63
+ Computes the median value of a list.
64
+
65
+ middle(a: int | float, b: int | float) -> float
66
+ Returns the midpoint of two numeric values.
67
+
68
+ mode(values: List[int | float]) -> int | float | List[int | float]
69
+ Computes the mode(s) of a list. Returns a single value or a list of modes.
70
+
71
+ nth_prime(position: int) -> int
72
+ Retrieves the n-th prime number (1-based index).
73
+
74
+ triangle_number(index: int) -> int
75
+ Computes the n-th triangular number.
76
+
77
+
78
+ Use Cases
79
+
80
+ Pythagix is suitable for:
81
+
82
+ Educational platforms and math-related applications
83
+
84
+ Prototyping number-theoretic algorithms
85
+
86
+ Teaching foundational concepts in discrete mathematics
87
+
88
+ Lightweight command-line tools and academic scripting
89
+
90
+
91
+ License
92
+
93
+ This project is licensed under the MIT License.
94
+ You are free to use, modify, and distribute the software as permitted under the license terms.
95
+
96
+ Contributing
97
+
98
+ Contributions are welcome.
99
+
100
+ To report bugs, suggest enhancements, or submit code improvements, please open an issue or create a pull request via the GitHub repository.
@@ -0,0 +1,85 @@
1
+ # Pythagix
2
+
3
+ Pythagix is a lightweight, dependency-free Python library for number theory operations.
4
+ It provides a clean and efficient interface for common mathematical utilities such as prime checking, greatest common divisor, triangular numbers, and more.
5
+
6
+ ---
7
+
8
+
9
+ Installation
10
+
11
+ You can install Pythagix using pip:
12
+
13
+ ```bash
14
+ pip install pythagix
15
+ ```
16
+
17
+
18
+ Features
19
+
20
+ count_factors(number: int) -> List[int]
21
+ Returns a sorted list of all positive factors of the given number.
22
+
23
+ digit_sum(number: int) -> int
24
+ Returns the sum of all digits in the given number.
25
+
26
+ filter_primes(values: List[int]) -> List[int]
27
+ Filters and returns prime numbers from a list of integers.
28
+
29
+ gcd(values: List[int]) -> int
30
+ Computes the greatest common divisor (GCD) of a list of integers.
31
+
32
+ is_perfect_square(number: int) -> bool
33
+ Determines whether a number is a perfect square.
34
+
35
+ is_prime(number: int) -> bool
36
+ Checks whether a number is prime.
37
+
38
+ is_multiple(number: int, base: int) -> bool
39
+ Checks if one number is a multiple of another.
40
+
41
+ lcm(values: List[int]) -> int
42
+ Computes the least common multiple (LCM) of a list of integers.
43
+
44
+ mean(values: List[int | float]) -> float
45
+ Calculates the arithmetic mean (average) of a list of numbers.
46
+
47
+ median(values: List[int | float]) -> float
48
+ Computes the median value of a list.
49
+
50
+ middle(a: int | float, b: int | float) -> float
51
+ Returns the midpoint of two numeric values.
52
+
53
+ mode(values: List[int | float]) -> int | float | List[int | float]
54
+ Computes the mode(s) of a list. Returns a single value or a list of modes.
55
+
56
+ nth_prime(position: int) -> int
57
+ Retrieves the n-th prime number (1-based index).
58
+
59
+ triangle_number(index: int) -> int
60
+ Computes the n-th triangular number.
61
+
62
+
63
+ Use Cases
64
+
65
+ Pythagix is suitable for:
66
+
67
+ Educational platforms and math-related applications
68
+
69
+ Prototyping number-theoretic algorithms
70
+
71
+ Teaching foundational concepts in discrete mathematics
72
+
73
+ Lightweight command-line tools and academic scripting
74
+
75
+
76
+ License
77
+
78
+ This project is licensed under the MIT License.
79
+ You are free to use, modify, and distribute the software as permitted under the license terms.
80
+
81
+ Contributing
82
+
83
+ Contributions are welcome.
84
+
85
+ To report bugs, suggest enhancements, or submit code improvements, please open an issue or create a pull request via the GitHub repository.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pythagix"
3
- version = "0.1.9"
3
+ version = "0.2.2"
4
4
  description = "A mathy Python package with utilities like LCM, triangle numbers, etc."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.6"
@@ -1,10 +1,17 @@
1
1
  # pythagix/__init__.py
2
2
  from .core import (
3
+ count_factors,
4
+ digit_sum,
3
5
  filter_primes,
4
- is_prime,
5
- nth_prime,
6
6
  gcd,
7
7
  is_perfect_square,
8
- count_factors,
8
+ is_prime,
9
+ is_multiple,
10
+ lcm,
11
+ mean,
12
+ median,
13
+ middle,
14
+ mode,
15
+ nth_prime,
9
16
  triangle_number,
10
17
  )
@@ -0,0 +1,306 @@
1
+ import math as m
2
+ from functools import reduce
3
+ from typing import List, Union
4
+ from collections import Counter
5
+
6
+ Numeric = Union[int, float]
7
+
8
+ __all__ = [
9
+ "count_factors",
10
+ "digit_sum",
11
+ "filter_primes",
12
+ "gcd",
13
+ "is_perfect_square",
14
+ "is_prime",
15
+ "is_multiple",
16
+ "lcm",
17
+ "mean",
18
+ "median",
19
+ "middle",
20
+ "mode",
21
+ "nth_prime",
22
+ "triangle_number",
23
+ ]
24
+
25
+
26
+ def is_prime(number: int) -> bool:
27
+ """
28
+ Check whether a given integer is a prime number.
29
+
30
+ Args:
31
+ number (int): The number to check.
32
+
33
+ Returns:
34
+ bool: True if the number is prime, False otherwise.
35
+ """
36
+ if number <= 1:
37
+ return False
38
+ if number == 2:
39
+ return True
40
+ if number % 2 == 0:
41
+ return False
42
+ for i in range(3, m.isqrt(number) + 1, 2):
43
+ if number % i == 0:
44
+ return False
45
+ return True
46
+
47
+
48
+ def filter_primes(values: List[int]) -> List[int]:
49
+ """
50
+ Filter and return the prime numbers from a list.
51
+
52
+ Args:
53
+ values (List[int]): A list of integers.
54
+
55
+ Returns:
56
+ List[int]: A list containing only the prime numbers.
57
+ """
58
+ return [num for num in values if is_prime(num)]
59
+
60
+
61
+ def nth_prime(position: int) -> int:
62
+ """
63
+ Get the N-th prime number (1-based index).
64
+
65
+ Args:
66
+ position (int): The index (1-based) of the prime number to find.
67
+
68
+ Returns:
69
+ int: The N-th prime number.
70
+
71
+ Raises:
72
+ ValueError: If position < 1.
73
+ """
74
+ if position < 1:
75
+ raise ValueError("Position must be >= 1")
76
+
77
+ count = 0
78
+ candidate = 2
79
+ while True:
80
+ if is_prime(candidate):
81
+ count += 1
82
+ if count == position:
83
+ return candidate
84
+ candidate += 1
85
+
86
+
87
+ def gcd(values: List[int]) -> int:
88
+ """
89
+ Compute the greatest common divisor (GCD) of a list of integers.
90
+
91
+ Args:
92
+ values (List[int]): A list of integers.
93
+
94
+ Returns:
95
+ int: The GCD of the numbers.
96
+
97
+ Raises:
98
+ ValueError: If the list is empty.
99
+ """
100
+ if not values:
101
+ raise ValueError("Input list must not be empty")
102
+ return reduce(m.gcd, values)
103
+
104
+
105
+ def is_perfect_square(number: int) -> bool:
106
+ """
107
+ Check whether a number is a perfect square.
108
+
109
+ Args:
110
+ number (int): The number to check.
111
+
112
+ Returns:
113
+ bool: True if the number is a perfect square, False otherwise.
114
+ """
115
+ if number < 0:
116
+ return False
117
+ root = m.isqrt(number)
118
+ return root * root == number
119
+
120
+
121
+ def count_factors(number: int) -> List[int]:
122
+ """
123
+ Return all positive factors of a number.
124
+
125
+ Args:
126
+ number (int): The number whose factors are to be found.
127
+
128
+ Returns:
129
+ List[int]: A sorted list of factors.
130
+
131
+ Raises:
132
+ ValueError: If the number is not positive.
133
+ """
134
+ if number <= 0:
135
+ raise ValueError("Number must be positive")
136
+
137
+ factors = set()
138
+ for i in range(1, m.isqrt(number) + 1):
139
+ if number % i == 0:
140
+ factors.add(i)
141
+ factors.add(number // i)
142
+ return sorted(factors)
143
+
144
+
145
+ def triangle_number(index: int) -> int:
146
+ """
147
+ Calculate the N-th triangular number.
148
+
149
+ Args:
150
+ index (int): The position (starting from 0) in the triangular number sequence.
151
+
152
+ Returns:
153
+ int: The N-th triangular number.
154
+
155
+ Raises:
156
+ ValueError: If the index is negative.
157
+ """
158
+ if index < 0:
159
+ raise ValueError("Index must be >= 0")
160
+ return index * (index + 1) // 2
161
+
162
+
163
+ def lcm(values: List[int]) -> int:
164
+ """
165
+ Compute the least common multiple (LCM) of a list of integers.
166
+
167
+ Args:
168
+ values (List[int]): A list of integers.
169
+
170
+ Returns:
171
+ int: The LCM of the numbers.
172
+
173
+ Raises:
174
+ ValueError: If the list is empty.
175
+ """
176
+ if not values:
177
+ raise ValueError("Input list must not be empty")
178
+
179
+ return reduce(m.lcm, values)
180
+
181
+
182
+ def digit_sum(number: int) -> int:
183
+ """
184
+ Sum all digits of the given number.
185
+
186
+ Args:
187
+ number (int): The number whose digits are to be summed.
188
+
189
+ Returns:
190
+ int: The sum of the digits in the number.
191
+ """
192
+ return sum(int(digit) for digit in str(number))
193
+
194
+
195
+ def is_multiple(number: int, base: int) -> bool:
196
+ """
197
+ Check if a number is a multiple of another number.
198
+
199
+ Args:
200
+ number (int): The number to test.
201
+ base (int): The base to check against.
202
+
203
+ Returns:
204
+ bool: True if number is a multiple of base, False otherwise.
205
+ """
206
+ return number % base == 0
207
+
208
+
209
+ def middle(a: Numeric, b: Numeric) -> float:
210
+ """
211
+ Return the midpoint between two numbers.
212
+
213
+ Args:
214
+ a (int | float): The first number.
215
+ b (int | float): The second number.
216
+
217
+ Returns:
218
+ float: The average of the two numbers.
219
+ """
220
+ return (a + b) / 2
221
+
222
+
223
+ def mean(values: List[Numeric]) -> float:
224
+ """
225
+ Calculate the mean (average) of a list of numbers.
226
+
227
+ Args:
228
+ values (List[int | float]): A list of integers or floats.
229
+
230
+ Returns:
231
+ float: The mean of the list.
232
+
233
+ Raises:
234
+ ValueError: If the input list is empty.
235
+ """
236
+ if not values:
237
+ raise ValueError("Must contain at least one data point")
238
+
239
+ total = 0
240
+ for number in values:
241
+ total += number
242
+
243
+ return total / len(values)
244
+
245
+
246
+ def median(values: List[Numeric]) -> float:
247
+ """
248
+ Calculate the median of a list of numbers.
249
+
250
+ Args:
251
+ values (List[int | float]): A list of integers or floats.
252
+
253
+ Returns:
254
+ float: The median of the list.
255
+
256
+ Raises:
257
+ ValueError: If the input list is empty.
258
+ """
259
+ if not values:
260
+ raise ValueError("Must contain at least one data point")
261
+
262
+ values = sorted(values)
263
+ length = len(values)
264
+ mid = length // 2
265
+
266
+ if length % 2 == 1:
267
+ return float(values[mid])
268
+ else:
269
+ return middle(values[mid - 1], values[mid])
270
+
271
+
272
+ def mode(values: List[Numeric]) -> Union[Numeric, List[Numeric]]:
273
+ """
274
+ Compute the mode(s) of a list of numeric values.
275
+
276
+ The mode is the number that appears most frequently in the list.
277
+ If multiple numbers have the same highest frequency, all such numbers are returned as a list.
278
+ If only one number has the highest frequency, that single value is returned.
279
+
280
+ Args:
281
+ values (List[int | float]): A list of integers or floats.
282
+
283
+ Returns:
284
+ int | float | List[int | float]:
285
+ The mode of the list. Returns a single value if there's one mode,
286
+ or a list of values if multiple modes exist.
287
+
288
+ Raises:
289
+ ValueError: If the input list is empty.
290
+ """
291
+ if not values:
292
+ raise ValueError("Input list must not be empty")
293
+
294
+ frequency = Counter(values)
295
+ highest = max(frequency.values())
296
+ modes = [number for number, count in frequency.items() if count == highest]
297
+
298
+ return modes[0] if len(modes) == 1 else modes
299
+
300
+
301
+ if __name__ == "__main__":
302
+
303
+ def main() -> None:
304
+ """Tester Function."""
305
+
306
+ main()
@@ -0,0 +1,100 @@
1
+ Metadata-Version: 2.4
2
+ Name: pythagix
3
+ Version: 0.2.2
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, dependency-free Python library for number theory operations.
19
+ It provides a clean and efficient interface for common mathematical utilities such as prime checking, greatest common divisor, triangular numbers, and more.
20
+
21
+ ---
22
+
23
+
24
+ Installation
25
+
26
+ You can install Pythagix using pip:
27
+
28
+ ```bash
29
+ pip install pythagix
30
+ ```
31
+
32
+
33
+ Features
34
+
35
+ count_factors(number: int) -> List[int]
36
+ Returns a sorted list of all positive factors of the given number.
37
+
38
+ digit_sum(number: int) -> int
39
+ Returns the sum of all digits in the given number.
40
+
41
+ filter_primes(values: List[int]) -> List[int]
42
+ Filters and returns prime numbers from a list of integers.
43
+
44
+ gcd(values: List[int]) -> int
45
+ Computes the greatest common divisor (GCD) of a list of integers.
46
+
47
+ is_perfect_square(number: int) -> bool
48
+ Determines whether a number is a perfect square.
49
+
50
+ is_prime(number: int) -> bool
51
+ Checks whether a number is prime.
52
+
53
+ is_multiple(number: int, base: int) -> bool
54
+ Checks if one number is a multiple of another.
55
+
56
+ lcm(values: List[int]) -> int
57
+ Computes the least common multiple (LCM) of a list of integers.
58
+
59
+ mean(values: List[int | float]) -> float
60
+ Calculates the arithmetic mean (average) of a list of numbers.
61
+
62
+ median(values: List[int | float]) -> float
63
+ Computes the median value of a list.
64
+
65
+ middle(a: int | float, b: int | float) -> float
66
+ Returns the midpoint of two numeric values.
67
+
68
+ mode(values: List[int | float]) -> int | float | List[int | float]
69
+ Computes the mode(s) of a list. Returns a single value or a list of modes.
70
+
71
+ nth_prime(position: int) -> int
72
+ Retrieves the n-th prime number (1-based index).
73
+
74
+ triangle_number(index: int) -> int
75
+ Computes the n-th triangular number.
76
+
77
+
78
+ Use Cases
79
+
80
+ Pythagix is suitable for:
81
+
82
+ Educational platforms and math-related applications
83
+
84
+ Prototyping number-theoretic algorithms
85
+
86
+ Teaching foundational concepts in discrete mathematics
87
+
88
+ Lightweight command-line tools and academic scripting
89
+
90
+
91
+ License
92
+
93
+ This project is licensed under the MIT License.
94
+ You are free to use, modify, and distribute the software as permitted under the license terms.
95
+
96
+ Contributing
97
+
98
+ Contributions are welcome.
99
+
100
+ To report bugs, suggest enhancements, or submit code improvements, please open an issue or create a pull request via the GitHub repository.
@@ -6,7 +6,7 @@ with open("README.md", encoding="utf-8") as f:
6
6
 
7
7
  setup(
8
8
  name="pythagix",
9
- version="0.1.9",
9
+ version="0.2.2",
10
10
  author="UltraQuantumScriptor",
11
11
  description="A mathy Python package with utilities like LCM, triangle numbers, etc.",
12
12
  long_description=long_description,
pythagix-0.1.9/PKG-INFO DELETED
@@ -1,103 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: pythagix
3
- Version: 0.1.9
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.
pythagix-0.1.9/README.md DELETED
@@ -1,88 +0,0 @@
1
- ---
2
-
3
- # Pythagix
4
-
5
- **Pythagix** is a lightweight and dependency-free Python library designed for number theory operations.
6
- It provides a clean, efficient interface to common mathematical utilities such as prime number checks, greatest common divisor computation, triangular numbers, and more.
7
-
8
- ---
9
-
10
- ## Installation
11
-
12
- Install Pythagix using pip:
13
-
14
- ```bash
15
- pip install pythagix
16
- ```
17
-
18
- ---
19
-
20
- ## Features
21
-
22
- * `is_prime(number: int) -> bool`
23
- Determine whether a number is a prime number.
24
-
25
- * `filter_primes(numbers: List[int]) -> List[int]`
26
- Return all prime numbers from a list of integers.
27
-
28
- * `nth_prime(position: int) -> int`
29
- Retrieve the *n*-th prime number (1-based indexing).
30
-
31
- * `gcd(values: List[int]) -> int`
32
- Compute the greatest common divisor (GCD) of a list of integers.
33
-
34
- * `is_perfect_square(number: int) -> bool`
35
- Check whether a number is a perfect square.
36
-
37
- * `count_factors(number: int) -> List[int]`
38
- Return a sorted list of all positive factors of a number.
39
-
40
- * `triangle_number(index: int) -> int`
41
- Compute the *n*-th triangular number.
42
-
43
- ---
44
-
45
- ## Example Usage
46
-
47
- ```python
48
- from pythagix import is_prime, nth_prime, gcd, triangle_number
49
-
50
- print(is_prime(13)) # Output: True
51
-
52
- print(nth_prime(10)) # Output: 29
53
-
54
- print(gcd([12, 18, 24])) # Output: 6
55
-
56
- print(triangle_number(7)) # Output: 28
57
- ```
58
-
59
- ---
60
-
61
- ## Use Cases
62
-
63
- Pythagix is ideal for:
64
-
65
- * Educational platforms and math-related tools
66
-
67
- * Prototyping algorithms and number-theoretic computations
68
-
69
- * Teaching foundational concepts in discrete mathematics and number theory
70
-
71
- * Lightweight CLI utilities and academic scripting
72
-
73
- ---
74
-
75
- ## License
76
-
77
- Pythagix is released under the [MIT License](LICENSE), making it free to use, modify, and distribute.
78
-
79
- ---
80
-
81
- ## Contributing
82
-
83
- Contributions are welcome!
84
- 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).
85
-
86
- ---
87
-
88
- 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.
@@ -1,182 +0,0 @@
1
- import math as m
2
- from functools import reduce
3
- from typing import List
4
-
5
- __all__ = [
6
- "is_prime",
7
- "filter_primes",
8
- "nth_prime",
9
- "gcd",
10
- "is_perfect_square",
11
- "count_factors",
12
- "triangle_number",
13
- ]
14
-
15
-
16
- def is_prime(number: int) -> bool:
17
- """
18
- Check whether a given integer is a prime number.
19
-
20
- Args:
21
- number (int): The number to check.
22
-
23
- Returns:
24
- bool: True if number is prime, False otherwise.
25
- """
26
- if number <= 1:
27
- return False
28
- if number == 2:
29
- return True
30
- if number % 2 == 0:
31
- return False
32
- for i in range(3, m.isqrt(number) + 1, 2):
33
- if number % i == 0:
34
- return False
35
- return True
36
-
37
-
38
- def filter_primes(values: List[int]) -> List[int]:
39
- """
40
- Filter and return the prime numbers from a list.
41
-
42
- Args:
43
- values (List[int]): A list of integers.
44
-
45
- Returns:
46
- List[int]: A list containing only the prime numbers.
47
- """
48
- return [num for num in values if is_prime(num)]
49
-
50
-
51
- def nth_prime(position: int) -> int:
52
- """
53
- Get the N-th prime number (1-based index).
54
-
55
- Args:
56
- position (int): The index (1-based) of the prime number to find.
57
-
58
- Returns:
59
- int: The N-th prime number.
60
-
61
- Raises:
62
- ValueError: If position < 1.
63
- """
64
- if position < 1:
65
- raise ValueError("Position must be >= 1")
66
-
67
- count = 0
68
- candidate = 2
69
- while True:
70
- if is_prime(candidate):
71
- count += 1
72
- if count == position:
73
- return candidate
74
- candidate += 1
75
-
76
-
77
- def gcd(values: List[int]) -> int:
78
- """
79
- Compute the greatest common divisor (GCD) of a list of integers.
80
-
81
- Args:
82
- values (List[int]): A list of integers.
83
-
84
- Returns:
85
- int: The GCD of the numbers.
86
-
87
- Raises:
88
- ValueError: If the list is empty.
89
- """
90
- if not values:
91
- raise ValueError("Input list must not be empty")
92
- return reduce(m.gcd, values)
93
-
94
-
95
- def is_perfect_square(number: int) -> bool:
96
- """
97
- Check whether a number is a perfect square.
98
-
99
- Args:
100
- number (int): The number to check.
101
-
102
- Returns:
103
- bool: True if the number is a perfect square, False otherwise.
104
- """
105
- if number < 0:
106
- return False
107
- root = m.isqrt(number)
108
- return root * root == number
109
-
110
-
111
- def count_factors(number: int) -> List[int]:
112
- """
113
- Return all positive factors of a number.
114
-
115
- Args:
116
- number (int): The number whose factors are to be found.
117
-
118
- Returns:
119
- List[int]: A sorted list of factors.
120
-
121
- Raises:
122
- ValueError: If number is not positive.
123
- """
124
- if number <= 0:
125
- raise ValueError("Number must be positive")
126
-
127
- factors = set()
128
- for i in range(1, m.isqrt(number) + 1):
129
- if number % i == 0:
130
- factors.add(i)
131
- factors.add(number // i)
132
- return sorted(factors)
133
-
134
-
135
- def triangle_number(index: int) -> int:
136
- """
137
- Calculate the N-th triangular number.
138
-
139
- Args:
140
- index (int): The position (starting from 0) in the triangular number sequence.
141
-
142
- Returns:
143
- int: The N-th triangular number.
144
-
145
- Raises:
146
- ValueError: If index is negative.
147
- """
148
- if index < 0:
149
- raise ValueError("Index must be >= 0")
150
- return index * (index + 1) // 2
151
-
152
-
153
- def lcm(values: List[int]) -> int:
154
- """
155
- Compute the least common multiple (LCM) of a list of integers.
156
-
157
- Args:
158
- values (List[int]): A list of integers.
159
-
160
- Returns:
161
- int: The LCM of the numbers.
162
-
163
- Raises:
164
- ValueError: If the list is empty.
165
- """
166
- if not values:
167
- raise ValueError("Input list must not empty")
168
-
169
- result = 0
170
- i1, i2 = 0, 1
171
- for v in values:
172
- if v
173
-
174
-
175
-
176
- def main() -> None:
177
- """Tester Function."""
178
- print(lcm([2, 4, 6]))
179
-
180
-
181
- if __name__ == "__main__":
182
- main()
@@ -1,103 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: pythagix
3
- Version: 0.1.9
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.
File without changes
File without changes
File without changes