Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def thacher(n):
r = sqrt(3) / 6
data = [(1, [n * [2 * r]]), (+r, _s(n, -1, r)), (-r, _s(n, +1, r))]
points, weights = untangle(data)
return CnScheme("Thacher", n, weights, points, 2, _source, 1.511e-14)
def stroud_4_1():
pts = (
2
* sqrt(5)
* numpy.array(
[
[cos(2 * i * pi / 5) for i in range(5)],
[sin(2 * i * pi / 5) for i in range(5)],
]
).T
)
data = [(frac(7, 10), numpy.array([[0, 0]])), (frac(3, 50), pts)]
points, weights = untangle(data)
return E2rScheme("Stroud 4-1", weights, points, 4, _source)
(
frac(
(-1) ** i * 2 ** (-2 * s) * (d + n - 2 * i) ** d,
fact(i) * fact(d + n - i),
),
numpy.array(
[
[frac(2 * p + 1, d + n - 2 * i) for p in part]
for part in exponents[s - i]
]
),
)
for i in range(s + 1)
]
points, weights = untangle(data)
weights /= sum(weights)
name = f"GrundmannMöller(dim={n}, {s})"
return TnScheme(name, n, weights, points, d, source)
def f(x):
degree = 7
n = 5
u = x[0]
v = x[1]
B = x[2:]
data = [
(B[0], z(n)),
(B[1], fsd(n, (u, 1))),
(B[2], fsd(n, (v, 1))),
(B[3], fsd(n, (u, 2))),
(B[4], fsd(n, (v, 2))),
(B[5], fsd(n, (u, 3))),
]
points, weights = untangle(data)
exponents = get_all_exponents(n, degree)
# flatten list
exponents = numpy.array([item for sublist in exponents for item in sublist])
def evaluate_all_monomials(x):
return numpy.prod(x[..., None] ** exponents.T[:, None], axis=0).T
flt = numpy.vectorize(float)
exact_vals = flt([integrate_monomial_over_unit_nball(k) for k in exponents])
A = evaluate_all_monomials(points.T)
out = numpy.dot(A, weights)
out -= exact_vals
r2 = (3 * (n + 6) * (8 - n) - t * (n - 2) * alpha) / ((n + 6) * (34 - 5 * n))
s2 = (3 * n * (n + 6) - t * 2 * alpha) / ((n + 6) * (3 * n ** 2 + 6 * n - 16))
t2 = (6 * (n + 6) + t * alpha) / (14 * (n + 6))
B = (8 - n) / (n + 2) / (n + 4) / (n + 6) / r2 ** 3
C = 1 / (n + 2) / (n + 4) / (n + 6) / s2 ** 3 / 2 ** n
D = 1 / (n + 2) / (n + 4) / (n + 6) / t2 ** 3 / 2
A = 1 - 2 * n * B - 2 ** n * C - 2 * n * (n - 1) * D
r = sqrt(r2)
s = sqrt(s2)
t = sqrt(t2)
data = [(A, z(n)), (B, fsd(n, (r, 1))), (C, pm(n, s)), (D, fsd(n, (t, 2)))]
points, weights = untangle(data)
variant = "a" if variant_a else "b"
return SnScheme(f"Stroud 1967-7{variant}", n, weights, points, 7, source)
pts.append(fsd(n, (v1, 2), (u1, n - 2)))
k_range.append(8)
if n >= 5:
pts.append(fsd(n, (v2, 2), (u2, n - 2)))
k_range.append(10)
# TODO build the equation system from orthogonal polynomials
b = [
integrate_monomial_over_unit_nsphere([k] + (n - 1) * [0], symbolic=False)
for k in k_range
]
A = [[sum(p[:, 0] ** k) for p in pts] for k in k_range]
w = numpy.linalg.solve(A, b)
data = [(w[k], pts[k]) for k in range(len(w))]
points, weights = untangle(data)
weights /= volume_nsphere(n - 1)
return UnScheme("Stroud 1969", n, weights, points, degree, source, 1.428e-14)
self.name = 'Stround Un({})'.format(index)
self.dim = n
if index == 'Un 3-1':
self.degree = 3
data = [
(frac(1, 2*n), fsd(n, (1, 1))),
]
self.points, self.weights = untangle(data)
self.weights *= \
integrate_monomial_over_unit_nsphere(n * [0], symbolic)
elif index == 'Un 3-2':
self.degree = 3
data = [
(frac(1, 2**n), pm(n, sqrt(frac(1, n)))),
]
self.points, self.weights = untangle(data)
self.weights *= \
integrate_monomial_over_unit_nsphere(n * [0], symbolic)
elif index == 'Un 5-1':
self.degree = 5
B1 = frac(4-n, 2*n*(n+2))
B2 = frac(1, n * (n+2))
data = [
(B1, fsd(n, (1, 1))),
(B2, fsd(n, (sqrt(frac(1, 2)), 2))),
]
self.points, self.weights = untangle(data)
self.weights *= \
integrate_monomial_over_unit_nsphere(n * [0], symbolic)
def hammer_stroud_1_3():
data = [(frac(1, 6), fsd(3, (1, 1)))]
points, weights = untangle(data)
return C3Scheme("Hammer-Stroud 1-3", weights, points, 3, _source)
def kim_song_6():
data = [
(2 / 27 * math.pi, fsd(2, (0.866025403784439, 1))),
(0.387077796006226, fsd(2, (0.322914992067400, 2))),
(0.165609800458645, fsd(2, (0.644171310389465, 2))),
]
points, weights = untangle(data)
weights /= math.pi
return S2Scheme("Kim-Song 6", weights, points, 7, _source)
def kim_song_9():
data = [
(0.051310052712355, fsd(2, (0.680167267076408, 2))),
(0.208368275231940, fsd(2, (0.232463234651158, 2))),
(0.113628206510048, fsd(2, (0.547722557505169, 2))),
(0.126977836503225, fsd(2, (0.652159581445885, 1), (0.174745633184644, 1))),
(0.079067977968328, fsd(2, (0.904823085572323, 1), (0.242446615072141, 1))),
]
points, weights = untangle(data)
weights /= math.pi
return S2Scheme("Kim-Song 9", weights, points, 11, _source, 1.742e-14)