oresmen 0.1.0__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.
- oresmen-0.1.0/LICENSE +21 -0
- oresmen-0.1.0/PKG-INFO +343 -0
- oresmen-0.1.0/README.md +326 -0
- oresmen-0.1.0/pyproject.toml +19 -0
- oresmen-0.1.0/src/oresmen/__init__.py +46 -0
- oresmen-0.1.0/src/oresmen/_version.py +9 -0
- oresmen-0.1.0/src/oresmen/main.py +364 -0
oresmen-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mehmet Keçeci
|
|
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.
|
oresmen-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: oresmen
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A module for generating Oresme numbers (harmonic series partial sums)
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Mehmet Keçeci
|
|
7
|
+
Author-email: mkececi@yaani.com
|
|
8
|
+
Requires-Python: >=3.11,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Dist: numpy (>=2.3.2,<3.0.0)
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# Oresme Numba
|
|
18
|
+
|
|
19
|
+
[](https://doi.org/)
|
|
20
|
+
|
|
21
|
+
[](https://doi.org/)
|
|
22
|
+
|
|
23
|
+
[](https://doi.org/)
|
|
24
|
+
|
|
25
|
+
[](https://doi.org/)
|
|
26
|
+
|
|
27
|
+
[](https://anaconda.org/bilgi/oresmen)
|
|
28
|
+
[](https://anaconda.org/bilgi/oresmen)
|
|
29
|
+
[](https://anaconda.org/bilgi/oresmen)
|
|
30
|
+
[](https://anaconda.org/bilgi/oresmen)
|
|
31
|
+
[](https://opensource.org/)
|
|
32
|
+
[](https://opensource.org/licenses/MIT)
|
|
33
|
+
|
|
34
|
+
[](https://github.com/WhiteSymmetry/oresmen/actions/workflows/python_ci.yml)
|
|
35
|
+
[](https://codecov.io/gh/WhiteSymmetry/oresmen)
|
|
36
|
+
[](https://oresmen.readthedocs.io/en/latest/)
|
|
37
|
+
[](https://terrarium.evidencepub.io/v2/gh/WhiteSymmetry/oresmen/HEAD)
|
|
38
|
+
[](https://badge.fury.io/py/oresmen)
|
|
39
|
+
[](https://pepy.tech/projects/oresmen)
|
|
40
|
+
[](CODE_OF_CONDUCT.md)
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
<p align="left">
|
|
45
|
+
<table>
|
|
46
|
+
<tr>
|
|
47
|
+
<td style="text-align: center;">PyPI</td>
|
|
48
|
+
<td style="text-align: center;">
|
|
49
|
+
<a href="https://pypi.org/project/oresmen/">
|
|
50
|
+
<img src="https://badge.fury.io/py/oresmen.svg" alt="PyPI version" height="18"/>
|
|
51
|
+
</a>
|
|
52
|
+
</td>
|
|
53
|
+
</tr>
|
|
54
|
+
<tr>
|
|
55
|
+
<td style="text-align: center;">Conda</td>
|
|
56
|
+
<td style="text-align: center;">
|
|
57
|
+
<a href="https://anaconda.org/bilgi/oresmen">
|
|
58
|
+
<img src="https://anaconda.org/bilgi/oresmen/badges/version.svg" alt="conda-forge version" height="18"/>
|
|
59
|
+
</a>
|
|
60
|
+
</td>
|
|
61
|
+
</tr>
|
|
62
|
+
<tr>
|
|
63
|
+
<td style="text-align: center;">DOI</td>
|
|
64
|
+
<td style="text-align: center;">
|
|
65
|
+
<a href="https://doi.org/">
|
|
66
|
+
<img src="https://zenodo.org/badge/DOI/.svg" alt="DOI" height="18"/>
|
|
67
|
+
</a>
|
|
68
|
+
</td>
|
|
69
|
+
</tr>
|
|
70
|
+
<tr>
|
|
71
|
+
<td style="text-align: center;">License: MIT</td>
|
|
72
|
+
<td style="text-align: center;">
|
|
73
|
+
<a href="https://opensource.org/licenses/MIT">
|
|
74
|
+
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License" height="18"/>
|
|
75
|
+
</a>
|
|
76
|
+
</td>
|
|
77
|
+
</tr>
|
|
78
|
+
</table>
|
|
79
|
+
</p>
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
Oresme numbers refer to the sums related to the harmonic series.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
### **Türkçe Tanım:**
|
|
88
|
+
**Oresme Sayıları**, 14. yüzyılda Nicole Oresme tarafından incelenen matematiksel serilerdir. Oresme sayıları harmonik seriye ait toplamları ifade eder. İki türü vardır:
|
|
89
|
+
1. **\( \frac{n}{2^n} \) serisi** (Oresme'nin orijinal çalışması),
|
|
90
|
+
2. **Harmonik sayılar** (\( H_n = 1 + \frac{1}{2} + \cdots + \frac{1}{n} \)).
|
|
91
|
+
Bu sayılar, analiz ve sayı teorisinde önemli rol oynar.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
### **English Definition:**
|
|
96
|
+
**Oresme Numbers** are mathematical series studied by Nicole Oresme in the 14th century. Oresme numbers refer to the sums related to the harmonic series. They include two types:
|
|
97
|
+
1. The **\( \frac{n}{2^n} \) sequence** (Oresme's original work),
|
|
98
|
+
2. **Harmonic numbers** (\( H_n = 1 + \frac{1}{2} + \cdots + \frac{1}{n} \)).
|
|
99
|
+
These numbers play a key role in analysis and number theory.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
### **Fark/Karşılaştırma (Difference):**
|
|
104
|
+
- **Oresme'nin \( \frac{n}{2^n} \) serisi** ıraksaklık kanıtları için önemlidir.
|
|
105
|
+
- **Harmonik sayılar** (\( H_n \)) ise logaritmik büyüme gösterir ve \( n \to \infty \) iken ıraksar.
|
|
106
|
+
- Modern literatürde "Oresme numbers" terimi daha çok tarihsel bağlamda kullanılır.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Kurulum (Türkçe) / Installation (English)
|
|
111
|
+
|
|
112
|
+
### Python ile Kurulum / Install with pip, conda, mamba
|
|
113
|
+
```bash
|
|
114
|
+
pip install oresmen -U
|
|
115
|
+
python -m pip install -U oresmen
|
|
116
|
+
conda install bilgi::oresmen -y
|
|
117
|
+
mamba install bilgi::oresmen -y
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
```diff
|
|
121
|
+
- pip uninstall Oresme -y
|
|
122
|
+
+ pip install -U oresmen
|
|
123
|
+
+ python -m pip install -U oresmen
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
[PyPI](https://pypi.org/project/Oresme/)
|
|
127
|
+
|
|
128
|
+
### Test Kurulumu / Test Installation
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
pip install -i https://test.pypi.org/simple/ oresmen -U
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Github Master Kurulumu / GitHub Master Installation
|
|
135
|
+
|
|
136
|
+
**Terminal:**
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
pip install git+https://github.com/WhiteSymmetry/oresmen.git
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Jupyter Lab, Notebook, Visual Studio Code:**
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
!pip install git+https://github.com/WhiteSymmetry/oresmen.git
|
|
146
|
+
# or
|
|
147
|
+
%pip install git+https://github.com/WhiteSymmetry/oresmen.git
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Kullanım (Türkçe) / Usage (English)
|
|
153
|
+
|
|
154
|
+
Note: "\Lib\site-packages\numba\__init__.py"
|
|
155
|
+
|
|
156
|
+
if numpy_version > (2, 0):
|
|
157
|
+
msg = (f"Numba needs NumPy 2.0 or less. Got NumPy "
|
|
158
|
+
f"{numpy_version[0]}.{numpy_version[1]}.")
|
|
159
|
+
raise ImportError(msg)
|
|
160
|
+
|
|
161
|
+
-->
|
|
162
|
+
|
|
163
|
+
if numpy_version > (2, 5):
|
|
164
|
+
msg = (f"Numba needs NumPy 2.5 or less. Got NumPy "
|
|
165
|
+
f"{numpy_version[0]}.{numpy_version[1]}.")
|
|
166
|
+
raise ImportError(msg)
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
import oresmen as on
|
|
170
|
+
|
|
171
|
+
# Doğrudan erişim (on.main.harmonic_number yerine)
|
|
172
|
+
n = 100
|
|
173
|
+
hn = on.harmonic_number(n)
|
|
174
|
+
print(f"H_{n} = {hn}")
|
|
175
|
+
|
|
176
|
+
# Enum sınıfına doğrudan erişim
|
|
177
|
+
approx_hn = on.harmonic_number_approx(
|
|
178
|
+
n,
|
|
179
|
+
method=on.ApproximationMethod.EULER_MASCHERONI
|
|
180
|
+
)
|
|
181
|
+
print(f"H_{n} (Yaklaşık) = {approx_hn}")
|
|
182
|
+
|
|
183
|
+
# Numba ile hızlandırılmış diziye erişim
|
|
184
|
+
sums_array = on.harmonic_numbers_numba(10)
|
|
185
|
+
print(f"İlk 10 harmonik sayı: {sums_array}")
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
import oresmen as on
|
|
190
|
+
import numpy as np
|
|
191
|
+
import numba
|
|
192
|
+
import time
|
|
193
|
+
import matplotlib.pyplot as plt
|
|
194
|
+
|
|
195
|
+
# Simple usage example
|
|
196
|
+
plt.figure(figsize=(10, 5))
|
|
197
|
+
plt.plot(on.harmonic_numbers_numba(500))
|
|
198
|
+
plt.title("First 5000000 Harmonic Numbers")
|
|
199
|
+
plt.xlabel("n")
|
|
200
|
+
plt.ylabel("H(n)")
|
|
201
|
+
plt.show()
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
import oresmen
|
|
206
|
+
oresmen.__version__
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
import importlib
|
|
211
|
+
import inspect
|
|
212
|
+
import oresmen as on # Varsa import hatasını yakalamak için
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def diagnose_module(module_name):
|
|
216
|
+
try:
|
|
217
|
+
# Modülü yükle
|
|
218
|
+
module = importlib.import_module(module_name)
|
|
219
|
+
|
|
220
|
+
print(f"\n{' Modül Tanılama Raporu ':=^80}")
|
|
221
|
+
print(f"Modül adı: {module_name}")
|
|
222
|
+
print(f"Modül dosya yolu: {inspect.getfile(module)}")
|
|
223
|
+
|
|
224
|
+
# Modülün tüm özelliklerini listele
|
|
225
|
+
print("\nModülde bulunan özellikler:")
|
|
226
|
+
members = inspect.getmembers(module)
|
|
227
|
+
public_members = [name for name, _ in members if not name.startswith('_')]
|
|
228
|
+
print(public_members)
|
|
229
|
+
|
|
230
|
+
# Özel olarak kontrol edilecek fonksiyonlar
|
|
231
|
+
required_functions = [
|
|
232
|
+
'oresme_sequence',
|
|
233
|
+
'harmonic_numbers',
|
|
234
|
+
'harmonic_number',
|
|
235
|
+
'harmonic_number_numba',
|
|
236
|
+
'harmonic_numbers_numba',
|
|
237
|
+
'harmonic_generator_numba',
|
|
238
|
+
'harmonic_number_approx'
|
|
239
|
+
]
|
|
240
|
+
|
|
241
|
+
print("\nEksik olan fonksiyonlar:")
|
|
242
|
+
missing = [fn for fn in required_functions if not hasattr(module, fn)]
|
|
243
|
+
print(missing if missing else "Tüm gerekli fonksiyonlar mevcut")
|
|
244
|
+
|
|
245
|
+
# __all__ değişkenini kontrol et
|
|
246
|
+
print("\n__all__ değişkeni:")
|
|
247
|
+
if hasattr(module, '__all__'):
|
|
248
|
+
print(module.__all__)
|
|
249
|
+
else:
|
|
250
|
+
print("__all__ tanımlı değil (tüm public fonksiyonlar içe aktarılır)")
|
|
251
|
+
|
|
252
|
+
except ImportError as e:
|
|
253
|
+
print(f"\nHATA: Modül yüklenemedi - {e}")
|
|
254
|
+
except Exception as e:
|
|
255
|
+
print(f"\nBeklenmeyen hata: {e}")
|
|
256
|
+
|
|
257
|
+
# Tanılama çalıştır
|
|
258
|
+
diagnose_module('oresmen')
|
|
259
|
+
|
|
260
|
+
# Alternatif olarak doğrudan kontrol
|
|
261
|
+
print("\nDoğrudan fonksiyon varlığı kontrolü:")
|
|
262
|
+
try:
|
|
263
|
+
print("harmonic_numbers_numba mevcut mu?", hasattr(on, 'harmonic_numbers_numba'))
|
|
264
|
+
if hasattr(on, 'harmonic_numbers_numba'):
|
|
265
|
+
print("Fonksiyon imzası:", inspect.signature(on.harmonic_numbers_numba))
|
|
266
|
+
else:
|
|
267
|
+
print("Eksik fonksiyon: harmonic_numbers_numba")
|
|
268
|
+
except Exception as e:
|
|
269
|
+
print("Kontrol sırasında hata:", e)
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
# 1. Alternatif içe aktarma yöntemi
|
|
274
|
+
from oresmen import harmonic_numbers_numba # Doğrudan import deneyin
|
|
275
|
+
import oresmen as on
|
|
276
|
+
|
|
277
|
+
# 2. Modülü yeniden yükleme
|
|
278
|
+
import importlib
|
|
279
|
+
importlib.reload(on)
|
|
280
|
+
|
|
281
|
+
# 3. Fonksiyonun alternatif isimle var olup olmadığını kontrol
|
|
282
|
+
print("Alternatif fonksiyon isimleri:", [name for name in dir(on) if 'harmonic' in name.lower()])
|
|
283
|
+
```
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
### Development
|
|
287
|
+
```bash
|
|
288
|
+
# Clone the repository
|
|
289
|
+
git clone https://github.com/WhiteSymmetry/oresmen.git
|
|
290
|
+
cd oresmen
|
|
291
|
+
|
|
292
|
+
# Install in development mode
|
|
293
|
+
python -m pip install -ve . # Install package in development mode
|
|
294
|
+
|
|
295
|
+
# Run tests
|
|
296
|
+
pytest
|
|
297
|
+
|
|
298
|
+
Notebook, Jupyterlab, Colab, Visual Studio Code
|
|
299
|
+
!python -m pip install git+https://github.com/WhiteSymmetry/oresmen.git
|
|
300
|
+
```
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## Citation
|
|
304
|
+
|
|
305
|
+
If this library was useful to you in your research, please cite us. Following the [GitHub citation standards](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files), here is the recommended citation.
|
|
306
|
+
|
|
307
|
+
### BibTeX
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
### APA
|
|
311
|
+
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Keçeci, M. (2025). oresmen [Data set]. ResearchGate. https://doi.org/
|
|
315
|
+
|
|
316
|
+
Keçeci, M. (2025). oresmen [Data set]. figshare. https://doi.org/
|
|
317
|
+
|
|
318
|
+
Keçeci, M. (2025). oresmen [Data set]. WorkflowHub. https://doi.org/
|
|
319
|
+
|
|
320
|
+
Keçeci, M. (2025). oresmen. Open Science Articles (OSAs), Zenodo. https://doi.org/
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Chicago
|
|
324
|
+
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Keçeci, Mehmet. oresmen [Data set]. ResearchGate, 2025. https://doi.org/
|
|
328
|
+
|
|
329
|
+
Keçeci, Mehmet (2025). oresmen [Data set]. figshare, 2025. https://doi.org/
|
|
330
|
+
|
|
331
|
+
Keçeci, Mehmet. oresmen [Data set]. WorkflowHub, 2025. https://doi.org/
|
|
332
|
+
|
|
333
|
+
Keçeci, Mehmet. oresmen. Open Science Articles (OSAs), Zenodo, 2025. https://doi.org/
|
|
334
|
+
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
### Lisans (Türkçe) / License (English)
|
|
339
|
+
|
|
340
|
+
```
|
|
341
|
+
This project is licensed under the MIT License.
|
|
342
|
+
```
|
|
343
|
+
|
oresmen-0.1.0/README.md
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# Oresme Numba
|
|
2
|
+
|
|
3
|
+
[](https://doi.org/)
|
|
4
|
+
|
|
5
|
+
[](https://doi.org/)
|
|
6
|
+
|
|
7
|
+
[](https://doi.org/)
|
|
8
|
+
|
|
9
|
+
[](https://doi.org/)
|
|
10
|
+
|
|
11
|
+
[](https://anaconda.org/bilgi/oresmen)
|
|
12
|
+
[](https://anaconda.org/bilgi/oresmen)
|
|
13
|
+
[](https://anaconda.org/bilgi/oresmen)
|
|
14
|
+
[](https://anaconda.org/bilgi/oresmen)
|
|
15
|
+
[](https://opensource.org/)
|
|
16
|
+
[](https://opensource.org/licenses/MIT)
|
|
17
|
+
|
|
18
|
+
[](https://github.com/WhiteSymmetry/oresmen/actions/workflows/python_ci.yml)
|
|
19
|
+
[](https://codecov.io/gh/WhiteSymmetry/oresmen)
|
|
20
|
+
[](https://oresmen.readthedocs.io/en/latest/)
|
|
21
|
+
[](https://terrarium.evidencepub.io/v2/gh/WhiteSymmetry/oresmen/HEAD)
|
|
22
|
+
[](https://badge.fury.io/py/oresmen)
|
|
23
|
+
[](https://pepy.tech/projects/oresmen)
|
|
24
|
+
[](CODE_OF_CONDUCT.md)
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
<p align="left">
|
|
29
|
+
<table>
|
|
30
|
+
<tr>
|
|
31
|
+
<td style="text-align: center;">PyPI</td>
|
|
32
|
+
<td style="text-align: center;">
|
|
33
|
+
<a href="https://pypi.org/project/oresmen/">
|
|
34
|
+
<img src="https://badge.fury.io/py/oresmen.svg" alt="PyPI version" height="18"/>
|
|
35
|
+
</a>
|
|
36
|
+
</td>
|
|
37
|
+
</tr>
|
|
38
|
+
<tr>
|
|
39
|
+
<td style="text-align: center;">Conda</td>
|
|
40
|
+
<td style="text-align: center;">
|
|
41
|
+
<a href="https://anaconda.org/bilgi/oresmen">
|
|
42
|
+
<img src="https://anaconda.org/bilgi/oresmen/badges/version.svg" alt="conda-forge version" height="18"/>
|
|
43
|
+
</a>
|
|
44
|
+
</td>
|
|
45
|
+
</tr>
|
|
46
|
+
<tr>
|
|
47
|
+
<td style="text-align: center;">DOI</td>
|
|
48
|
+
<td style="text-align: center;">
|
|
49
|
+
<a href="https://doi.org/">
|
|
50
|
+
<img src="https://zenodo.org/badge/DOI/.svg" alt="DOI" height="18"/>
|
|
51
|
+
</a>
|
|
52
|
+
</td>
|
|
53
|
+
</tr>
|
|
54
|
+
<tr>
|
|
55
|
+
<td style="text-align: center;">License: MIT</td>
|
|
56
|
+
<td style="text-align: center;">
|
|
57
|
+
<a href="https://opensource.org/licenses/MIT">
|
|
58
|
+
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License" height="18"/>
|
|
59
|
+
</a>
|
|
60
|
+
</td>
|
|
61
|
+
</tr>
|
|
62
|
+
</table>
|
|
63
|
+
</p>
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
Oresme numbers refer to the sums related to the harmonic series.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
### **Türkçe Tanım:**
|
|
72
|
+
**Oresme Sayıları**, 14. yüzyılda Nicole Oresme tarafından incelenen matematiksel serilerdir. Oresme sayıları harmonik seriye ait toplamları ifade eder. İki türü vardır:
|
|
73
|
+
1. **\( \frac{n}{2^n} \) serisi** (Oresme'nin orijinal çalışması),
|
|
74
|
+
2. **Harmonik sayılar** (\( H_n = 1 + \frac{1}{2} + \cdots + \frac{1}{n} \)).
|
|
75
|
+
Bu sayılar, analiz ve sayı teorisinde önemli rol oynar.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
### **English Definition:**
|
|
80
|
+
**Oresme Numbers** are mathematical series studied by Nicole Oresme in the 14th century. Oresme numbers refer to the sums related to the harmonic series. They include two types:
|
|
81
|
+
1. The **\( \frac{n}{2^n} \) sequence** (Oresme's original work),
|
|
82
|
+
2. **Harmonic numbers** (\( H_n = 1 + \frac{1}{2} + \cdots + \frac{1}{n} \)).
|
|
83
|
+
These numbers play a key role in analysis and number theory.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
### **Fark/Karşılaştırma (Difference):**
|
|
88
|
+
- **Oresme'nin \( \frac{n}{2^n} \) serisi** ıraksaklık kanıtları için önemlidir.
|
|
89
|
+
- **Harmonik sayılar** (\( H_n \)) ise logaritmik büyüme gösterir ve \( n \to \infty \) iken ıraksar.
|
|
90
|
+
- Modern literatürde "Oresme numbers" terimi daha çok tarihsel bağlamda kullanılır.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Kurulum (Türkçe) / Installation (English)
|
|
95
|
+
|
|
96
|
+
### Python ile Kurulum / Install with pip, conda, mamba
|
|
97
|
+
```bash
|
|
98
|
+
pip install oresmen -U
|
|
99
|
+
python -m pip install -U oresmen
|
|
100
|
+
conda install bilgi::oresmen -y
|
|
101
|
+
mamba install bilgi::oresmen -y
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```diff
|
|
105
|
+
- pip uninstall Oresme -y
|
|
106
|
+
+ pip install -U oresmen
|
|
107
|
+
+ python -m pip install -U oresmen
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
[PyPI](https://pypi.org/project/Oresme/)
|
|
111
|
+
|
|
112
|
+
### Test Kurulumu / Test Installation
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
pip install -i https://test.pypi.org/simple/ oresmen -U
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Github Master Kurulumu / GitHub Master Installation
|
|
119
|
+
|
|
120
|
+
**Terminal:**
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
pip install git+https://github.com/WhiteSymmetry/oresmen.git
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Jupyter Lab, Notebook, Visual Studio Code:**
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
!pip install git+https://github.com/WhiteSymmetry/oresmen.git
|
|
130
|
+
# or
|
|
131
|
+
%pip install git+https://github.com/WhiteSymmetry/oresmen.git
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Kullanım (Türkçe) / Usage (English)
|
|
137
|
+
|
|
138
|
+
Note: "\Lib\site-packages\numba\__init__.py"
|
|
139
|
+
|
|
140
|
+
if numpy_version > (2, 0):
|
|
141
|
+
msg = (f"Numba needs NumPy 2.0 or less. Got NumPy "
|
|
142
|
+
f"{numpy_version[0]}.{numpy_version[1]}.")
|
|
143
|
+
raise ImportError(msg)
|
|
144
|
+
|
|
145
|
+
-->
|
|
146
|
+
|
|
147
|
+
if numpy_version > (2, 5):
|
|
148
|
+
msg = (f"Numba needs NumPy 2.5 or less. Got NumPy "
|
|
149
|
+
f"{numpy_version[0]}.{numpy_version[1]}.")
|
|
150
|
+
raise ImportError(msg)
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
import oresmen as on
|
|
154
|
+
|
|
155
|
+
# Doğrudan erişim (on.main.harmonic_number yerine)
|
|
156
|
+
n = 100
|
|
157
|
+
hn = on.harmonic_number(n)
|
|
158
|
+
print(f"H_{n} = {hn}")
|
|
159
|
+
|
|
160
|
+
# Enum sınıfına doğrudan erişim
|
|
161
|
+
approx_hn = on.harmonic_number_approx(
|
|
162
|
+
n,
|
|
163
|
+
method=on.ApproximationMethod.EULER_MASCHERONI
|
|
164
|
+
)
|
|
165
|
+
print(f"H_{n} (Yaklaşık) = {approx_hn}")
|
|
166
|
+
|
|
167
|
+
# Numba ile hızlandırılmış diziye erişim
|
|
168
|
+
sums_array = on.harmonic_numbers_numba(10)
|
|
169
|
+
print(f"İlk 10 harmonik sayı: {sums_array}")
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
import oresmen as on
|
|
174
|
+
import numpy as np
|
|
175
|
+
import numba
|
|
176
|
+
import time
|
|
177
|
+
import matplotlib.pyplot as plt
|
|
178
|
+
|
|
179
|
+
# Simple usage example
|
|
180
|
+
plt.figure(figsize=(10, 5))
|
|
181
|
+
plt.plot(on.harmonic_numbers_numba(500))
|
|
182
|
+
plt.title("First 5000000 Harmonic Numbers")
|
|
183
|
+
plt.xlabel("n")
|
|
184
|
+
plt.ylabel("H(n)")
|
|
185
|
+
plt.show()
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
import oresmen
|
|
190
|
+
oresmen.__version__
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
import importlib
|
|
195
|
+
import inspect
|
|
196
|
+
import oresmen as on # Varsa import hatasını yakalamak için
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def diagnose_module(module_name):
|
|
200
|
+
try:
|
|
201
|
+
# Modülü yükle
|
|
202
|
+
module = importlib.import_module(module_name)
|
|
203
|
+
|
|
204
|
+
print(f"\n{' Modül Tanılama Raporu ':=^80}")
|
|
205
|
+
print(f"Modül adı: {module_name}")
|
|
206
|
+
print(f"Modül dosya yolu: {inspect.getfile(module)}")
|
|
207
|
+
|
|
208
|
+
# Modülün tüm özelliklerini listele
|
|
209
|
+
print("\nModülde bulunan özellikler:")
|
|
210
|
+
members = inspect.getmembers(module)
|
|
211
|
+
public_members = [name for name, _ in members if not name.startswith('_')]
|
|
212
|
+
print(public_members)
|
|
213
|
+
|
|
214
|
+
# Özel olarak kontrol edilecek fonksiyonlar
|
|
215
|
+
required_functions = [
|
|
216
|
+
'oresme_sequence',
|
|
217
|
+
'harmonic_numbers',
|
|
218
|
+
'harmonic_number',
|
|
219
|
+
'harmonic_number_numba',
|
|
220
|
+
'harmonic_numbers_numba',
|
|
221
|
+
'harmonic_generator_numba',
|
|
222
|
+
'harmonic_number_approx'
|
|
223
|
+
]
|
|
224
|
+
|
|
225
|
+
print("\nEksik olan fonksiyonlar:")
|
|
226
|
+
missing = [fn for fn in required_functions if not hasattr(module, fn)]
|
|
227
|
+
print(missing if missing else "Tüm gerekli fonksiyonlar mevcut")
|
|
228
|
+
|
|
229
|
+
# __all__ değişkenini kontrol et
|
|
230
|
+
print("\n__all__ değişkeni:")
|
|
231
|
+
if hasattr(module, '__all__'):
|
|
232
|
+
print(module.__all__)
|
|
233
|
+
else:
|
|
234
|
+
print("__all__ tanımlı değil (tüm public fonksiyonlar içe aktarılır)")
|
|
235
|
+
|
|
236
|
+
except ImportError as e:
|
|
237
|
+
print(f"\nHATA: Modül yüklenemedi - {e}")
|
|
238
|
+
except Exception as e:
|
|
239
|
+
print(f"\nBeklenmeyen hata: {e}")
|
|
240
|
+
|
|
241
|
+
# Tanılama çalıştır
|
|
242
|
+
diagnose_module('oresmen')
|
|
243
|
+
|
|
244
|
+
# Alternatif olarak doğrudan kontrol
|
|
245
|
+
print("\nDoğrudan fonksiyon varlığı kontrolü:")
|
|
246
|
+
try:
|
|
247
|
+
print("harmonic_numbers_numba mevcut mu?", hasattr(on, 'harmonic_numbers_numba'))
|
|
248
|
+
if hasattr(on, 'harmonic_numbers_numba'):
|
|
249
|
+
print("Fonksiyon imzası:", inspect.signature(on.harmonic_numbers_numba))
|
|
250
|
+
else:
|
|
251
|
+
print("Eksik fonksiyon: harmonic_numbers_numba")
|
|
252
|
+
except Exception as e:
|
|
253
|
+
print("Kontrol sırasında hata:", e)
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
```python
|
|
257
|
+
# 1. Alternatif içe aktarma yöntemi
|
|
258
|
+
from oresmen import harmonic_numbers_numba # Doğrudan import deneyin
|
|
259
|
+
import oresmen as on
|
|
260
|
+
|
|
261
|
+
# 2. Modülü yeniden yükleme
|
|
262
|
+
import importlib
|
|
263
|
+
importlib.reload(on)
|
|
264
|
+
|
|
265
|
+
# 3. Fonksiyonun alternatif isimle var olup olmadığını kontrol
|
|
266
|
+
print("Alternatif fonksiyon isimleri:", [name for name in dir(on) if 'harmonic' in name.lower()])
|
|
267
|
+
```
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
### Development
|
|
271
|
+
```bash
|
|
272
|
+
# Clone the repository
|
|
273
|
+
git clone https://github.com/WhiteSymmetry/oresmen.git
|
|
274
|
+
cd oresmen
|
|
275
|
+
|
|
276
|
+
# Install in development mode
|
|
277
|
+
python -m pip install -ve . # Install package in development mode
|
|
278
|
+
|
|
279
|
+
# Run tests
|
|
280
|
+
pytest
|
|
281
|
+
|
|
282
|
+
Notebook, Jupyterlab, Colab, Visual Studio Code
|
|
283
|
+
!python -m pip install git+https://github.com/WhiteSymmetry/oresmen.git
|
|
284
|
+
```
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## Citation
|
|
288
|
+
|
|
289
|
+
If this library was useful to you in your research, please cite us. Following the [GitHub citation standards](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files), here is the recommended citation.
|
|
290
|
+
|
|
291
|
+
### BibTeX
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
### APA
|
|
295
|
+
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Keçeci, M. (2025). oresmen [Data set]. ResearchGate. https://doi.org/
|
|
299
|
+
|
|
300
|
+
Keçeci, M. (2025). oresmen [Data set]. figshare. https://doi.org/
|
|
301
|
+
|
|
302
|
+
Keçeci, M. (2025). oresmen [Data set]. WorkflowHub. https://doi.org/
|
|
303
|
+
|
|
304
|
+
Keçeci, M. (2025). oresmen. Open Science Articles (OSAs), Zenodo. https://doi.org/
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Chicago
|
|
308
|
+
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Keçeci, Mehmet. oresmen [Data set]. ResearchGate, 2025. https://doi.org/
|
|
312
|
+
|
|
313
|
+
Keçeci, Mehmet (2025). oresmen [Data set]. figshare, 2025. https://doi.org/
|
|
314
|
+
|
|
315
|
+
Keçeci, Mehmet. oresmen [Data set]. WorkflowHub, 2025. https://doi.org/
|
|
316
|
+
|
|
317
|
+
Keçeci, Mehmet. oresmen. Open Science Articles (OSAs), Zenodo, 2025. https://doi.org/
|
|
318
|
+
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
### Lisans (Türkçe) / License (English)
|
|
323
|
+
|
|
324
|
+
```
|
|
325
|
+
This project is licensed under the MIT License.
|
|
326
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "oresmen"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A module for generating Oresme numbers (harmonic series partial sums)"
|
|
5
|
+
authors = ["Mehmet Keçeci <mkececi@yaani.com>"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
|
|
9
|
+
[tool.poetry.dependencies]
|
|
10
|
+
python = "^3.11"
|
|
11
|
+
numpy = "^2.3.2"
|
|
12
|
+
|
|
13
|
+
[tool.poetry.group.build.dependencies]
|
|
14
|
+
setuptools = "^80.9.0"
|
|
15
|
+
cython = "^3.1.2"
|
|
16
|
+
|
|
17
|
+
[build-system]
|
|
18
|
+
requires = ["poetry-core", "cython", "setuptools>=61.0"]
|
|
19
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# src/oresmen/__init__.py
|
|
2
|
+
"""
|
|
3
|
+
A module for generating Oresme numbers (harmonic series partial sums)
|
|
4
|
+
Oresme sayıları (harmonik seri kısmi toplamları) üretmek için bir modül.
|
|
5
|
+
Bu sürüm, hesaplamaları hızlandırmak için Numba kullanır.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
# Projenizin versiyon numarasını belirtmek iyi bir pratiktir.
|
|
9
|
+
__version__ = "0.1.0"
|
|
10
|
+
|
|
11
|
+
# main.py dosyasındaki ana sınıfları ve fonksiyonları buraya import et
|
|
12
|
+
from .main import (
|
|
13
|
+
# Temel Hesaplama Fonksiyonları
|
|
14
|
+
harmonic_number, # Numba ile optimize edilmiş en hızlı tekil float hesaplama
|
|
15
|
+
harmonic_numbers_numba, # Numba ile optimize edilmiş float dizisi hesaplama
|
|
16
|
+
harmonic_numbers, # Kesin sonuçlar için yavaş ama hassas Fraction tabanlı hesaplama
|
|
17
|
+
oresme_sequence, # Orijinal Oresme dizisi fonksiyonu
|
|
18
|
+
harmonic_generator_numba, # Numba destekli üreteç
|
|
19
|
+
|
|
20
|
+
# Yaklaşım (Approximation) Fonksiyonları
|
|
21
|
+
harmonic_number_approx, # Yaklaşık değer hesaplayan ana fonksiyon
|
|
22
|
+
harmonic_sum_approx_numba, # Numba ile optimize edilmiş yaklaşık değer hesaplama
|
|
23
|
+
|
|
24
|
+
# Kullanıcıların ihtiyaç duyacağı yardımcılar
|
|
25
|
+
ApproximationMethod, # Yaklaşım metodunu seçmek için gereken Enum sınıfı
|
|
26
|
+
EULER_MASCHERONI, # Önemli bir matematiksel sabit
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# __all__ listesi, "from oresmen import *" komutu kullanıldığında nelerin import edileceğini tanımlar.
|
|
30
|
+
# Bu, kütüphanenizin genel arayüzünü (public API) belirlemek için iyi bir pratiktir.
|
|
31
|
+
__all__ = [
|
|
32
|
+
# Temel Hesaplama Fonksiyonları
|
|
33
|
+
"harmonic_number",
|
|
34
|
+
"harmonic_numbers_numba",
|
|
35
|
+
"harmonic_numbers",
|
|
36
|
+
"oresme_sequence",
|
|
37
|
+
"harmonic_generator_numba",
|
|
38
|
+
|
|
39
|
+
# Yaklaşım Fonksiyonları
|
|
40
|
+
"harmonic_number_approx",
|
|
41
|
+
"harmonic_sum_approx_numba",
|
|
42
|
+
|
|
43
|
+
# Yardımcı Sınıflar ve Sabitler
|
|
44
|
+
"ApproximationMethod",
|
|
45
|
+
"EULER_MASCHERONI",
|
|
46
|
+
]
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# _version.py
|
|
2
|
+
|
|
3
|
+
__version__ = "0.1.0"
|
|
4
|
+
__license__ = "MIT"
|
|
5
|
+
__description__ = "A module for generating Oresme numbers (harmonic series partial sums)"
|
|
6
|
+
__author__ = "Mehmet Keçeci"
|
|
7
|
+
__url__ = "https://github.com/WhiteSymmetry/oresmen"
|
|
8
|
+
__docs__ = "https://WhiteSymmetry.github.io/oresmen" # Opsiyonel: Dokümantasyon linki
|
|
9
|
+
__dependencies__ = ["python>=3.9"] # Diğer bağımlılıkları da ekleyebilirsiniz
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
# oresmen.py
|
|
2
|
+
"""
|
|
3
|
+
A module for generating Oresme numbers (harmonic series partial sums)
|
|
4
|
+
Oresme sayıları (harmonik seri kısmi toplamları) üretmek için bir modül.
|
|
5
|
+
Bu sürüm, hesaplamaları hızlandırmak için Numba kullanır.
|
|
6
|
+
"""
|
|
7
|
+
import os
|
|
8
|
+
import numba
|
|
9
|
+
import numpy as np
|
|
10
|
+
from functools import lru_cache
|
|
11
|
+
from fractions import Fraction
|
|
12
|
+
import math
|
|
13
|
+
from typing import List, Union, Generator, Tuple, Optional
|
|
14
|
+
import time
|
|
15
|
+
import logging
|
|
16
|
+
from enum import Enum, auto
|
|
17
|
+
|
|
18
|
+
# -----------------------------
|
|
19
|
+
# Logging Yapılandırması
|
|
20
|
+
# -----------------------------
|
|
21
|
+
logging.basicConfig(
|
|
22
|
+
level=logging.INFO,
|
|
23
|
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
24
|
+
handlers=[logging.StreamHandler()]
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
logger = logging.getLogger('harmonic_numba')
|
|
28
|
+
logger.propagate = False # Yinelenen logları engelle
|
|
29
|
+
|
|
30
|
+
# Handler'ı yalnızca bir kez ekle
|
|
31
|
+
if not logger.handlers:
|
|
32
|
+
ch = logging.StreamHandler()
|
|
33
|
+
ch.setLevel(logging.INFO)
|
|
34
|
+
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
35
|
+
ch.setFormatter(formatter)
|
|
36
|
+
logger.addHandler(ch)
|
|
37
|
+
|
|
38
|
+
# -----------------------------
|
|
39
|
+
# Sabitler ve Enum'lar
|
|
40
|
+
# -----------------------------
|
|
41
|
+
|
|
42
|
+
class ApproximationMethod(Enum):
|
|
43
|
+
"""Harmonik sayı yaklaştırma yöntemleri"""
|
|
44
|
+
EULER_MASCHERONI = auto()
|
|
45
|
+
EULER_MACLAURIN = auto()
|
|
46
|
+
ASYMPTOTIC = auto()
|
|
47
|
+
|
|
48
|
+
EULER_MASCHERONI = 0.57721566490153286060
|
|
49
|
+
EULER_MASCHERONI_FRACTION = Fraction(303847, 562250)
|
|
50
|
+
|
|
51
|
+
# -----------------------------
|
|
52
|
+
# Temel Fonksiyonlar
|
|
53
|
+
# -----------------------------
|
|
54
|
+
|
|
55
|
+
def oresme_sequence(n_terms: int, start: int = 1) -> List[float]:
|
|
56
|
+
"""Oresme dizisi: a_i = i / 2^i"""
|
|
57
|
+
if n_terms <= 0:
|
|
58
|
+
raise ValueError("Terim sayısı pozitif olmalıdır")
|
|
59
|
+
return [i / (2 ** i) for i in range(start, start + n_terms)]
|
|
60
|
+
|
|
61
|
+
@lru_cache(maxsize=128)
|
|
62
|
+
def harmonic_numbers(n_terms: int, start_index: int = 1) -> Tuple[Fraction]:
|
|
63
|
+
"""Kesirli harmonik sayılar (önbellekli)"""
|
|
64
|
+
if n_terms <= 0:
|
|
65
|
+
raise ValueError("n_terms pozitif olmalıdır")
|
|
66
|
+
if start_index <= 0:
|
|
67
|
+
raise ValueError("start_index pozitif olmalıdır")
|
|
68
|
+
|
|
69
|
+
sequence = []
|
|
70
|
+
current_sum = Fraction(0)
|
|
71
|
+
for i in range(start_index, start_index + n_terms):
|
|
72
|
+
current_sum += Fraction(1, i)
|
|
73
|
+
sequence.append(current_sum)
|
|
74
|
+
return tuple(sequence)
|
|
75
|
+
|
|
76
|
+
# Bu fonksiyon Numba ile de hızlandırılabilir.
|
|
77
|
+
@numba.njit
|
|
78
|
+
def harmonic_number(n: int) -> float:
|
|
79
|
+
"""n-inci harmonik sayı (float, Numba ile hızlandırılmış)"""
|
|
80
|
+
if n <= 0:
|
|
81
|
+
# njit modunda istisna yükseltme sınırlıdır, ancak basit durumlar çalışır.
|
|
82
|
+
raise ValueError("n pozitif olmalıdır")
|
|
83
|
+
total = 0.0
|
|
84
|
+
for k in range(1, n + 1):
|
|
85
|
+
total += 1.0 / k
|
|
86
|
+
return total
|
|
87
|
+
|
|
88
|
+
# -----------------------------
|
|
89
|
+
# Numba ile Optimize Edilmiş Fonksiyonlar
|
|
90
|
+
# -----------------------------
|
|
91
|
+
|
|
92
|
+
@numba.njit
|
|
93
|
+
def harmonic_number_numba(n: int) -> float:
|
|
94
|
+
"""JIT derlenmiş harmonik sayı fonksiyonu"""
|
|
95
|
+
return np.sum(1.0 / np.arange(1, n + 1))
|
|
96
|
+
|
|
97
|
+
@numba.njit
|
|
98
|
+
def harmonic_numbers_numba(n: int) -> np.ndarray:
|
|
99
|
+
"""Numba ile hızlandırılmış harmonik sayılar"""
|
|
100
|
+
return np.cumsum(1.0 / np.arange(1, n + 1))
|
|
101
|
+
|
|
102
|
+
def harmonic_generator_numba(n: int) -> Generator[float, None, None]:
|
|
103
|
+
"""Numba destekli harmonik sayı üreteci"""
|
|
104
|
+
sums = harmonic_numbers_numba(n)
|
|
105
|
+
for i in range(n):
|
|
106
|
+
yield float(sums[i])
|
|
107
|
+
|
|
108
|
+
# -----------------------------
|
|
109
|
+
# Yaklaştırma Fonksiyonları
|
|
110
|
+
# -----------------------------
|
|
111
|
+
|
|
112
|
+
def harmonic_number_approx(
|
|
113
|
+
n: int,
|
|
114
|
+
method: ApproximationMethod = ApproximationMethod.EULER_MASCHERONI,
|
|
115
|
+
k: int = 2
|
|
116
|
+
) -> float:
|
|
117
|
+
"""Yaklaşık harmonik sayı hesaplaması"""
|
|
118
|
+
if n <= 0:
|
|
119
|
+
raise ValueError("n pozitif olmalıdır")
|
|
120
|
+
|
|
121
|
+
if method == ApproximationMethod.EULER_MASCHERONI:
|
|
122
|
+
return math.log(n) + EULER_MASCHERONI + 1/(2*n) - 1/(12*n**2)
|
|
123
|
+
elif method == ApproximationMethod.EULER_MACLAURIN:
|
|
124
|
+
result = math.log(n) + EULER_MASCHERONI + 1/(2*n)
|
|
125
|
+
for i in range(1, k+1):
|
|
126
|
+
B = bernoulli_number(2*i)
|
|
127
|
+
term = B / (2*i) * (1/n)**(2*i)
|
|
128
|
+
result -= term
|
|
129
|
+
return result
|
|
130
|
+
elif method == ApproximationMethod.ASYMPTOTIC:
|
|
131
|
+
return math.log(n) + EULER_MASCHERONI + 1/(2*n)
|
|
132
|
+
else:
|
|
133
|
+
raise ValueError("Bilinmeyen yaklaştırma yöntemi")
|
|
134
|
+
|
|
135
|
+
@lru_cache(maxsize=32)
|
|
136
|
+
def bernoulli_number(n: int) -> float:
|
|
137
|
+
"""Bernoulli sayıları (önbellekli)"""
|
|
138
|
+
if n == 0: return 1.0
|
|
139
|
+
elif n == 1: return -0.5
|
|
140
|
+
elif n % 2 != 0: return 0.0
|
|
141
|
+
else:
|
|
142
|
+
from scipy.special import bernoulli
|
|
143
|
+
return bernoulli(n)[n]
|
|
144
|
+
|
|
145
|
+
# -----------------------------
|
|
146
|
+
# Performans Analizi
|
|
147
|
+
# -----------------------------
|
|
148
|
+
|
|
149
|
+
def benchmark_harmonic(n: int, runs: int = 10) -> dict:
|
|
150
|
+
"""Farklı hesaplama yöntemlerini karşılaştırır"""
|
|
151
|
+
results = {}
|
|
152
|
+
|
|
153
|
+
# Isınma çağrısı
|
|
154
|
+
_ = harmonic_number_numba(10)
|
|
155
|
+
|
|
156
|
+
# Saf Python (Döngü Numba tarafından hızlandırıldı)
|
|
157
|
+
start = time.perf_counter()
|
|
158
|
+
for _ in range(runs):
|
|
159
|
+
_ = harmonic_number(n)
|
|
160
|
+
results['pure_python_numba_loop'] = (time.perf_counter() - start)/runs
|
|
161
|
+
|
|
162
|
+
# Numba (NumPy ile)
|
|
163
|
+
start = time.perf_counter()
|
|
164
|
+
for _ in range(runs):
|
|
165
|
+
_ = harmonic_number_numba(n)
|
|
166
|
+
results['numba'] = (time.perf_counter() - start)/runs
|
|
167
|
+
|
|
168
|
+
# Yaklaşık
|
|
169
|
+
start = time.perf_counter()
|
|
170
|
+
for _ in range(runs):
|
|
171
|
+
_ = harmonic_number_approx(n)
|
|
172
|
+
results['approximate'] = (time.perf_counter() - start)/runs
|
|
173
|
+
|
|
174
|
+
return results
|
|
175
|
+
|
|
176
|
+
def compare_with_approximation(n: int) -> dict:
|
|
177
|
+
"""Tam ve yaklaşık değerleri karşılaştırır"""
|
|
178
|
+
exact = harmonic_number(n)
|
|
179
|
+
approx = harmonic_number_approx(n)
|
|
180
|
+
error = abs(exact - approx)
|
|
181
|
+
relative_error = error / exact if exact != 0 else 0
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
'exact': exact,
|
|
185
|
+
'approximate': approx,
|
|
186
|
+
'absolute_error': error,
|
|
187
|
+
'relative_error': relative_error,
|
|
188
|
+
'percentage_error': relative_error * 100
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
# -----------------------------
|
|
192
|
+
# Görselleştirme Fonksiyonları
|
|
193
|
+
# -----------------------------
|
|
194
|
+
|
|
195
|
+
def plot_comparative_performance(max_n=50000, step=5000, runs=10):
|
|
196
|
+
"""Karşılaştırmalı performans analizi"""
|
|
197
|
+
import matplotlib.pyplot as plt
|
|
198
|
+
|
|
199
|
+
# Veri hazırlığı
|
|
200
|
+
n_values = list(range(5000, max_n+1, step))
|
|
201
|
+
results = {
|
|
202
|
+
'python_loop': [],
|
|
203
|
+
'numba': [],
|
|
204
|
+
'approx': []
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
# Isınma çağrısı
|
|
208
|
+
_ = harmonic_number_numba(100)
|
|
209
|
+
|
|
210
|
+
for n in n_values:
|
|
211
|
+
# Python döngü performansı
|
|
212
|
+
py_times = []
|
|
213
|
+
for _ in range(runs):
|
|
214
|
+
start = time.perf_counter()
|
|
215
|
+
_ = harmonic_number(n)
|
|
216
|
+
py_times.append(time.perf_counter() - start)
|
|
217
|
+
|
|
218
|
+
# Numba performansı
|
|
219
|
+
numba_times = []
|
|
220
|
+
for _ in range(runs):
|
|
221
|
+
start = time.perf_counter()
|
|
222
|
+
_ = harmonic_number_numba(n)
|
|
223
|
+
numba_times.append(time.perf_counter() - start)
|
|
224
|
+
|
|
225
|
+
# Yaklaşık metot
|
|
226
|
+
approx_times = []
|
|
227
|
+
for _ in range(runs):
|
|
228
|
+
start = time.perf_counter()
|
|
229
|
+
_ = harmonic_number_approx(n)
|
|
230
|
+
approx_times.append(time.perf_counter() - start)
|
|
231
|
+
|
|
232
|
+
# Sonuçları milisaniye cinsinden sakla
|
|
233
|
+
results['python_loop'].append(np.mean(py_times)*1000)
|
|
234
|
+
results['numba'].append(np.mean(numba_times)*1000)
|
|
235
|
+
results['approx'].append(np.mean(approx_times)*1000)
|
|
236
|
+
|
|
237
|
+
# Çizim
|
|
238
|
+
plt.figure(figsize=(12, 8))
|
|
239
|
+
plt.plot(n_values, results['python_loop'], 'b-o', label='Saf Python Döngüsü (@njit)')
|
|
240
|
+
plt.plot(n_values, results['numba'], 'r-s', label='Numba (NumPy ile)')
|
|
241
|
+
plt.plot(n_values, results['approx'], 'g-^', label='Yaklaşık')
|
|
242
|
+
|
|
243
|
+
plt.title('Hesaplama Yöntemlerinin Performans Karşılaştırması')
|
|
244
|
+
plt.xlabel('n değeri')
|
|
245
|
+
plt.ylabel('Süre (ms)')
|
|
246
|
+
plt.grid(True)
|
|
247
|
+
plt.legend()
|
|
248
|
+
plt.tight_layout()
|
|
249
|
+
plt.show()
|
|
250
|
+
|
|
251
|
+
# Detaylı veri çıktısı
|
|
252
|
+
print("\nDetaylı Performans Verileri (milisaniye cinsinden):")
|
|
253
|
+
print(f"{'n':>8} | {'Python (@njit)':>15} | {'Numba (NumPy)':>15} | {'Yaklaşık':>10} | {'Hızlanma':>10}")
|
|
254
|
+
print("-" * 75)
|
|
255
|
+
for i, n in enumerate(n_values):
|
|
256
|
+
speedup = results['python_loop'][i] / results['numba'][i]
|
|
257
|
+
print(f"{n:8} | {results['python_loop'][i]:15.3f} | "
|
|
258
|
+
f"{results['numba'][i]:15.3f} | {results['approx'][i]:10.3f} | {speedup:9.2f}x")
|
|
259
|
+
|
|
260
|
+
# -----------------------------
|
|
261
|
+
# Gelişmiş Harmonik Yaklaştırmalar
|
|
262
|
+
# -----------------------------
|
|
263
|
+
|
|
264
|
+
@numba.njit
|
|
265
|
+
def harmonic_sum_approx_numba(n: np.ndarray,
|
|
266
|
+
method: int = 1, # 0:EULER_MASCHERONI, 1:EULER_MACLAURIN
|
|
267
|
+
order: int = 4) -> np.ndarray:
|
|
268
|
+
"""
|
|
269
|
+
Numba uyumlu optimize edilmiş harmonik yaklaştırma versiyonu.
|
|
270
|
+
Not: JIT uyumluluğu için Enum yerine tamsayı bayrakları kullanır.
|
|
271
|
+
"""
|
|
272
|
+
gamma = EULER_MASCHERONI
|
|
273
|
+
log_n = np.log(n)
|
|
274
|
+
inv_n = 1.0 / n
|
|
275
|
+
|
|
276
|
+
# Temel terimler
|
|
277
|
+
result = gamma + log_n
|
|
278
|
+
|
|
279
|
+
if method >= 1: # EULER_MASCHERONI 1/(2n) içerir
|
|
280
|
+
result += 0.5 * inv_n
|
|
281
|
+
|
|
282
|
+
if order >= 2:
|
|
283
|
+
inv_n2 = inv_n * inv_n
|
|
284
|
+
result -= inv_n2 / 12
|
|
285
|
+
|
|
286
|
+
if order >= 4:
|
|
287
|
+
inv_n4 = inv_n2 * inv_n2
|
|
288
|
+
result += inv_n4 / 120
|
|
289
|
+
|
|
290
|
+
if order >= 6:
|
|
291
|
+
inv_n6 = inv_n4 * inv_n2
|
|
292
|
+
result -= inv_n6 / 252
|
|
293
|
+
|
|
294
|
+
return result
|
|
295
|
+
|
|
296
|
+
# -----------------------------
|
|
297
|
+
# Yakınsama Analizi Yardımcıları
|
|
298
|
+
# -----------------------------
|
|
299
|
+
|
|
300
|
+
def harmonic_convergence_analysis(n_values: np.ndarray) -> dict:
|
|
301
|
+
"""
|
|
302
|
+
Verilen değerler için harmonik seri yakınsamasını analiz eder.
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
n_values: Analiz edilecek n değerleri dizisi.
|
|
306
|
+
|
|
307
|
+
Returns:
|
|
308
|
+
Sözlük:
|
|
309
|
+
- exact_sums: Tam harmonik toplamlar
|
|
310
|
+
- approx_sums: Yaklaşık toplamlar
|
|
311
|
+
- errors: Mutlak hatalar
|
|
312
|
+
- log_fit: Logaritmik uyum katsayıları
|
|
313
|
+
"""
|
|
314
|
+
# -1, 0 tabanlı indeksleme için
|
|
315
|
+
exact = harmonic_numbers_numba(n_values[-1])[n_values-1]
|
|
316
|
+
approx = harmonic_sum_approx_numba(n_values.astype(float))
|
|
317
|
+
|
|
318
|
+
return {
|
|
319
|
+
'exact_sums': exact,
|
|
320
|
+
'approx_sums': approx,
|
|
321
|
+
'errors': np.abs(exact - approx),
|
|
322
|
+
'log_fit': np.polyfit(np.log(n_values), exact, 1) # a*ln(n) + b
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
# -----------------------------
|
|
327
|
+
# Ana Program
|
|
328
|
+
# -----------------------------
|
|
329
|
+
|
|
330
|
+
def main():
|
|
331
|
+
"""Ana fonksiyon"""
|
|
332
|
+
# Hesaplamalar
|
|
333
|
+
logger.info("Oresme Dizisi (ilk 5 terim): %s", oresme_sequence(5))
|
|
334
|
+
logger.info("Kesirli Harmonik Sayılar (H1-H3): %s", harmonic_numbers(3))
|
|
335
|
+
logger.info("5. Harmonik Sayı: %.4f", harmonic_number(5))
|
|
336
|
+
|
|
337
|
+
# Yaklaşık değerler
|
|
338
|
+
logger.info("1000. Harmonik Sayı Yaklaştırmaları:")
|
|
339
|
+
logger.info("Euler-Mascheroni: %.8f",
|
|
340
|
+
harmonic_number_approx(1000, ApproximationMethod.EULER_MASCHERONI))
|
|
341
|
+
logger.info("Asimptotik: %.8f",
|
|
342
|
+
harmonic_number_approx(1000, ApproximationMethod.ASYMPTOTIC))
|
|
343
|
+
|
|
344
|
+
# Numba hesaplamaları
|
|
345
|
+
_ = harmonic_number_numba(10) # Isınma
|
|
346
|
+
logger.info("Numba ile Hızlandırılmış (H1-H5): %s", harmonic_numbers_numba(5))
|
|
347
|
+
logger.info("Numba Üreteci (H1-H3): %s", list(harmonic_generator_numba(3)))
|
|
348
|
+
|
|
349
|
+
# Performans testi
|
|
350
|
+
n_test = 100000
|
|
351
|
+
logger.info("Performans Testi (n=%d):", n_test)
|
|
352
|
+
bench_results = benchmark_harmonic(n_test)
|
|
353
|
+
for method, time_taken in bench_results.items():
|
|
354
|
+
logger.info("%25s: %.6f s/run", method, time_taken)
|
|
355
|
+
|
|
356
|
+
# Karşılaştırma
|
|
357
|
+
logger.info("Tam/Yaklaşık Değer Karşılaştırması (H_100):")
|
|
358
|
+
comparison = compare_with_approximation(100)
|
|
359
|
+
for key, value in comparison.items():
|
|
360
|
+
logger.info("%20s: %.10f", key, value)
|
|
361
|
+
|
|
362
|
+
if __name__ == "__main__":
|
|
363
|
+
main()
|
|
364
|
+
plot_comparative_performance()
|