pythagix 0.1.9__py3-none-any.whl → 0.2.2__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 CHANGED
@@ -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
  )
pythagix/core.py CHANGED
@@ -1,14 +1,24 @@
1
1
  import math as m
2
2
  from functools import reduce
3
- from typing import List
3
+ from typing import List, Union
4
+ from collections import Counter
5
+
6
+ Numeric = Union[int, float]
4
7
 
5
8
  __all__ = [
6
- "is_prime",
9
+ "count_factors",
10
+ "digit_sum",
7
11
  "filter_primes",
8
- "nth_prime",
9
12
  "gcd",
10
13
  "is_perfect_square",
11
- "count_factors",
14
+ "is_prime",
15
+ "is_multiple",
16
+ "lcm",
17
+ "mean",
18
+ "median",
19
+ "middle",
20
+ "mode",
21
+ "nth_prime",
12
22
  "triangle_number",
13
23
  ]
14
24
 
@@ -21,7 +31,7 @@ def is_prime(number: int) -> bool:
21
31
  number (int): The number to check.
22
32
 
23
33
  Returns:
24
- bool: True if number is prime, False otherwise.
34
+ bool: True if the number is prime, False otherwise.
25
35
  """
26
36
  if number <= 1:
27
37
  return False
@@ -119,7 +129,7 @@ def count_factors(number: int) -> List[int]:
119
129
  List[int]: A sorted list of factors.
120
130
 
121
131
  Raises:
122
- ValueError: If number is not positive.
132
+ ValueError: If the number is not positive.
123
133
  """
124
134
  if number <= 0:
125
135
  raise ValueError("Number must be positive")
@@ -143,7 +153,7 @@ def triangle_number(index: int) -> int:
143
153
  int: The N-th triangular number.
144
154
 
145
155
  Raises:
146
- ValueError: If index is negative.
156
+ ValueError: If the index is negative.
147
157
  """
148
158
  if index < 0:
149
159
  raise ValueError("Index must be >= 0")
@@ -164,19 +174,133 @@ def lcm(values: List[int]) -> int:
164
174
  ValueError: If the list is empty.
165
175
  """
166
176
  if not values:
167
- raise ValueError("Input list must not empty")
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.
168
279
 
169
- result = 0
170
- i1, i2 = 0, 1
171
- for v in values:
172
- if v
280
+ Args:
281
+ values (List[int | float]): A list of integers or floats.
173
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.
174
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]
175
297
 
176
- def main() -> None:
177
- """Tester Function."""
178
- print(lcm([2, 4, 6]))
298
+ return modes[0] if len(modes) == 1 else modes
179
299
 
180
300
 
181
301
  if __name__ == "__main__":
302
+
303
+ def main() -> None:
304
+ """Tester Function."""
305
+
182
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.
@@ -0,0 +1,7 @@
1
+ pythagix/__init__.py,sha256=1DtygFgNUk9idxupKZ6gLQLGL9mY4Hkeumd91YdTPt4,267
2
+ pythagix/core.py,sha256=kbA2n0SLI4QVZExU93u2M8QgiJGO86Ybbxke_m62AFo,7206
3
+ pythagix-0.2.2.dist-info/licenses/LICENSE,sha256=mAiqjt0kIJZfw70XUmdIrsvPwnhKBMerHN3nDFg8H9c,1096
4
+ pythagix-0.2.2.dist-info/METADATA,sha256=1DMFFOxWlitY1byrUfpzYYAqP3I4LogwUOr9UnKBkBw,2813
5
+ pythagix-0.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ pythagix-0.2.2.dist-info/top_level.txt,sha256=U3rm-YGObQkL0gSuVWFPZTakILlqyAd7pUVvtJiMlsE,9
7
+ pythagix-0.2.2.dist-info/RECORD,,
@@ -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.
@@ -1,7 +0,0 @@
1
- pythagix/__init__.py,sha256=6tpiGil3VFdLrZ9fUZ41YY7qAkNyWOC74fiUNCuXzAE,175
2
- pythagix/core.py,sha256=IfshQbq1v-m5WXf4T3tfCW1usfVu_f9jlqjgoHNqelA,3986
3
- pythagix-0.1.9.dist-info/licenses/LICENSE,sha256=mAiqjt0kIJZfw70XUmdIrsvPwnhKBMerHN3nDFg8H9c,1096
4
- pythagix-0.1.9.dist-info/METADATA,sha256=6sGeTrPAXqOkbWHn0nOR8raWAlyM2e3nxSrzzUBYLT0,2669
5
- pythagix-0.1.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
- pythagix-0.1.9.dist-info/top_level.txt,sha256=U3rm-YGObQkL0gSuVWFPZTakILlqyAd7pUVvtJiMlsE,9
7
- pythagix-0.1.9.dist-info/RECORD,,