pythagix 0.2.0__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
@@ -8,7 +8,10 @@ from .core import (
8
8
  is_prime,
9
9
  is_multiple,
10
10
  lcm,
11
+ mean,
12
+ median,
11
13
  middle,
14
+ mode,
12
15
  nth_prime,
13
16
  triangle_number,
14
17
  )
pythagix/core.py CHANGED
@@ -1,6 +1,9 @@
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
9
  "count_factors",
@@ -11,7 +14,10 @@ __all__ = [
11
14
  "is_prime",
12
15
  "is_multiple",
13
16
  "lcm",
17
+ "mean",
18
+ "median",
14
19
  "middle",
20
+ "mode",
15
21
  "nth_prime",
16
22
  "triangle_number",
17
23
  ]
@@ -25,7 +31,7 @@ def is_prime(number: int) -> bool:
25
31
  number (int): The number to check.
26
32
 
27
33
  Returns:
28
- bool: True if number is prime, False otherwise.
34
+ bool: True if the number is prime, False otherwise.
29
35
  """
30
36
  if number <= 1:
31
37
  return False
@@ -123,7 +129,7 @@ def count_factors(number: int) -> List[int]:
123
129
  List[int]: A sorted list of factors.
124
130
 
125
131
  Raises:
126
- ValueError: If number is not positive.
132
+ ValueError: If the number is not positive.
127
133
  """
128
134
  if number <= 0:
129
135
  raise ValueError("Number must be positive")
@@ -147,7 +153,7 @@ def triangle_number(index: int) -> int:
147
153
  int: The N-th triangular number.
148
154
 
149
155
  Raises:
150
- ValueError: If index is negative.
156
+ ValueError: If the index is negative.
151
157
  """
152
158
  if index < 0:
153
159
  raise ValueError("Index must be >= 0")
@@ -168,23 +174,22 @@ def lcm(values: List[int]) -> int:
168
174
  ValueError: If the list is empty.
169
175
  """
170
176
  if not values:
171
- raise ValueError("Input list must not empty")
177
+ raise ValueError("Input list must not be empty")
172
178
 
173
179
  return reduce(m.lcm, values)
174
180
 
175
181
 
176
182
  def digit_sum(number: int) -> int:
177
183
  """
178
- Sum all digits that are in the given number
184
+ Sum all digits of the given number.
179
185
 
180
186
  Args:
181
187
  number (int): The number whose digits are to be summed.
182
188
 
183
189
  Returns:
184
- int: The sum of the digits in the number
190
+ int: The sum of the digits in the number.
185
191
  """
186
-
187
- return sum([int(digit) for digit in str(number)])
192
+ return sum(int(digit) for digit in str(number))
188
193
 
189
194
 
190
195
  def is_multiple(number: int, base: int) -> bool:
@@ -192,35 +197,110 @@ def is_multiple(number: int, base: int) -> bool:
192
197
  Check if a number is a multiple of another number.
193
198
 
194
199
  Args:
195
- n (int): The number to test.
200
+ number (int): The number to test.
196
201
  base (int): The base to check against.
197
202
 
198
203
  Returns:
199
- bool: True if n is a multiple of base, False otherwise.
204
+ bool: True if number is a multiple of base, False otherwise.
200
205
  """
201
-
202
206
  return number % base == 0
203
207
 
204
208
 
205
- def middle(a: int | float, b: int | float) -> float:
209
+ def middle(a: Numeric, b: Numeric) -> float:
206
210
  """
207
211
  Return the midpoint between two numbers.
208
212
 
209
213
  Args:
210
- a (float): The first number.
211
- b (float): The second number.
214
+ a (int | float): The first number.
215
+ b (int | float): The second number.
212
216
 
213
217
  Returns:
214
218
  float: The average of the two numbers.
215
219
  """
216
-
217
220
  return (a + b) / 2
218
221
 
219
222
 
220
- def main() -> None:
221
- """Tester Function."""
222
- print(middle(246, 2))
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
223
299
 
224
300
 
225
301
  if __name__ == "__main__":
302
+
303
+ def main() -> None:
304
+ """Tester Function."""
305
+
226
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,112 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: pythagix
3
- Version: 0.2.0
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
- count_factors(number: int) -> List[int]
38
- Return a sorted list of all positive factors of the given number.
39
-
40
- digit_sum(number: int) -> int
41
- Return the sum of all digit in the given number.
42
-
43
- filter_primes(numbers: List[int]) -> List[int]
44
- Return all prime numbers from a list of integers.
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
- is_prime(number: int) -> bool
53
- Determine whether a number is prime.
54
-
55
- lcm(values: List[int]) -> int
56
- Compute the least common multiple (LCM) of a list of integers.
57
-
58
- middle(a: int | float, b: int | float) -> float
59
- Return the midpoint of two numbers.
60
-
61
- nth_prime(position: int) -> int
62
- Retrieve the n-th prime number (1-based index).
63
-
64
- triangle_number(index: int) -> int
65
- Compute the n-th triangular number.
66
-
67
- ---
68
-
69
- ## Example Usage
70
-
71
- ```python
72
- from pythagix import is_prime, nth_prime, gcd, triangle_number
73
-
74
- print(is_prime(13)) # Output: True
75
-
76
- print(nth_prime(10)) # Output: 29
77
-
78
- print(gcd([12, 18, 24])) # Output: 6
79
-
80
- print(triangle_number(7)) # Output: 28
81
- ```
82
-
83
- ---
84
-
85
- ## Use Cases
86
-
87
- Pythagix is ideal for:
88
-
89
- Educational platforms and math-related tools
90
-
91
- Prototyping algorithms and number-theoretic computations
92
-
93
- Teaching foundational concepts in discrete mathematics and number theory
94
-
95
- Lightweight CLI utilities and academic scripting
96
-
97
- ---
98
-
99
- ## License
100
-
101
- Pythagix is released under the [MIT License](LICENSE), making it free to use, modify, and distribute.
102
-
103
- ---
104
-
105
- ## Contributing
106
-
107
- Contributions are welcome!
108
- 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).
109
-
110
- ---
111
-
112
- 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=LUVDAw14_IqsBFgs0qWQor9QNQ3VlDG9XSH-ONMT7xY,232
2
- pythagix/core.py,sha256=dyLRvIJbH5RABSTEK3ZuF0BrVjdbVRFrn6RTs0PmkgA,4963
3
- pythagix-0.2.0.dist-info/licenses/LICENSE,sha256=mAiqjt0kIJZfw70XUmdIrsvPwnhKBMerHN3nDFg8H9c,1096
4
- pythagix-0.2.0.dist-info/METADATA,sha256=3EqjE5mGCx53YX_4NNcKZL2UgpX9lR-pBAuNbO2mfGU,2875
5
- pythagix-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
- pythagix-0.2.0.dist-info/top_level.txt,sha256=U3rm-YGObQkL0gSuVWFPZTakILlqyAd7pUVvtJiMlsE,9
7
- pythagix-0.2.0.dist-info/RECORD,,