dolphinmath 0.0.2__tar.gz → 0.0.3__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.
- dolphinmath-0.0.3/LICENSE +21 -0
- dolphinmath-0.0.3/PKG-INFO +226 -0
- dolphinmath-0.0.3/README.md +214 -0
- dolphinmath-0.0.3/dolphinmath/__init__.py +105 -0
- dolphinmath-0.0.3/dolphinmath/numbers.py +331 -0
- dolphinmath-0.0.3/dolphinmath/prime.py +293 -0
- dolphinmath-0.0.3/dolphinmath/sequences.py +149 -0
- dolphinmath-0.0.3/dolphinmath/series.py +223 -0
- dolphinmath-0.0.3/dolphinmath/stats.py +244 -0
- dolphinmath-0.0.3/dolphinmath.egg-info/PKG-INFO +226 -0
- {dolphinmath-0.0.2 → dolphinmath-0.0.3}/dolphinmath.egg-info/SOURCES.txt +7 -7
- {dolphinmath-0.0.2 → dolphinmath-0.0.3}/pyproject.toml +17 -17
- dolphinmath-0.0.3/tests/test_numbers.py +216 -0
- dolphinmath-0.0.3/tests/test_prime.py +163 -0
- dolphinmath-0.0.3/tests/test_sequences.py +91 -0
- dolphinmath-0.0.3/tests/test_series.py +178 -0
- dolphinmath-0.0.3/tests/test_stats.py +153 -0
- dolphinmath-0.0.2/DolphinMath/__init__.py +0 -16
- dolphinmath-0.0.2/DolphinMath/numbers.py +0 -37
- dolphinmath-0.0.2/DolphinMath/prime.py +0 -45
- dolphinmath-0.0.2/DolphinMath/sequences.py +0 -12
- dolphinmath-0.0.2/DolphinMath/series.py +0 -16
- dolphinmath-0.0.2/DolphinMath/stats.py +0 -20
- dolphinmath-0.0.2/PKG-INFO +0 -20
- dolphinmath-0.0.2/README.md +0 -10
- dolphinmath-0.0.2/dolphinmath.egg-info/PKG-INFO +0 -20
- {dolphinmath-0.0.2 → dolphinmath-0.0.3}/dolphinmath.egg-info/dependency_links.txt +0 -0
- {dolphinmath-0.0.2 → dolphinmath-0.0.3}/dolphinmath.egg-info/top_level.txt +0 -0
- {dolphinmath-0.0.2 → dolphinmath-0.0.3}/setup.cfg +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Peddakotla Karthikeya
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dolphinmath
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: Simple math helper library made by a student
|
|
5
|
+
Author-email: Peddakotla Karthikeya <karthikeyapeddakotla@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://pypi.org/project/dolphinmath/
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# DolphinMath
|
|
14
|
+
|
|
15
|
+
[](https://www.python.org/)
|
|
16
|
+
[](LICENSE)
|
|
17
|
+
[]()
|
|
18
|
+
|
|
19
|
+
`DolphinMath` is a lightweight, high-performance, and comprehensive Python helper library designed for mathematical and statistical operations. It provides convenient functions for number theory, sequences, progressions, prime number computations, and statistical summaries.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Table of Contents
|
|
24
|
+
1. [Installation](#installation)
|
|
25
|
+
2. [Quick Start](#quick-start)
|
|
26
|
+
3. [Module Reference & Examples](#module-reference--examples)
|
|
27
|
+
- [Numbers Module (`dolphinmath.numbers`)](#numbers-module-dolphinmathnumbers)
|
|
28
|
+
- [Primes Module (`dolphinmath.prime`)](#primes-module-dolphinmathprime)
|
|
29
|
+
- [Sequences Module (`dolphinmath.sequences`)](#sequences-module-dolphinmathsequences)
|
|
30
|
+
- [Series Module (`dolphinmath.series`)](#series-module-dolphinmathseries)
|
|
31
|
+
- [Statistics Module (`dolphinmath.stats`)](#statistics-module-dolphinmathstats)
|
|
32
|
+
4. [Development & Testing](#development--testing)
|
|
33
|
+
5. [License](#license)
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
To install `DolphinMath` run:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install dolphinmath
|
|
43
|
+
```
|
|
44
|
+
Upgrade to the latest version:
|
|
45
|
+
```bash
|
|
46
|
+
pip install --upgrade dolphinmath
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Quick Start
|
|
52
|
+
|
|
53
|
+
All functions are exposed at the package root level for easy import:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import dolphinmath as dm
|
|
57
|
+
|
|
58
|
+
# Basic calculations
|
|
59
|
+
print(dm.gcd(24, 36)) # Output: 12
|
|
60
|
+
print(dm.is_prime(97)) # Output: True
|
|
61
|
+
print(dm.fibonacci(8)) # Output: [0, 1, 1, 2, 3, 5, 8, 13]
|
|
62
|
+
print(dm.quartiles([1, 2, 3, 4, 5, 6, 7, 8])) # Output: (2.75, 4.5, 6.25)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Module Reference & Examples
|
|
68
|
+
|
|
69
|
+
### Numbers Module (`dolphinmath.numbers`)
|
|
70
|
+
|
|
71
|
+
Provides basic number theory operations and properties of integers.
|
|
72
|
+
|
|
73
|
+
| Function | Description | Example |
|
|
74
|
+
| :--- | :--- | :--- |
|
|
75
|
+
| `gcd(a, b)` | Great Common Divisor of $a$ and $b$. | `dm.gcd(12, 18)` $\rightarrow$ `6` |
|
|
76
|
+
| `hcf(a, b)` | Highest Common Factor (alias of `gcd`). | `dm.hcf(12, 18)` $\rightarrow$ `6` |
|
|
77
|
+
| `lcm(a, b)` | Least Common Multiple of $a$ and $b$. | `dm.lcm(12, 18)` $\rightarrow$ `36` |
|
|
78
|
+
| `prime_factors(n)` | Prime factors of $n \ge 2$ with duplicates. | `dm.prime_factors(12)` $\rightarrow$ `[2, 2, 3]` |
|
|
79
|
+
| `factors(n)` | All positive factors of $n$ ($O(\sqrt{n})$ speed). | `dm.factors(12)` $\rightarrow$ `[1, 2, 3, 4, 6, 12]` |
|
|
80
|
+
| `is_perfect(n)` | Returns `True` if $n$ is equal to sum of proper factors. | `dm.is_perfect(28)` $\rightarrow$ `True` |
|
|
81
|
+
| `is_armstrong(n)` | Returns `True` if sum of digits to power length is $n$. | `dm.is_armstrong(153)` $\rightarrow$ `True` |
|
|
82
|
+
| `is_even(n)` | Returns `True` if $n$ is even. | `dm.is_even(14)` $\rightarrow$ `True` |
|
|
83
|
+
| `is_odd(n)` | Returns `True` if $n$ is odd. | `dm.is_odd(15)` $\rightarrow$ `True` |
|
|
84
|
+
| `reverse_number(n)` | Reverses digits of $n$, preserving signs. | `dm.reverse_number(-123)` $\rightarrow$ `-321` |
|
|
85
|
+
| `sum_of_digits(n)` | Returns sum of digits of the absolute value of $n$. | `dm.sum_of_digits(-405)` $\rightarrow$ `9` |
|
|
86
|
+
| `palindrome_number(n)`| Returns `True` if $n$ is palindromic. | `dm.palindrome_number(121)` $\rightarrow$ `True` |
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import dolphinmath as dm
|
|
90
|
+
|
|
91
|
+
# Checking number properties
|
|
92
|
+
print(dm.is_even(42)) # True
|
|
93
|
+
print(dm.is_odd(42)) # False
|
|
94
|
+
print(dm.reverse_number(-809)) # -908
|
|
95
|
+
print(dm.sum_of_digits(-405)) # 9
|
|
96
|
+
print(dm.palindrome_number(12321))# True
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
### Primes Module (`dolphinmath.prime`)
|
|
102
|
+
|
|
103
|
+
Optimized utilities for identifying, counting, and generating prime numbers.
|
|
104
|
+
|
|
105
|
+
| Function | Description | Example |
|
|
106
|
+
| :--- | :--- | :--- |
|
|
107
|
+
| `is_prime(n)` | Check primality of $n$ using $6k \pm 1$ test. | `dm.is_prime(97)` $\rightarrow$ `True` |
|
|
108
|
+
| `prime_sieve(limit)` | Generate primes up to `limit` (Sieve of Eratosthenes). | `dm.prime_sieve(20)` $\rightarrow$ `[2, 3, 5, 7, 11, 13, 17, 19]` |
|
|
109
|
+
| `list_primes(a, b)` | Find all primes in range $[a, b]$ (inclusive). | `dm.list_primes(10, 20)` $\rightarrow$ `[11, 13, 17, 19]` |
|
|
110
|
+
| `primes(a, b)` | Print all primes in range $[a, b]$ one per line. | `dm.primes(1, 5)` $\rightarrow$ prints `2`, `3`, `5` |
|
|
111
|
+
| `count_primes(a, b)` | Count the number of primes in range $[a, b]$. | `dm.count_primes(10, 20)` $\rightarrow$ `4` |
|
|
112
|
+
| `prime_count_upto(lim)`| Count primes up to a limit using sieve. | `dm.prime_count_upto(100)` $\rightarrow$ `25` |
|
|
113
|
+
| `nth_prime(n)` | Find the $n$-th prime (optimized PNT bound search). | `dm.nth_prime(1000)` $\rightarrow$ `7919` |
|
|
114
|
+
| `next_prime(n)` | Find the first prime strictly greater than $n$. | `dm.next_prime(5)` $\rightarrow$ `7` |
|
|
115
|
+
| `twin_primes(a, b)` | Find all twin prime pairs $(p, p+2)$ in $[a, b]$. | `dm.twin_primes(3, 15)` $\rightarrow$ `[(3, 5), (5, 7), (11, 13)]` |
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
import dolphinmath as dm
|
|
119
|
+
|
|
120
|
+
# Efficient prime generation and checks
|
|
121
|
+
print(dm.prime_sieve(30)) # [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
|
|
122
|
+
print(dm.twin_primes(1, 20)) # [(3, 5), (5, 7), (11, 13), (17, 19)]
|
|
123
|
+
print(dm.nth_prime(500)) # 3571
|
|
124
|
+
print(dm.next_prime(14)) # 17
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
### Sequences Module (`dolphinmath.sequences`)
|
|
130
|
+
|
|
131
|
+
Functions for generating popular mathematical sequences.
|
|
132
|
+
|
|
133
|
+
| Function | Description | Example |
|
|
134
|
+
| :--- | :--- | :--- |
|
|
135
|
+
| `factorial(n)` | Compute factorial of $n \ge 0$ ($n!$). | `dm.factorial(5)` $\rightarrow$ `120` |
|
|
136
|
+
| `fibonacci(n)` | Generate first $n$ Fibonacci numbers. | `dm.fibonacci(5)` $\rightarrow$ `[0, 1, 1, 2, 3]` |
|
|
137
|
+
| `lucas_sequence(n)` | Generate first $n$ Lucas numbers ($2, 1, 3, 4, ...$). | `dm.lucas_sequence(5)` $\rightarrow$ `[2, 1, 3, 4, 7]` |
|
|
138
|
+
| `tribonacci(n)` | Generate first $n$ Tribonacci numbers ($0, 0, 1, ...$). | `dm.tribonacci(6)` $\rightarrow$ `[0, 0, 1, 1, 2, 4]` |
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
import dolphinmath as dm
|
|
142
|
+
|
|
143
|
+
# Sequences
|
|
144
|
+
print(dm.factorial(6)) # 720
|
|
145
|
+
print(dm.fibonacci(8)) # [0, 1, 1, 2, 3, 5, 8, 13]
|
|
146
|
+
print(dm.lucas_sequence(6)) # [2, 1, 3, 4, 7, 11]
|
|
147
|
+
print(dm.tribonacci(8)) # [0, 0, 1, 1, 2, 4, 7, 13]
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
### Series Module (`dolphinmath.series`)
|
|
153
|
+
|
|
154
|
+
Progression series calculators and generalized means.
|
|
155
|
+
|
|
156
|
+
| Function | Description | Example |
|
|
157
|
+
| :--- | :--- | :--- |
|
|
158
|
+
| `ap_nth(a, d, n)` | Calculate the $n$-th term of Arithmetic Progression. | `dm.ap_nth(2, 3, 5)` $\rightarrow$ `14` |
|
|
159
|
+
| `ap_sum(a, d, n)` | Calculate sum of first $n$ terms of AP. | `dm.ap_sum(2, 3, 5)` $\rightarrow$ `40.0` |
|
|
160
|
+
| `gp_nth(a, r, n)` | Calculate the $n$-th term of Geometric Progression. | `dm.gp_nth(2, 3, 4)` $\rightarrow$ `54` |
|
|
161
|
+
| `gp_sum(a, r, n)` | Calculate sum of first $n$ terms of GP. | `dm.gp_sum(2, 3, 4)` $\rightarrow$ `80.0` |
|
|
162
|
+
| `harmonic_sum(n)` | Sum of first $n$ terms of Harmonic series. | `dm.harmonic_sum(3)` $\rightarrow$ `1.8333...` |
|
|
163
|
+
| `arithmetic_mean(ns)` | Calculate arithmetic mean of a list of numbers. | `dm.arithmetic_mean([1, 2, 3])` $\rightarrow$ `2.0` |
|
|
164
|
+
| `geometric_mean(ns)` | Calculate geometric mean of positive numbers. | `dm.geometric_mean([2, 8])` $\rightarrow$ `4.0` |
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
import dolphinmath as dm
|
|
168
|
+
|
|
169
|
+
# Series and means
|
|
170
|
+
print(dm.ap_sum(1, 2, 10)) # Sum: 1 + 3 + ... + 19 = 100.0
|
|
171
|
+
print(dm.gp_nth(3, 2, 5)) # 5th term of 3, 6, 12, 24, 48 = 48
|
|
172
|
+
print(dm.harmonic_sum(4)) # 1 + 1/2 + 1/3 + 1/4 = 2.083333333333333
|
|
173
|
+
print(dm.geometric_mean([1, 10, 100]))# 10.0
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
### Statistics Module (`dolphinmath.stats`)
|
|
179
|
+
|
|
180
|
+
Statistical functions for descriptive data analysis.
|
|
181
|
+
|
|
182
|
+
| Function | Description | Example |
|
|
183
|
+
| :--- | :--- | :--- |
|
|
184
|
+
| `mean(nums)` | Calculate the arithmetic mean of a list. | `dm.mean([1, 2, 3, 4, 5])` $\rightarrow$ `3.0` |
|
|
185
|
+
| `median(nums)` | Calculate the median of a list. | `dm.median([1, 2, 3, 4])` $\rightarrow$ `2.5` |
|
|
186
|
+
| `mode(nums)` | Returns a list of modes (highest frequency). | `dm.mode([1, 2, 2, 3])` $\rightarrow$ `[2]` |
|
|
187
|
+
| `variance(nums, sample)` | Calculate sample or population variance. | `dm.variance([1, 2, 3, 4])` $\rightarrow$ `1.6666...` |
|
|
188
|
+
| `standard_deviation(...)`| Calculate sample or population standard deviation. | `dm.standard_deviation([1, 2, 3, 4])` $\rightarrow$ `1.2909...` |
|
|
189
|
+
| `range_value(nums)` | Difference between max and min in a list. | `dm.range_value([1, 2, 9, 4])` $\rightarrow$ `8` |
|
|
190
|
+
| `quartiles(nums)` | Returns a tuple (Q1, Q2, Q3) using interpolation. | `dm.quartiles([1, 2, 3, 4, 5, 6, 7, 8])` $\rightarrow$ `(2.75, 4.5, 6.25)` |
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
import dolphinmath as dm
|
|
194
|
+
|
|
195
|
+
data = [10, 20, 20, 30, 40, 50, 60, 70]
|
|
196
|
+
|
|
197
|
+
print(dm.mean(data)) # 37.5
|
|
198
|
+
print(dm.median(data)) # 35.0
|
|
199
|
+
print(dm.mode(data)) # [20]
|
|
200
|
+
print(dm.variance(data, sample=True)) # 450.0
|
|
201
|
+
print(dm.standard_deviation(data)) # 21.213203435596427
|
|
202
|
+
print(dm.range_value(data)) # 60
|
|
203
|
+
print(dm.quartiles(data)) # (20.0, 35.0, 52.5)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Development & Testing
|
|
209
|
+
|
|
210
|
+
We use standard unit tests. To run tests:
|
|
211
|
+
|
|
212
|
+
1. Run testing modules directly:
|
|
213
|
+
```bash
|
|
214
|
+
python -m tests.test_numbers
|
|
215
|
+
python -m tests.test_prime
|
|
216
|
+
```
|
|
217
|
+
2. Or use pytest if installed:
|
|
218
|
+
```bash
|
|
219
|
+
python -m pytest
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# DolphinMath
|
|
2
|
+
|
|
3
|
+
[](https://www.python.org/)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[]()
|
|
6
|
+
|
|
7
|
+
`DolphinMath` is a lightweight, high-performance, and comprehensive Python helper library designed for mathematical and statistical operations. It provides convenient functions for number theory, sequences, progressions, prime number computations, and statistical summaries.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Table of Contents
|
|
12
|
+
1. [Installation](#installation)
|
|
13
|
+
2. [Quick Start](#quick-start)
|
|
14
|
+
3. [Module Reference & Examples](#module-reference--examples)
|
|
15
|
+
- [Numbers Module (`dolphinmath.numbers`)](#numbers-module-dolphinmathnumbers)
|
|
16
|
+
- [Primes Module (`dolphinmath.prime`)](#primes-module-dolphinmathprime)
|
|
17
|
+
- [Sequences Module (`dolphinmath.sequences`)](#sequences-module-dolphinmathsequences)
|
|
18
|
+
- [Series Module (`dolphinmath.series`)](#series-module-dolphinmathseries)
|
|
19
|
+
- [Statistics Module (`dolphinmath.stats`)](#statistics-module-dolphinmathstats)
|
|
20
|
+
4. [Development & Testing](#development--testing)
|
|
21
|
+
5. [License](#license)
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
To install `DolphinMath` run:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install dolphinmath
|
|
31
|
+
```
|
|
32
|
+
Upgrade to the latest version:
|
|
33
|
+
```bash
|
|
34
|
+
pip install --upgrade dolphinmath
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
All functions are exposed at the package root level for easy import:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import dolphinmath as dm
|
|
45
|
+
|
|
46
|
+
# Basic calculations
|
|
47
|
+
print(dm.gcd(24, 36)) # Output: 12
|
|
48
|
+
print(dm.is_prime(97)) # Output: True
|
|
49
|
+
print(dm.fibonacci(8)) # Output: [0, 1, 1, 2, 3, 5, 8, 13]
|
|
50
|
+
print(dm.quartiles([1, 2, 3, 4, 5, 6, 7, 8])) # Output: (2.75, 4.5, 6.25)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Module Reference & Examples
|
|
56
|
+
|
|
57
|
+
### Numbers Module (`dolphinmath.numbers`)
|
|
58
|
+
|
|
59
|
+
Provides basic number theory operations and properties of integers.
|
|
60
|
+
|
|
61
|
+
| Function | Description | Example |
|
|
62
|
+
| :--- | :--- | :--- |
|
|
63
|
+
| `gcd(a, b)` | Great Common Divisor of $a$ and $b$. | `dm.gcd(12, 18)` $\rightarrow$ `6` |
|
|
64
|
+
| `hcf(a, b)` | Highest Common Factor (alias of `gcd`). | `dm.hcf(12, 18)` $\rightarrow$ `6` |
|
|
65
|
+
| `lcm(a, b)` | Least Common Multiple of $a$ and $b$. | `dm.lcm(12, 18)` $\rightarrow$ `36` |
|
|
66
|
+
| `prime_factors(n)` | Prime factors of $n \ge 2$ with duplicates. | `dm.prime_factors(12)` $\rightarrow$ `[2, 2, 3]` |
|
|
67
|
+
| `factors(n)` | All positive factors of $n$ ($O(\sqrt{n})$ speed). | `dm.factors(12)` $\rightarrow$ `[1, 2, 3, 4, 6, 12]` |
|
|
68
|
+
| `is_perfect(n)` | Returns `True` if $n$ is equal to sum of proper factors. | `dm.is_perfect(28)` $\rightarrow$ `True` |
|
|
69
|
+
| `is_armstrong(n)` | Returns `True` if sum of digits to power length is $n$. | `dm.is_armstrong(153)` $\rightarrow$ `True` |
|
|
70
|
+
| `is_even(n)` | Returns `True` if $n$ is even. | `dm.is_even(14)` $\rightarrow$ `True` |
|
|
71
|
+
| `is_odd(n)` | Returns `True` if $n$ is odd. | `dm.is_odd(15)` $\rightarrow$ `True` |
|
|
72
|
+
| `reverse_number(n)` | Reverses digits of $n$, preserving signs. | `dm.reverse_number(-123)` $\rightarrow$ `-321` |
|
|
73
|
+
| `sum_of_digits(n)` | Returns sum of digits of the absolute value of $n$. | `dm.sum_of_digits(-405)` $\rightarrow$ `9` |
|
|
74
|
+
| `palindrome_number(n)`| Returns `True` if $n$ is palindromic. | `dm.palindrome_number(121)` $\rightarrow$ `True` |
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import dolphinmath as dm
|
|
78
|
+
|
|
79
|
+
# Checking number properties
|
|
80
|
+
print(dm.is_even(42)) # True
|
|
81
|
+
print(dm.is_odd(42)) # False
|
|
82
|
+
print(dm.reverse_number(-809)) # -908
|
|
83
|
+
print(dm.sum_of_digits(-405)) # 9
|
|
84
|
+
print(dm.palindrome_number(12321))# True
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### Primes Module (`dolphinmath.prime`)
|
|
90
|
+
|
|
91
|
+
Optimized utilities for identifying, counting, and generating prime numbers.
|
|
92
|
+
|
|
93
|
+
| Function | Description | Example |
|
|
94
|
+
| :--- | :--- | :--- |
|
|
95
|
+
| `is_prime(n)` | Check primality of $n$ using $6k \pm 1$ test. | `dm.is_prime(97)` $\rightarrow$ `True` |
|
|
96
|
+
| `prime_sieve(limit)` | Generate primes up to `limit` (Sieve of Eratosthenes). | `dm.prime_sieve(20)` $\rightarrow$ `[2, 3, 5, 7, 11, 13, 17, 19]` |
|
|
97
|
+
| `list_primes(a, b)` | Find all primes in range $[a, b]$ (inclusive). | `dm.list_primes(10, 20)` $\rightarrow$ `[11, 13, 17, 19]` |
|
|
98
|
+
| `primes(a, b)` | Print all primes in range $[a, b]$ one per line. | `dm.primes(1, 5)` $\rightarrow$ prints `2`, `3`, `5` |
|
|
99
|
+
| `count_primes(a, b)` | Count the number of primes in range $[a, b]$. | `dm.count_primes(10, 20)` $\rightarrow$ `4` |
|
|
100
|
+
| `prime_count_upto(lim)`| Count primes up to a limit using sieve. | `dm.prime_count_upto(100)` $\rightarrow$ `25` |
|
|
101
|
+
| `nth_prime(n)` | Find the $n$-th prime (optimized PNT bound search). | `dm.nth_prime(1000)` $\rightarrow$ `7919` |
|
|
102
|
+
| `next_prime(n)` | Find the first prime strictly greater than $n$. | `dm.next_prime(5)` $\rightarrow$ `7` |
|
|
103
|
+
| `twin_primes(a, b)` | Find all twin prime pairs $(p, p+2)$ in $[a, b]$. | `dm.twin_primes(3, 15)` $\rightarrow$ `[(3, 5), (5, 7), (11, 13)]` |
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
import dolphinmath as dm
|
|
107
|
+
|
|
108
|
+
# Efficient prime generation and checks
|
|
109
|
+
print(dm.prime_sieve(30)) # [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
|
|
110
|
+
print(dm.twin_primes(1, 20)) # [(3, 5), (5, 7), (11, 13), (17, 19)]
|
|
111
|
+
print(dm.nth_prime(500)) # 3571
|
|
112
|
+
print(dm.next_prime(14)) # 17
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
### Sequences Module (`dolphinmath.sequences`)
|
|
118
|
+
|
|
119
|
+
Functions for generating popular mathematical sequences.
|
|
120
|
+
|
|
121
|
+
| Function | Description | Example |
|
|
122
|
+
| :--- | :--- | :--- |
|
|
123
|
+
| `factorial(n)` | Compute factorial of $n \ge 0$ ($n!$). | `dm.factorial(5)` $\rightarrow$ `120` |
|
|
124
|
+
| `fibonacci(n)` | Generate first $n$ Fibonacci numbers. | `dm.fibonacci(5)` $\rightarrow$ `[0, 1, 1, 2, 3]` |
|
|
125
|
+
| `lucas_sequence(n)` | Generate first $n$ Lucas numbers ($2, 1, 3, 4, ...$). | `dm.lucas_sequence(5)` $\rightarrow$ `[2, 1, 3, 4, 7]` |
|
|
126
|
+
| `tribonacci(n)` | Generate first $n$ Tribonacci numbers ($0, 0, 1, ...$). | `dm.tribonacci(6)` $\rightarrow$ `[0, 0, 1, 1, 2, 4]` |
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
import dolphinmath as dm
|
|
130
|
+
|
|
131
|
+
# Sequences
|
|
132
|
+
print(dm.factorial(6)) # 720
|
|
133
|
+
print(dm.fibonacci(8)) # [0, 1, 1, 2, 3, 5, 8, 13]
|
|
134
|
+
print(dm.lucas_sequence(6)) # [2, 1, 3, 4, 7, 11]
|
|
135
|
+
print(dm.tribonacci(8)) # [0, 0, 1, 1, 2, 4, 7, 13]
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
### Series Module (`dolphinmath.series`)
|
|
141
|
+
|
|
142
|
+
Progression series calculators and generalized means.
|
|
143
|
+
|
|
144
|
+
| Function | Description | Example |
|
|
145
|
+
| :--- | :--- | :--- |
|
|
146
|
+
| `ap_nth(a, d, n)` | Calculate the $n$-th term of Arithmetic Progression. | `dm.ap_nth(2, 3, 5)` $\rightarrow$ `14` |
|
|
147
|
+
| `ap_sum(a, d, n)` | Calculate sum of first $n$ terms of AP. | `dm.ap_sum(2, 3, 5)` $\rightarrow$ `40.0` |
|
|
148
|
+
| `gp_nth(a, r, n)` | Calculate the $n$-th term of Geometric Progression. | `dm.gp_nth(2, 3, 4)` $\rightarrow$ `54` |
|
|
149
|
+
| `gp_sum(a, r, n)` | Calculate sum of first $n$ terms of GP. | `dm.gp_sum(2, 3, 4)` $\rightarrow$ `80.0` |
|
|
150
|
+
| `harmonic_sum(n)` | Sum of first $n$ terms of Harmonic series. | `dm.harmonic_sum(3)` $\rightarrow$ `1.8333...` |
|
|
151
|
+
| `arithmetic_mean(ns)` | Calculate arithmetic mean of a list of numbers. | `dm.arithmetic_mean([1, 2, 3])` $\rightarrow$ `2.0` |
|
|
152
|
+
| `geometric_mean(ns)` | Calculate geometric mean of positive numbers. | `dm.geometric_mean([2, 8])` $\rightarrow$ `4.0` |
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
import dolphinmath as dm
|
|
156
|
+
|
|
157
|
+
# Series and means
|
|
158
|
+
print(dm.ap_sum(1, 2, 10)) # Sum: 1 + 3 + ... + 19 = 100.0
|
|
159
|
+
print(dm.gp_nth(3, 2, 5)) # 5th term of 3, 6, 12, 24, 48 = 48
|
|
160
|
+
print(dm.harmonic_sum(4)) # 1 + 1/2 + 1/3 + 1/4 = 2.083333333333333
|
|
161
|
+
print(dm.geometric_mean([1, 10, 100]))# 10.0
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
### Statistics Module (`dolphinmath.stats`)
|
|
167
|
+
|
|
168
|
+
Statistical functions for descriptive data analysis.
|
|
169
|
+
|
|
170
|
+
| Function | Description | Example |
|
|
171
|
+
| :--- | :--- | :--- |
|
|
172
|
+
| `mean(nums)` | Calculate the arithmetic mean of a list. | `dm.mean([1, 2, 3, 4, 5])` $\rightarrow$ `3.0` |
|
|
173
|
+
| `median(nums)` | Calculate the median of a list. | `dm.median([1, 2, 3, 4])` $\rightarrow$ `2.5` |
|
|
174
|
+
| `mode(nums)` | Returns a list of modes (highest frequency). | `dm.mode([1, 2, 2, 3])` $\rightarrow$ `[2]` |
|
|
175
|
+
| `variance(nums, sample)` | Calculate sample or population variance. | `dm.variance([1, 2, 3, 4])` $\rightarrow$ `1.6666...` |
|
|
176
|
+
| `standard_deviation(...)`| Calculate sample or population standard deviation. | `dm.standard_deviation([1, 2, 3, 4])` $\rightarrow$ `1.2909...` |
|
|
177
|
+
| `range_value(nums)` | Difference between max and min in a list. | `dm.range_value([1, 2, 9, 4])` $\rightarrow$ `8` |
|
|
178
|
+
| `quartiles(nums)` | Returns a tuple (Q1, Q2, Q3) using interpolation. | `dm.quartiles([1, 2, 3, 4, 5, 6, 7, 8])` $\rightarrow$ `(2.75, 4.5, 6.25)` |
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
import dolphinmath as dm
|
|
182
|
+
|
|
183
|
+
data = [10, 20, 20, 30, 40, 50, 60, 70]
|
|
184
|
+
|
|
185
|
+
print(dm.mean(data)) # 37.5
|
|
186
|
+
print(dm.median(data)) # 35.0
|
|
187
|
+
print(dm.mode(data)) # [20]
|
|
188
|
+
print(dm.variance(data, sample=True)) # 450.0
|
|
189
|
+
print(dm.standard_deviation(data)) # 21.213203435596427
|
|
190
|
+
print(dm.range_value(data)) # 60
|
|
191
|
+
print(dm.quartiles(data)) # (20.0, 35.0, 52.5)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Development & Testing
|
|
197
|
+
|
|
198
|
+
We use standard unit tests. To run tests:
|
|
199
|
+
|
|
200
|
+
1. Run testing modules directly:
|
|
201
|
+
```bash
|
|
202
|
+
python -m tests.test_numbers
|
|
203
|
+
python -m tests.test_prime
|
|
204
|
+
```
|
|
205
|
+
2. Or use pytest if installed:
|
|
206
|
+
```bash
|
|
207
|
+
python -m pytest
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""DolphinMath helper library.
|
|
2
|
+
|
|
3
|
+
A simple and comprehensive math helper library containing tools for
|
|
4
|
+
number theory, primes, sequences, series, and statistics.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
owner = "PEDDAKOTLA KARTHIKEYA"
|
|
8
|
+
version = "0.3.0"
|
|
9
|
+
|
|
10
|
+
from .numbers import (
|
|
11
|
+
gcd,
|
|
12
|
+
hcf,
|
|
13
|
+
lcm,
|
|
14
|
+
prime_factors,
|
|
15
|
+
factors,
|
|
16
|
+
is_perfect,
|
|
17
|
+
is_armstrong,
|
|
18
|
+
is_even,
|
|
19
|
+
is_odd,
|
|
20
|
+
reverse_number,
|
|
21
|
+
sum_of_digits,
|
|
22
|
+
palindrome_number,
|
|
23
|
+
)
|
|
24
|
+
from .prime import (
|
|
25
|
+
primes,
|
|
26
|
+
is_prime,
|
|
27
|
+
list_primes,
|
|
28
|
+
count_primes,
|
|
29
|
+
nth_prime,
|
|
30
|
+
next_prime,
|
|
31
|
+
prime_sieve,
|
|
32
|
+
twin_primes,
|
|
33
|
+
prime_count_upto,
|
|
34
|
+
)
|
|
35
|
+
from .sequences import (
|
|
36
|
+
factorial,
|
|
37
|
+
fibonacci,
|
|
38
|
+
lucas_sequence,
|
|
39
|
+
tribonacci,
|
|
40
|
+
)
|
|
41
|
+
from .series import (
|
|
42
|
+
ap_nth,
|
|
43
|
+
ap_sum,
|
|
44
|
+
gp_nth,
|
|
45
|
+
gp_sum,
|
|
46
|
+
harmonic_sum,
|
|
47
|
+
arithmetic_mean,
|
|
48
|
+
geometric_mean,
|
|
49
|
+
)
|
|
50
|
+
from .stats import (
|
|
51
|
+
mean,
|
|
52
|
+
median,
|
|
53
|
+
mode,
|
|
54
|
+
variance,
|
|
55
|
+
standard_deviation,
|
|
56
|
+
range_value,
|
|
57
|
+
quartiles,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
__all__ = [
|
|
61
|
+
# Numbers
|
|
62
|
+
"gcd",
|
|
63
|
+
"hcf",
|
|
64
|
+
"lcm",
|
|
65
|
+
"prime_factors",
|
|
66
|
+
"factors",
|
|
67
|
+
"is_perfect",
|
|
68
|
+
"is_armstrong",
|
|
69
|
+
"is_even",
|
|
70
|
+
"is_odd",
|
|
71
|
+
"reverse_number",
|
|
72
|
+
"sum_of_digits",
|
|
73
|
+
"palindrome_number",
|
|
74
|
+
# Primes
|
|
75
|
+
"primes",
|
|
76
|
+
"is_prime",
|
|
77
|
+
"list_primes",
|
|
78
|
+
"count_primes",
|
|
79
|
+
"nth_prime",
|
|
80
|
+
"next_prime",
|
|
81
|
+
"prime_sieve",
|
|
82
|
+
"twin_primes",
|
|
83
|
+
"prime_count_upto",
|
|
84
|
+
# Sequences
|
|
85
|
+
"factorial",
|
|
86
|
+
"fibonacci",
|
|
87
|
+
"lucas_sequence",
|
|
88
|
+
"tribonacci",
|
|
89
|
+
# Series
|
|
90
|
+
"ap_nth",
|
|
91
|
+
"ap_sum",
|
|
92
|
+
"gp_nth",
|
|
93
|
+
"gp_sum",
|
|
94
|
+
"harmonic_sum",
|
|
95
|
+
"arithmetic_mean",
|
|
96
|
+
"geometric_mean",
|
|
97
|
+
# Stats
|
|
98
|
+
"mean",
|
|
99
|
+
"median",
|
|
100
|
+
"mode",
|
|
101
|
+
"variance",
|
|
102
|
+
"standard_deviation",
|
|
103
|
+
"range_value",
|
|
104
|
+
"quartiles",
|
|
105
|
+
]
|