forked from Bumpkin-Pi/QuadraticRegression
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqrtm1___.py
70 lines (56 loc) · 1.9 KB
/
sqrtm1___.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# modified, from: https://github.com/Bumpkin-Pi/QuadraticRegression
import math
import sys
import pandas as pd
import matplotlib.pyplot as plt
from math import pow as toPower
import numpy as np
data = pd.DataFrame({
"x": [100355, 200700, 272770, 330855, 388342],
"y": [447.1, 2144.4, 3748.0, 5311.2, 8741.8]
})
data2 = pd.DataFrame({
"x2": [100355, 200700, 272770, 330855, 388342, 1000000],
"y2": [647.6, 2812.2, 5406.6, 7931.3, 12018.3, 93640.8]
})
Σx = 0
Σy = 0
Σxy = 0
Σx2 = 0
Σx3 = 0
Σx4 = 0
Σx2y = 0
n = len(data)
a = 0
b = 0
c = 0
for i in range(len(data2)):
plt.scatter([data2.iloc[i].x2], [data2.iloc[i].y2], color="grey")
for i in range(len(data)):
Σx += data.iloc[i].x
Σy += data.iloc[i].y
Σxy += data.iloc[i].x * data.iloc[i].y
Σx2 += toPower(data.iloc[i].x, 2)
Σx3 += toPower(data.iloc[i].x, 3)
Σx4 += toPower(data.iloc[i].x, 4)
Σx2y += toPower(data.iloc[i].x, 2) * data.iloc[i].y
plt.scatter([data.iloc[i].x], [data.iloc[i].y], color="black")
a = np.array([[Σx4, Σx3, Σx2], [Σx3, Σx2, Σx], [Σx2, Σx, n]])
b = np.array([Σx2y, Σxy, Σy])
solve = np.linalg.solve(a, b)
print((f'y = {solve[0]}x² + {solve[1]}x + {solve[2]}').replace("+ -", "- "))
x = np.linspace(80000, 1020000, 1000)
x2 = np.linspace(80000, 1020000, 1000)
y = (x**2)*solve[0] + solve[1]*x + solve[2]
plt.plot(x, y)
y2 = (x**2)*1.0554194832720814e-07 - x*0.012866576114746796 + 963.5694282158807
plt.plot(x2, y2)
font = {'family': 'monospace',
'color': 'darkred',
'weight': 'normal',
'size': 12,
}
plt.title('i7-11850H mpz_powm() benchmark; determines sqrt(-1) (mod p),\nsmallest quadratic non-residue deterministic powm(); C++ with libgmpxx', fontsize=12)
plt.ylabel('mpz_powm(res, sqnr, p/4, p) runtime [s]', fontsize=8, fontdict=font)
plt.xlabel('prime p [decimal digits] (bottom curve: faster 7600X CPU) ', fontsize=12)
plt.show()