"""
Test 13: Group-level analytic continuation — the critical test

This is the test paper 2 depends on.

Test 9 showed that Matsubara periodicity at T_dS gives PROPAGATOR-LEVEL
analytic continuation between the Euclidean S^3 and Lorentzian H^3
propagators. The structural pattern is there.

But: propagator-level equivalence is weaker than group-level equivalence.

The question for Test 13 is: does the Matsubara construction genuinely
promote SO(4) → SO(3,1) at the level of the SYMMETRY GROUP of the
effective theory, not merely at the level of two-point functions?

SCOPE AND CAVEAT (important):
This is fundamentally a representation-theory question, not a numerical
one. "Run the test" can only go so far — what we can do is:

  1. State precisely what "group-level continuation" means.
  2. Check a specific concrete criterion (KMS condition, character-
     function match) numerically.
  3. Identify where a purely numerical approach hits its ceiling.
  4. Draw the honest verdict.

We cannot substitute numerics for a proper representation-theoretic
argument. Where the test can falsify the claim, it will. Where the test
is only suggestive, we'll say so.
"""

import numpy as np
import matplotlib.pyplot as plt

print("=" * 72)
print("TEST 13: Group-level SO(4) → SO(3,1) via Matsubara")
print("=" * 72)

# -------------------------------------------------------------------
# Part 1: State the question precisely
# -------------------------------------------------------------------
print("""
-------------------------------------------------------------------
PART 1: What does "group-level continuation" mean?
-------------------------------------------------------------------

Two candidate statements, increasing in strength:

STATEMENT S1 (weak — propagator level):
  For thermal state at T = H/(2π), the two-point function
  G_Eucl(θ) on S^3 and G_Lor(χ) on H^3 are related by θ → iχ.
  Test 9 established this.

STATEMENT S2 (group level — what we actually need):
  The effective theory on the brane, in the thermal state at T_dS,
  has Poincaré-invariant (SO(3,1)) correlation functions at all orders,
  not merely at the two-point level. I.e., the THERMAL state itself
  has SO(3,1) symmetry realised on its n-point functions.

S2 is the claim Paper 2 actually needs. S1 is necessary but not
sufficient for S2.

The KMS condition is the standard rigorous formulation of thermal
analytic continuation. A thermal state at inverse temperature β satisfies:
  <A(t) B(0)> = <B(0) A(t + iβ)>
for any operators A, B. This is a statement about all correlation
functions, not just two-point ones.

The question then reduces to: does a KMS state at T_dS on the brane
carry an SO(3,1) action on its GNS-reconstructed Hilbert space?
""")

# -------------------------------------------------------------------
# Part 2: Character-function check (a necessary condition)
# -------------------------------------------------------------------
print("""
-------------------------------------------------------------------
PART 2: Character-function check — a necessary condition
-------------------------------------------------------------------

A necessary condition for two group actions to be related by analytic
continuation is that their character functions (traces of group elements
in finite-dimensional reps, or suitable generalisations for non-compact
groups) match under the continuation.

For SO(4):
  Irreps labelled by (j_L, j_R), both half-integers.
  Character of (j_L, j_R) on rotation by angles (θ_1, θ_2) in two
  orthogonal planes is χ(θ_1, θ_2) = χ_{j_L}(θ_L) χ_{j_R}(θ_R)
  where χ_j(θ) = sin((2j+1)θ/2) / sin(θ/2).

For SO(3,1):
  Principal series irreps labelled by (j_0, c) where j_0 is half-
  integer and c is a complex parameter.
  Character on a pure boost of rapidity η is
  χ_{j_0, c}(η) = [cosh((2j_0)η) e^{-cη} + ...] / sinh(η).

Analytic continuation θ → iη in the compact character should reproduce
the hyperbolic character. Let's check this numerically for the simplest
case j_L = j_R = 1/2 (the vector rep of SO(4)):
""")

# Compact character for j=1/2: sin(θ)/sin(θ/2) = 2cos(θ/2)
# Under θ → iη: 2cos(iη/2) = 2cosh(η/2)

thetas = np.linspace(0.01, np.pi - 0.01, 100)
char_compact_half = np.sin(thetas) / np.sin(thetas / 2)  # = 2cos(θ/2)

etas = np.linspace(0, 3, 100)
# Under θ → iη: sin(iη)/sin(iη/2) = i·sinh(η) / (i·sinh(η/2)) = sinh(η)/sinh(η/2)
# = 2cosh(η/2)
char_noncompact_half = np.sinh(etas) / np.sinh(etas/2)  # = 2cosh(η/2)

# Also check: 2cos(θ/2) at θ = small should equal 2cosh(η/2) at η = small
# Small theta: 2cos(θ/2) ≈ 2 - θ^2/4
# Small eta: 2cosh(η/2) ≈ 2 + η^2/4
# So they agree at leading order and differ at O((θ or η)^2) — which is
# the signature of analytic continuation

print(f"  Compact char at θ=0.1: {2*np.cos(0.05):.6f}")
print(f"  Non-compact char at η=0.1: {2*np.cosh(0.05):.6f}")
print(f"  Leading order agreement (both → 2 as angle → 0): ✓")
print(f"  O(angle^2) deviation has opposite sign as expected: ✓")

# Character match is necessary — but it's only a check on finite-
# dimensional/unitary reps of the spatial groups. The cosmological
# question is whether the FULL Poincaré structure (translations +
# boosts) emerges, not just the boost sector.

# -------------------------------------------------------------------
# Part 3: The critical obstruction — translations
# -------------------------------------------------------------------
print("""
-------------------------------------------------------------------
PART 3: The critical obstruction — translations
-------------------------------------------------------------------

HERE IS THE HARD POINT.

SO(4) and SO(3,1) can be related by character-level analytic continuation
on their rotation/boost subgroups. This is Test 9 (propagator level) plus
Part 2 above (character level) — both give consistent pictures.

BUT the full Lorentz group the framework needs to recover is NOT just
SO(3,1) — it's the full POINCARÉ group, which also includes spacetime
translations. Poincaré = SO(3,1) ⋉ R^{3,1}.

Matsubara periodicity gives you the boost sector. It does NOT
automatically give you translations that mix space and time.

Specifically: thermal equilibrium picks out a preferred frame — the
REST FRAME of the thermal bath. A thermal state is NOT Lorentz-
invariant; it breaks Lorentz symmetry down to spatial rotations
(the little group fixing the thermal bath's 4-velocity).

So a brane-intrinsic observer in a thermal state at T_dS does NOT
see full Poincaré symmetry. They see:
  - Spatial rotations (unbroken, SO(3) subgroup)
  - Time translations (unbroken, in the thermal rest frame)
  - Boosts: BROKEN by the thermal bath (the rest frame is preferred)
  - Spatial translations: unbroken

The thermal state has SO(3) × R × R^3 symmetry, not full SO(3,1) ⋉ R^4.

This is a general feature of thermal states: they pick a rest frame.
""")

# -------------------------------------------------------------------
# Part 4: The counterargument — de Sitter's special case
# -------------------------------------------------------------------
print("""
-------------------------------------------------------------------
PART 4: The de Sitter counterargument
-------------------------------------------------------------------

The above objection would be fatal except for the following fact:

The de Sitter thermal state is SPECIAL. It is not thermal in the
ordinary sense of "in a heat bath" — it's the Bunch-Davies vacuum,
which:
  - Has no preferred observer on the de Sitter manifold
  - Is de Sitter-invariant (SO(4,1) invariant in the 4D dS case)
  - Appears thermal to any local observer at T = H/(2π)

So the thermal character is OBSERVER-DEPENDENT while the full
de Sitter symmetry is preserved at the level of the state.

This is the rescue Option B (Test 12) was implicitly pointing to.
The Bunch-Davies / Hartle-Hawking state on dS is SIMULTANEOUSLY
  - thermal to any local observer (Matsubara-periodic in local time)
  - SO(4,1)-symmetric at the state level

These are compatible because the symmetry is non-trivially realised
on the Hilbert space (the state is cyclic and separating in the GNS
sense, and the modular operator generates the boost).

If the brane's thermal state is a Bunch-Davies-analog on dS_3 (which
is what Option B + the thermal cooling mechanism would give), then
the state IS Lorentz-invariant in the full sense, and the thermal
character is the observer-dependent projection, not a symmetry-breaking.

THIS IS THE LOOPHOLE PAPER 2 NEEDS.

But it has a heavy technical price:

  (a) You need to establish that the brane's thermal state is genuinely
      a Bunch-Davies-analog, not a thermal-bath-in-a-preferred-frame state.
      This is NOT automatic. It requires specific dynamical conditions
      (eternal de Sitter, specific initial conditions) that may not be
      satisfied by any brane whose thermal behaviour comes from blocked
      radiation.

  (b) The Bunch-Davies state on dS_3 requires a full dS_3 manifold,
      not a finite patch. The observable universe is a patch of dS,
      with a finite past (big bang). The Bunch-Davies construction
      uses the full manifold. Using a patch instead gives a state
      that is only APPROXIMATELY Bunch-Davies, with corrections that
      break full symmetry at low momentum (super-horizon modes).

  (c) The blocked-radiation mechanism of Paper 2 gives a thermal state
      that may or may not be Bunch-Davies. If the cooling is incomplete
      or the approach to dS is transient, the effective state is a
      thermal bath in a preferred frame, NOT Bunch-Davies. In that
      case boosts are broken.

  (d) Even if the state is Bunch-Davies on dS_3, the recovery is of
      SO(3,1) acting on a CURVED spacetime. What Paper 1 wanted was
      flat-space SR — local Lorentz invariance at every point, not
      "on average" over a cosmological horizon.

VERDICT: S2 (group-level analytic continuation) is plausibly achievable
IF the brane's thermal state is a Bunch-Davies-analog. But this requires
conditions that are non-trivial to establish, and even then gives
SO(3,1) curved-space invariance, not flat-space local Lorentz invariance.
""")

# -------------------------------------------------------------------
# Part 5: Honest synthesis — does S2 hold?
# -------------------------------------------------------------------
print("""
-------------------------------------------------------------------
PART 5: Honest synthesis — does group-level continuation hold?
-------------------------------------------------------------------

Scorecard:

  PROPAGATOR LEVEL (S1): CONFIRMED. Test 9 + Part 2 character match. ✓
  THERMAL → BOOST CHARACTER: Necessary condition met at O(angle^0,1)
    and deviates correctly at higher orders. ✓
  THERMAL STATE → FULL POINCARÉ: NOT AUTOMATIC. Thermal states
    generically break boosts. Requires Bunch-Davies-analog state. ✗
    unless further conditions met.
  LOCAL SR AT FLAT-SPACE LEVEL: NOT RECOVERED by this mechanism.
    At best recovered as "SO(3,1) acting on a dS_3 curved space",
    which is NOT what Paper 1's §3.1.1 residual obstruction asks for.

The residual obstruction in Paper 1 §3.1.1 was: c-invariance under
flat-space boosts, and 3-velocity addition in flat space. Paper 2's
mechanism would give you Lorentz symmetry OF THE THERMAL STATE AT
COSMOLOGICAL SCALES — which is a different beast than flat-space
local Lorentz invariance.

In other words: the thermal-Matsubara mechanism may solve a different
problem than the one Paper 1 identified. Paper 1 wanted local Lorentz
in the flat tangent space of any observer; Paper 2 is delivering
global dS symmetry of the cosmological thermal state.

These two are connected — local Lorentz is the flat-space limit of
dS symmetry at scales << 1/H — but the connection is through a
Penrose-diagram-style tangent-space argument, not through the
Matsubara construction per se.

DOES TEST 13 FAIL? It fails the strong version (S2 solves Paper 1's
residual obstruction via thermal mechanism only). It does NOT fail
in a way that kills the framework:
  - The propagator-level result stands (S1).
  - The dS cosmology story stands.
  - The Bunch-Davies loophole exists but requires additional technical
    development.
  - The flat-space local-Lorentz problem is more subtle than thermal
    analytic continuation alone delivers.

VERDICT: MIXED.

Paper 2 cannot claim it "resolves Paper 1's residual obstruction" in
the simple form originally sketched. The best it can claim is:
  - Thermal mechanism gives propagator-level continuation (S1).
  - For the state-level continuation (S2), further conditions
    (Bunch-Davies state, full dS manifold) are needed.
  - The flat-space local Lorentz story requires a separate argument
    (tangent-space approximation), not delivered by Matsubara alone.

This is still publishable — it's a sharpening of what the mechanism
does and doesn't achieve, and a specific roadmap for Paper 3 (which
would do the Bunch-Davies construction properly). But it's not the
victory Paper 2 was originally sketching.

RECOMMENDATION:
Paper 2 should reframe as: "Thermal mechanism gives a candidate for
partial solution to Paper 1's §8.1. Specifically, it delivers
propagator-level continuation and points toward a Bunch-Davies
state as the full resolution, but does not by itself resolve the
flat-space local-Lorentz problem. Further work needed."

This is a weaker claim than "we solve the Lorentz problem via
thermality", but it's honest, specific, and defensible.
""")

# Plot summary visualisation
fig, ax = plt.subplots(figsize=(10, 6))
claims = ["Propagator\nlevel (S1)", "Character\nmatch", "Thermal→full\nPoincaré (S2)", 
          "Flat-space local\nLorentz", "Bunch-Davies\nloophole"]
statuses = [1, 1, 0.3, 0.2, 0.5]  # roughly: 1 = confirmed, 0 = not established
colors = ['green' if s >= 0.9 else ('orange' if s >= 0.4 else 'red') for s in statuses]

ax.barh(claims, statuses, color=colors, alpha=0.7)
ax.set_xlabel('Strength of numerical/analytic support')
ax.set_xlim(0, 1.1)
ax.set_title('Test 13 scorecard: components of group-level analytic continuation')
ax.axvline(0.5, color='gray', ls=':', alpha=0.5)
ax.grid(alpha=0.3, axis='x')

plt.tight_layout()
plt.savefig('/home/claude/test13_scorecard.png', dpi=120)
print("Saved: test13_scorecard.png")

print("""
-------------------------------------------------------------------
BOTTOM LINE FOR TEST 13
-------------------------------------------------------------------

Paper 2's original sketch — "thermal periodicity at T_dS solves the
SO(4) → SO(3,1) problem" — is TOO STRONG in the form proposed.

What actually holds:
  - Propagator-level continuation ✓
  - Character-level necessary conditions ✓
  - State-level Lorentz invariance: only via Bunch-Davies loophole
  - Flat-space local Lorentz: NOT from Matsubara alone

Paper 2 can still be written, but its central claim must be reframed:
  OLD: "Thermal mechanism resolves residual obstruction of Paper 1."
  NEW: "Thermal mechanism gives partial resolution + specific route
        (Bunch-Davies) for completion. Does not by itself solve flat-
        space local Lorentz; that is left to future work."

This is not game over — but it is a reality check that materially
changes Paper 2's value proposition.
""")
