"""Verify the reverse-window obstruction using only switch-form data.""" import sympy as sp def verify_zero(expression, atoms, description): """Check all coefficients after treating the form values and logs as independent.""" for coefficient in sp.Poly(expression, *atoms).coeffs(): if sp.cancel(coefficient) != 0: raise AssertionError(f"{description}: {coefficient}") def verify_switch_vectors(): """Verify the three-switch vector relation for both common signs.""" tau_0, tau_1, tau_2, q_1, q_2 = sp.symbols( "tau_0 tau_1 tau_2 q_1 q_2", positive=True ) rotation = sp.Matrix([[0, 1], [-1, 1]]) for sign in (1, -1): transfer = sp.diag(q_1, 1 / q_1) * rotation**(-sign) if sign == 1: y_0 = transfer.inv() * sp.Matrix([0, -1 / tau_0]) y_1, y_2 = sp.Matrix([0, -1 / tau_1]), sp.Matrix([q_2 / tau_2, 0]) else: y_0 = transfer.inv() * sp.Matrix([-1 / tau_0, 0]) y_1, y_2 = sp.Matrix([-1 / tau_1, 0]), sp.Matrix([0, 1 / (q_2 * tau_2)]) mu_1, mu_2 = tau_0 * tau_1 / q_1**sign, tau_1 * tau_2 / q_2**sign if not (y_0 - (tau_1**2 * y_1 - mu_2 * y_2) / mu_1).applyfunc(sp.cancel).is_zero_matrix: raise AssertionError(f"Three-switch vector relation for sign {sign}") print("PASS three-switch vector relation for both signs", flush=True) def reverse_stationarity(active, tau_in, tau_out, mu, log_factor, value_in, value_out): """Return the cross pairing given by reverse-center stationarity.""" share_in, share_out = active / tau_in, active / tau_out return ( 1 + share_in + share_out - active**2 / mu - log_factor - (1 - 8 * value_in) / share_in - (1 - 8 * value_out) / share_out ) / 16 def weighted_value(active, tau, value, factor, log_factor): """Reverse-switch secant formula, divided by sqrt(3).""" share = active / tau secant = 1 + share**2 / factor - share * log_factor / (factor - 1) return tau**2 * factor * (factor - 1) * (8 * value - secant) def obstruction(p, following, unused, q, q_next, log_q, log_next): """The function N in the reverse-window lemma.""" return ( q * (q - 1) * following * ( following * q_next * (q_next - 1 - log_next) - unused * (q_next * log_next - q_next + 1) ) + (q_next - 1) * ( q * following * (unused + q * p) * (q - 1 - log_q) - unused * (q * following + p) * (q * log_q - q + 1) ) ) def verify_reverse_window(): p_1, p_2, unused, q_1, q_2 = sp.symbols("p_1 p_2 unused q_1 q_2", positive=True) log_q1, log_q2, sigma_1, sigma_2 = sp.symbols("log_q1 log_q2 sigma_1 sigma_2") # The reverse arc map fixes the outer margins and hence the three sums. tau_0, tau_1, tau_2 = (p_1 + unused) / q_1, p_1 + p_2, (p_2 + unused) / q_2 mu_1, mu_2 = q_1 * tau_0 * tau_1, q_2 * tau_1 * tau_2 sigma_12 = reverse_stationarity(p_2, tau_1, tau_2, mu_2, log_q2, sigma_1, sigma_2) basis_1, basis_2 = tau_1**2 / mu_1, -mu_2 / mu_1 sigma_0 = basis_1**2 * sigma_1 + basis_2**2 * sigma_2 + 2 * basis_1 * basis_2 * sigma_12 sigma_01 = basis_1 * sigma_1 + basis_2 * sigma_12 residual = sigma_01 - reverse_stationarity(p_1, tau_0, tau_1, mu_1, log_q1, sigma_0, sigma_1) value_left = weighted_value(p_1, tau_1, sigma_1, q_1, log_q1) value_middle = weighted_value(p_1, tau_0, sigma_0, q_1, log_q1) value_right = weighted_value(p_2, tau_1, sigma_1, q_2, log_q2) weight = p_2 * (q_2 - 1) + p_1 * (q_1 - 1) difference_left = ( unused * (q_2 - 1) * value_left + q_1 * weight * value_middle + p_1 * obstruction(p_1, p_2, unused, q_1, q_2, log_q1, log_q2) ) difference_right = ( unused * (q_1 - 1) * value_right + q_2 * weight * value_middle + p_2 * obstruction(p_2, p_1, unused, q_2, q_1, log_q2, log_q1) ) # These explicit polynomial multipliers avoid dividing by the vanishing # residual or making a generic-rank assumption. multiplier = 16 * p_1 * (unused + p_1) * (q_1 - 1) * (p_1 + p_2 - q_2 * p_2) atoms = (sigma_1, sigma_2, log_q1, log_q2) verify_zero(difference_left - q_1 * multiplier * residual, atoms, "Left obstruction") verify_zero(difference_right - q_2 * multiplier * residual, atoms, "Right obstruction") print("PASS both reverse-window identities from stationarity and secants", flush=True) if __name__ == "__main__": verify_switch_vectors() verify_reverse_window()