-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
396 lines (334 loc) · 7.14 KB
/
functions.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
import math
import numpy as np
epsylon = 10E-5
#((A^TxA)^-1)xA^Tx1
def calculate_conic_coefficients(x):
xt = x.T
ones = np.ones((x.shape[0], 1))
xtx = np.matmul(xt, x)
xtx1 = np.linalg.inv(xtx)
xtx1xt = np.matmul(xtx1, xt)
result = np.matmul(xtx1xt, ones)
coeffs = [result[i][0] for i in range(x.shape[1])]
return list(coeffs)
def least_squares_XAB(x, b):
xt = x.T
xtx = np.matmul(xt, x)
xtx1 = np.linalg.inv(xtx)
xtx1xt = np.matmul(xtx1, xt)
result = np.matmul(xtx1xt, b)
coeffs = [result[i][0] for i in range(x.shape[1])]
return list(coeffs)
def get_derivation(func, point, ind1, ind2):
v1_eps = get_epsyloned_point(point, ind1)
v2_eps = get_epsyloned_point(point, ind2)
still = func(point)
moved_v1 = func(v1_eps)
moved_v2 = func(v2_eps)
dv1 = moved_v1 - still
dv2 = moved_v2 - still
derr = - dv2/dv1
return derr
def get_epsyloned_point(point, ind):
new_point = []
for i in range(len(point)):
if i == ind:
new_point.append(point[i] + epsylon)
else:
new_point.append(point[i])
return new_point
def calc_sphere_rad5_xc0_yc0_zc0(point):
x, y, z = point[0], point[1], point[2]
return x*x + y*y + z*z - 25
def sphere_calc_func(radius, xc, yc, zc):
def calc_sphere(point):
x, y, z = point[0], point[1], point[2]
return (x-xc)**2 + (y-yc)**2 + (z-zc)**2 - radius*radius
return calc_sphere
"""
Solved by Eureka: N0
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 16
"""
def calc_1_6_20_a(point):
theta = point[0]
f = point[1]
return f - math.exp(-theta*theta / 2.0) / math.sqrt(2.0 * math.pi)
"""
Solved by Eureka: N0
Solved by AI-Feynman: YES
Data needed: 100
Solution time (s): 2992
"""
def calc_1_6_2(point):
sigma = point[0]
theta = point[1]
f = point[2]
return f - math.exp(-theta*theta / (2.0 * sigma * sigma)) / math.sqrt(2.0 * math.pi * sigma * sigma)
"""
Solved by Eureka: N0
Solved by AI-Feynman: YES
Data needed: 100
Solution time (s): 544
"""
def calc_1_8_14(point):
x1 = point[0]
x2 = point[1]
y1 = point[2]
y2 = point[3]
d = point[4]
return d - math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 12
"""
def calc_1_11_19(point):
x1 = point[0]
x2 = point[1]
x3 = point[2]
y1 = point[3]
y2 = point[4]
y3 = point[5]
A = point[6]
return A - (x1*y1 + x2*y2 + x3*y3)
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 100
Solution time (s): 184
"""
def calc_1_12_1(point):
mi = point[0]
nn = point[1]
F = point[2]
return F - mi * nn
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 22
"""
def calc_1_13_4(point):
m = point[0]
v = point[1]
u = point[2]
w = point[3]
K = point[4]
return K - 0.5*m*(v*v + u*u + w*w)
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 12
"""
def calc_1_14_3(point):
m = point[0]
g = point[1]
z = point[2]
U = point[3]
return U - m*g*z
"""
Solved by Eureka: NO
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 13
"""
def calc_1_15_10(point):
m0 = point[0]
v = point[1]
c = point[2]
p = point[3]
return p - m0*v / math.sqrt(1 - v**2/c**2)
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 17
"""
def calc_1_18_16(point):
m = point[0]
r = point[1]
v = point[2]
theta = point[3]
L = point[4]
return L - m *r*v*math.sin(theta)
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 22
"""
def calc_1_18_4(point):
m1 = point[0]
m2 = point[1]
r1 = point[2]
r2 = point[3]
r = point[4]
return r - (m1*r1 + m2*r2) / (m1+m2)
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 100
Solution time (s): 530
"""
def calc_1_26_2(point):
n = point[0]
theta2 = point[1]
theta1 = point[2]
return theta1 - math.asin(n * math.sin(theta2))
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 100
Solution time (s): 7032
"""
def calc_1_37_4(point):
I1 = point[0]
I2 = point[1]
delta = point[2]
I_star = point[3]
return I_star - (I1 + I2 + 2*math.sqrt(I1*I2)*math.cos(delta))
"""
Solved by Eureka: NO
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 20
"""
def calc_1_40_1(point):
n0 = point[0]
m = point[1]
x = point[2]
T = point[3]
g = point[4]
kb = point[5]
n = point[6]
return n - n0 * math.exp(-m*g*x/(kb*T))
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 29
"""
def calc_1_50_26(point):
x1 = point[0]
w = point[1]
t = point[2]
alpha = point[3]
x = point[4]
return x - x1 * (math.cos(w*t) + alpha*math.cos(w*t)*math.cos(w*t))
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 10
"""
def calc_2_4_23(point):
q = point[0]
e = point[1]
r = point[2]
Ve = point[3]
return Ve - q / (4 * math.pi * e * r)
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 23
"""
def calc_2_6_15b(point):
e = point[0]
p_d = point[1]
theta = point[2]
r = point[3]
Ef = point[4]
return Ef - (3.0 / (4.0*math.pi*e)) * (p_d / r**3) * math.cos(theta) * math.sin(theta)
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 13
"""
def calc_2_10_9(point):
qden = point[0]
e = point[1]
kappa = point[2]
ef = point[3]
return ef - (qden / e) * 1. / (1 + kappa)
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 21
"""
def calc_2_21_32(point):
q = point[0]
e = point[1]
r = point[2]
v = point[3]
c = point[4]
Ve = point[5]
return Ve - q / (4 * math.pi * e * r * (1 - v / c))
"""
Solved by Eureka: NO
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 62
"""
def calc_2_24_17(point):
w = point[0]
c = point[1]
d = point[2]
k = point[3]
return k - math.sqrt((w**2 / c**2) - (math.pi**2 / d**2))
"""
Solved by Eureka: NO
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 30
"""
def calc_2_35_18(point):
n0 = point[0]
kb = point[1]
T = point[2]
mim = point[3]
B = point[4]
n = point[5]
return n - n0 / (math.exp(mim*B/kb/T) + math.exp(-mim*B/kb/T))
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 15
"""
def calc_2_37_1(point):
mim = point[0]
B = point[1]
kappa = point[2]
E = point[3]
return E - mim * (1 + kappa) * B
"""
Solved by Eureka: NO
Solved by AI-Feynman: YES
Data needed: 1000
Solution time (s): 39
"""
def calc_3_8_54(point):
E = point[0]
t = point[1]
hi = point[2]
py = point[3]
return py - math.sin(E * t / (hi/(2*math.pi))) ** 2
"""
Solved by Eureka: YES
Solved by AI-Feynman: YES
Data needed: 10
Solution time (s): 14
"""
def calc_3_15_12(point):
U = point[0]
k = point[1]
d = point[2]
E = point[3]
return E - 2*U*(1 - math.cos(k*d))