neoryae-aegis / sharp_augmentation.py
PureOne's picture
Publish Neoryae Aegis research artifacts v1.0.0
3b80460 verified
Raw History Blame Contribute Delete
8.2 kB
"""Sharp small-inflation cost when a circle must be retained.
The old component is C=boundary(r D). An admissible finite segment network A
must make C union A connected and its convex hull contain (r+delta) D.
Only the length of A outside the old circle is charged. This is an
augmentation problem: it does not concern replacement of the old component.
Analytic conclusions (proved in tmp/sharp_augmentation_proof.tex):
S >= 2*sqrt(2*r*delta),
inf S / (pi*sqrt(2*r*delta)) -> 1 as delta/r -> 0.
The scalar lower bound below and radial-spoke upper bound sandwich inf S.
Floating-point values are diagnostics, not interval-certified optima over all A.
"""
from __future__ import annotations
import math
import numpy as np
from scipy.optimize import brentq
PI = math.pi
def _parameters(radius, inflation):
radius, inflation = float(radius), float(inflation)
if not math.isfinite(radius) or radius <= 0:
raise ValueError("radius must be finite and positive")
if not math.isfinite(inflation) or inflation <= 0:
raise ValueError("inflation must be finite and positive")
return radius, inflation
def covered_normal_width(length, radius=1.0, inflation=0.01):
"""Upper bound on normals served by one anchored exterior component.
A connected exterior piece of length ell has a circle anchor q; every x
in that piece has |x-q|<=ell. Thus u.x>=r+delta requires
u.q>=r+delta-ell. The resulting arc width is this scalar expression.
"""
radius, inflation = _parameters(radius, inflation)
length = float(length)
if not math.isfinite(length) or length < 0:
raise ValueError("length must be finite and nonnegative")
if length <= inflation:
return 0.0
if length >= inflation + 2 * radius:
return 2 * PI
return 2 * math.acos(1 - (length - inflation) / radius)
def elementary_lower_bound(radius=1.0, inflation=0.01):
radius, inflation = _parameters(radius, inflation)
return 2 * math.sqrt(2 * radius * inflation)
def scalar_lower_bound(radius=1.0, inflation=0.01):
"""Evaluate the exact one-variable lower-bound formula numerically.
M=sup_{ell>0} w(ell)/ell and S>=2*pi/M. Writing
ell=r*(a+1-cos(phi)) reduces this to
pi*r*min_{0<phi<=pi} (a+1-cos(phi))/phi.
Its only possible interior minimum is the first root of
phi*sin(phi)+cos(phi)-1=a in (0,pi/2]; the endpoint pi is also checked.
The global reduction is analytic; the reported root/value use doubles.
"""
radius, inflation = _parameters(radius, inflation)
a = inflation / radius
candidates = [(PI, a + 2)]
if a < PI / 2 - 1:
def equation(phi):
return phi * math.sin(phi) - 2 * math.sin(phi / 2) ** 2 - a
phi = brentq(equation, 0.0, PI / 2, xtol=1e-15, rtol=1e-14)
candidates.append((phi, a + 2 * math.sin(phi / 2) ** 2))
phi, denominator = min(candidates, key=lambda z: z[1] / z[0])
value = PI * radius * denominator / phi
return {"lower_bound": value, "max_width_per_length": 2 * PI / value,
"maximizing_component_length": radius * denominator,
"maximizing_phi": phi,
"evaluation": "analytic scalar reduction; floating-point root"}
def spoke_cost(count, radius=1.0, inflation=0.01):
radius, inflation = _parameters(radius, inflation)
if isinstance(count, bool) or int(count) != count or count < 3:
raise ValueError("count must be an integer at least three")
count = int(count)
x = PI / count
sec_minus_one = 2 * math.sin(x / 2) ** 2 / math.cos(x)
return count * (inflation + (radius + inflation) * sec_minus_one)
def optimal_spoke_count(radius=1.0, inflation=0.01):
"""Integer optimum within equal radial-arm constructions only.
The continuous cost N*((r+delta)*sec(pi/N)-r) is strictly convex for N>=3.
A floating-point derivative root brackets the two candidate integers.
"""
radius, inflation = _parameters(radius, inflation)
def derivative(count):
x = PI / count
sec_minus_one = 2 * math.sin(x / 2) ** 2 / math.cos(x)
return inflation + (radius + inflation) * (
sec_minus_one - x * math.tan(x) / math.cos(x))
upper = 6.0
while derivative(upper) < 0:
upper *= 2
continuous = brentq(derivative, 3.0, upper, xtol=1e-10, rtol=1e-13)
candidates = sorted({3, max(3, math.floor(continuous)), math.ceil(continuous)})
count = min(candidates, key=lambda n: spoke_cost(n, radius, inflation))
return {"count": count, "cost": spoke_cost(count, radius, inflation),
"continuous_count": continuous,
"scope": "equal radial-arm constructions"}
def radial_arms(count, radius=1.0, inflation=0.01, rotation=0.0):
"""Finite connected augmentation with an enclosing regular tip polygon."""
radius, inflation = _parameters(radius, inflation)
spoke_cost(count, radius, inflation) # validate the integer count
count = int(count)
theta = float(rotation) + 2 * PI * np.arange(count) / count
directions = np.column_stack((np.cos(theta), np.sin(theta)))
tip_radius = (radius + inflation) / math.cos(PI / count)
roots, tips = radius * directions, tip_radius * directions
return {"segments": np.stack((roots, tips), axis=1),
"roots": roots, "tips": tips, "tip_radius": tip_radius,
"count": count, "radius": radius, "inflation": inflation,
"cost_formula": spoke_cost(count, radius, inflation)}
def make_figure(path_png, path_pdf):
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
plt.rcParams.update({"font.size": 10, "axes.spines.top": False,
"axes.spines.right": False, "figure.dpi": 160})
fig, axes = plt.subplots(1, 3, figsize=(12.1, 3.5), layout="constrained")
ax = axes[0]
delta = 0.025
optimum = optimal_spoke_count(1, delta)
data = radial_arms(optimum["count"], 1, delta)
theta = np.linspace(0, 2 * PI, 800)
ax.plot(np.cos(theta), np.sin(theta), color="#283b59", lw=1.6,
label="retained circle")
ax.plot((1 + delta) * np.cos(theta), (1 + delta) * np.sin(theta),
color="#cc6545", lw=1, ls="--", label="inflated disk")
for segment in data["segments"]:
ax.plot(segment[:, 0], segment[:, 1], color="#167f86", lw=2)
tips = np.vstack((data["tips"], data["tips"][0]))
ax.plot(tips[:, 0], tips[:, 1], color="#167f86", lw=.7, alpha=.7)
ax.set_aspect("equal")
ax.set_title("A Retain the circle; add radial arms", loc="left", fontsize=10)
ax.set_xlim(-1.13, 1.13); ax.set_ylim(-1.13, 1.13)
ax.set_xticks([-1, 0, 1]); ax.set_yticks([-1, 0, 1])
ax.legend(frameon=False, loc="lower left", fontsize=8)
ratios = np.geomspace(1e-6, .1, 100)
scale = PI * np.sqrt(2 * ratios)
lower = np.array([scalar_lower_bound(1, d)["lower_bound"] for d in ratios])
spoke = [optimal_spoke_count(1, d) for d in ratios]
upper = np.array([row["cost"] for row in spoke])
ax = axes[1]
ax.semilogx(ratios, lower / scale, color="#283b59", lw=2,
label="scalar lower bound")
ax.semilogx(ratios, upper / scale, color="#167f86", lw=2,
label="radial-arm upper bound")
ax.axhline(1, color=".5", ls=":", lw=1)
ax.set_xlabel(r"relative inflation $\delta/r$")
ax.set_ylabel(r"length $/\,\pi\sqrt{2r\delta}$")
ax.set_title("B Matching sharp asymptotic", loc="left", fontsize=10)
ax.legend(frameon=False, fontsize=8)
ax.grid(alpha=.15)
ax = axes[2]
counts = np.array([row["count"] for row in spoke])
ax.semilogx(ratios, counts * np.sqrt(ratios), color="#167f86", lw=1.7,
label=r"integer-optimal $N\sqrt{\delta/r}$")
ax.axhline(PI / math.sqrt(2), color="#283b59", ls="--", lw=1.2,
label=r"limit $\pi/\sqrt{2}$")
ax.set_xlabel(r"relative inflation $\delta/r$")
ax.set_ylabel("scaled arm count")
ax.set_title("C Arm count grows as inverse square root", loc="left", fontsize=10)
ax.legend(frameon=False, fontsize=8)
ax.grid(alpha=.15)
fig.savefig(path_png, dpi=200)
fig.savefig(path_pdf)
plt.close(fig)