"""The bounds of this directory and those of Hile and Yeh, with exact comparisons (standard library only).""" from fractions import Fraction from math import isqrt, sqrt def buckling_excess_enclosure(n, digits=12): """Fractions lo <= E <= hi for E = 4 (n + 4)^2 / ((n + 2) (n^2 + 2n + 8 + 4 sqrt(2n(n + 2)))), the bound on Lambda_2 / Lambda_1 - 1. This is 4 (n + 4)^2 / ((n + 2) (sqrt(n(n + 2)) + 2 sqrt 2)^2).""" scale = 10 ** digits root = isqrt(2 * n * (n + 2) * scale * scale) exact = root * root == 2 * n * (n + 2) * scale * scale below, above = Fraction(root, scale), Fraction(root if exact else root + 1, scale) top, rest = 4 * (n + 4) ** 2, n * n + 2 * n + 8 return top / ((n + 2) * (rest + 4 * above)), top / ((n + 2) * (rest + 4 * below)) def buckling_excess_below(n, bound): """Whether E < bound, decided exactly.""" bound = Fraction(bound) if bound <= 0: return False # E < bound <=> sqrt(2n(n + 2)) > rho rho = (Fraction(4 * (n + 4) ** 2) / (bound * (n + 2)) - (n * n + 2 * n + 8)) / 4 return rho < 0 or rho * rho < 2 * n * (n + 2) def hile_yeh_buckling_excess(n): """Hile and Yeh: Lambda_2 / Lambda_1 <= (n^2 + 8n + 20) / (n + 2)^2 = 1 + 4 (n + 4) / (n + 2)^2.""" return Fraction(4 * (n + 4), (n + 2) ** 2) def plate_shift(n): return Fraction((6 - n) * (n + 2), 4) def plate_cubic(n, Y): """The numbers p, q, r of the cubic s^3 + p s^2 - q s + r of the proof.""" n, Y = Fraction(n), Fraction(Y) c = plate_shift(n) p = 1 + n / 2 q = (Y - n * n / 4) * (Y + c) r = (n * n / 4 - n / 2 * (Y - n * n / 4)) * (Y + c) return p, q, r def plate_test(n, Y): """Whether Y passes: n^2/4 < Y < n(n + 2)/4 and 4 (p^2 + 3q)^3 < (27 r + 9 p q + 2 p^3)^2. Then Gamma_2 / Gamma_1 <= 1 + (2n + 4) / Y in dimension n.""" n, Y = Fraction(n), Fraction(Y) if not n * n / 4 < Y < n * (n + 2) / 4: return False p, q, r = plate_cubic(n, Y) return 4 * (p * p + 3 * q) ** 3 < (27 * r + 9 * p * q + 2 * p ** 3) ** 2 def plate_bound(n, Y): return 1 + Fraction(2 * n + 4) / Fraction(Y) def plate_rational_constant(n): return Fraction(8 * n * n + 12 * n - 1, 32) def plate_rational_bound(n): """1 + 64 (n + 2) / (8 n^2 + 12 n - 1).""" return plate_bound(n, plate_rational_constant(n)) def plate_best_constant(n, digits=6): """The largest multiple of 10^-digits that passes the test.""" scale = 10 ** digits low, high = n * n * scale // 4 + 1, n * (n + 2) * scale // 4 if not plate_test(n, Fraction(low, scale)): raise ValueError('no multiple of 10^-%d passes in dimension %d' % (digits, n)) while high - low > 1: middle = (low + high) // 2 if plate_test(n, Fraction(middle, scale)): low = middle else: high = middle return Fraction(low, scale) def below_hile_yeh_plate(n, x): """Whether x < H, where H is the root larger than 1 of (H - 1)^3 = 512 H / (n^2 (n + 2)). The difference of the two sides is negative at 1, convex beyond 1 and positive at infinity, so for x > 1 it is negative exactly when x < H.""" x = Fraction(x) return x <= 1 or (x - 1) ** 3 * n * n * (n + 2) < 512 * x def hile_yeh_plate_function(n, sigma): """Hile and Yeh, Theorem 3 for the first two eigenvalues: for every sigma > 0, Gamma_2 / Gamma_1 <= 1 + sigma + q(sigma) M(n), with q(sigma) = ((1 + sigma)^3 / sigma)^(1/2) and M(n) = (32/3) (2/3)^(1/2) / (n (n + 2)^(1/2)). Floating point.""" return 1 + sigma + sqrt((1 + sigma) ** 3 / sigma) * 32 / 3 * sqrt(2 / 3) / (n * sqrt(n + 2)) def hile_yeh_plate_root_below(n, digits=6): """The largest multiple of 10^-digits that is less than H.""" scale = 10 ** digits low, high = scale, 26 * scale while high - low > 1: middle = (low + high) // 2 if below_hile_yeh_plate(n, Fraction(middle, scale)): low = middle else: high = middle return Fraction(low, scale) # Hile and Yeh, Pacific J. Math. 112 (1984), page 128: their own values of the plate bound. HILE_YEH_PRINTED_PLATE = {2: '7.103', 3: '4.792', 4: '3.704', 5: '3.081', 6: '2.684', 7: '2.409', 8: '2.210', 9: '2.058', 10: '1.939', 100: '1.081578', 1000: '1.008015963'} def round_up(value, digits=6): """The decimal string of the least multiple of 10^-digits that is at least value.""" scale = 10 ** digits value = Fraction(value) * scale units = -((-value.numerator) // value.denominator) return '%d.%0*d' % (units // scale, digits, units % scale)