"""
Test 12: The geometry mismatch — flat E^4 vs. S^4

Paper 1's framework uses flat Euclidean 4-space (E^4) as the ambient.
Paper 2's cosmology argument generates de Sitter dynamics, whose
Euclidean continuation is S^4 (the 4-sphere), NOT E^4.

The question: can these be reconciled self-consistently?

OPTION A: Flat E^4 is a local approximation; S^4 emerges at cosmological
scales. SR recovery is local; thermality is set by S^4 radius.

OPTION B: Flat E^4 is fundamental; de Sitter behaviour is intrinsic to
the brane, not to the ambient. The "de Sitter temperature" is observer-
dependent (analogous to Unruh).

This test: take each option seriously, work out what each implies, and
check whether either is self-consistent.
"""

import numpy as np
import matplotlib.pyplot as plt

print("=" * 72)
print("TEST 12: Geometry mismatch (E^4 vs S^4)")
print("=" * 72)

# -------------------------------------------------------------------
# Option A: S^4 ambient, E^4 as local approximation
# -------------------------------------------------------------------
print("""
-------------------------------------------------------------------
OPTION A: The ambient is actually S^4; flat E^4 is a local patch
-------------------------------------------------------------------

CLAIM: The true ambient geometry is a 4-sphere S^4 of radius R_dS ~ 1/H.
The flat E^4 used in Paper 1 is a local approximation valid at scales
small compared to R_dS.

CONSISTENCY CHECKS:

(i) Scale of R_dS vs Paper 1's regime:
    H_0 ~ 2.2e-18 /s  →  R_dS ~ c/H_0 ~ 1.4e26 m ~ 14 Gly
    
    Paper 1's numerical tests (1-6) are at particle/lab scales,
    << R_dS. Locally-flat approximation is excellent at these scales.
    Local SR recovery unaffected. ✓

(ii) Group structure in Option A:
    S^4 isometry is SO(5), not SO(4).
    The 4-brane living in S^4 has tangent space E^4 locally, with
    local tangent-space isometry SO(4). So Paper 1's SO(4) story
    survives as the local-tangent-space statement. ✓

    The full ambient symmetry SO(5) is however larger than needed.
    This is actually FINE: a cosmological setup naturally has
    extra symmetry that doesn't show up locally.

(iii) De Sitter horizon vs R_dS:
    In Option A, R_dS IS the ambient S^4 radius, and the Lorentzian
    continuation is dS_4 with horizon at R_dS. Perfectly consistent. ✓

(iv) The 3-brane in S^4:
    The 3-brane would be a 3-dimensional submanifold of S^4. In the
    static patch of dS_4 (Lorentzian), the brane is a spatial slice.
    In the Euclidean S^4, the brane is a 3-sphere slice (an equatorial
    S^3 or similar).
    
    This REPLACES the "flat 3D universe" with "3-sphere universe" at
    cosmological scales. Currently observed: universe is spatially flat
    (|Ω_k| < 0.01 from Planck), so any S^3 geometry must have
    radius >> current Hubble radius. Which it does, trivially. ✓

(v) Cosmological expansion in Option A:
    The brane is a 3-sphere slice of S^4, and "cosmic time" corresponds
    to the angular coordinate along one direction of S^4. Brane
    evolution = moving the slice. This naturally gives dS cosmology. ✓

VERDICT ON OPTION A:
Internally consistent. The price is replacing "flat Euclidean ambient"
with "spherical (large-radius) Euclidean ambient". Paper 1's local SR
derivation is unchanged; Paper 2's cosmology becomes natural.

What's LOST: Paper 1's framing of "ambient is fundamentally flat" is
demoted. The ambient IS curved on large scales. For Paper 1's
interpretive claims (mass-energy couples to w_4; positive-energy
grounds one-directionality), this doesn't matter — those claims are
local and survive. For the aesthetic of "flat ambient + everything
derived", Option A is a clear concession.
""")

# -------------------------------------------------------------------
# Option B: Genuine flat E^4; de Sitter is intrinsic to the brane
# -------------------------------------------------------------------
print("""
-------------------------------------------------------------------
OPTION B: Ambient is genuinely flat E^4; dS is intrinsic to brane
-------------------------------------------------------------------

CLAIM: The 4D ambient is genuinely flat Euclidean E^4. The de Sitter
behaviour and associated temperature are internal to the brane —
felt by brane-confined observers — not a feature of the ambient
geometry.

ANALOGY: Unruh effect. An accelerating observer in flat Minkowski space
sees a thermal bath at T_Unruh = a/(2π). The underlying spacetime is
perfectly cold; the temperature is observer-dependent.

CONSISTENCY CHECKS:

(i) Can a 3-brane embedded in flat E^4 have intrinsic de Sitter dynamics?
    YES, in principle. An FLRW metric on a 3-brane is a statement about
    the intrinsic metric, not about the ambient. You can have a
    de-Sitter-shaped 3-brane in flat E^4 — e.g., the brane traces out
    a hyperboloid-analog surface in E^4 where the intrinsic metric is
    that of dS_3.
    
    Concretely: parameterise the brane as w_4 = f(x, y, z, t_brane)
    for some function f. Choose f such that the induced metric on the
    brane is FLRW with dS equation of state. This is an extrinsic
    embedding question, and there's plenty of functional freedom to
    make the intrinsic geometry whatever you want. ✓

(ii) What determines the brane's embedding function f?
    In Paper 1, mass-energy drives w_4 evolution. In Option B, the
    same coupling — integrated over cosmological time — produces a
    specific embedding profile. If the integrated coupling drives
    w_4 linearly with "time" (i.e., constant rate), you get flat-
    spacetime-like embedding. If it drives w_4 with an accelerating
    profile (which is what "dark energy" means), the embedding curves
    away from flat and the intrinsic geometry is dS-like.
    
    This is CONSISTENT with the thermal-expansion story of Paper 2:
    the blocked-radiation mechanism drives H = const, which means
    the brane's embedding is accelerating in w_4 at constant proper
    rate, which means the intrinsic metric is dS_3 × time. ✓

(iii) Thermal behaviour in Option B:
    Question: does a brane-intrinsic observer see a thermal bath
    at T_dS = H/(2π), just like a true dS observer?
    
    YES, if the brane's intrinsic geometry is dS_3 (which the above
    argument establishes). An observer confined to the brane sees
    the brane's intrinsic geometry only (Nash/confinement argument
    from Paper 1). If that intrinsic geometry is dS, the observer
    sees dS thermality.
    
    This is NOT dependent on the ambient being curved. It's a
    statement about intrinsic geometry, which for a 3-brane in E^4
    is a function of the embedding. ✓

(iv) Matsubara mechanism in Option B:
    If brane-internal observers see thermal dS, then their effective
    field theory has Matsubara periodicity β = 2π/H. The analytic
    continuation mechanism of Test 9 goes through at the brane level.
    
    The ambient E^4 doesn't need to know about thermality — only the
    brane-intrinsic degrees of freedom do. ✓

VERDICT ON OPTION B:
Also internally consistent. The thermal-dS state is brane-intrinsic,
like Unruh temperature is observer-intrinsic. The ambient E^4 stays
flat and fundamental. Paper 1's entire setup is preserved.

What's REQUIRED: Option B needs a specific embedding function f(x,t)
that produces dS_3 intrinsic geometry. This isn't hard in principle —
FLRW embeddings in flat ambient are standard — but it becomes a
specific technical commitment of the framework.
""")

# Numerical illustration: a de Sitter 3-brane embedded in flat E^4
print("""
-------------------------------------------------------------------
Numerical illustration: embedding dS_3 in flat E^4 (Option B)
-------------------------------------------------------------------
""")

# One parametrisation: brane at w_4 = (1/H) * cosh(H*t) in appropriate coords
# This is the "Euclidean dS brane" — a hyperbolic embedding in flat ambient.

H = 1.0  # normalise Hubble rate
t_vals = np.linspace(-3, 3, 100)

# Brane height in w_4 direction (Lorentzian dS embedding)
# In (1+1)D analogue: brane is a hyperboloid w_4^2 - t^2 = (1/H)^2
w_4_brane = (1/H) * np.cosh(H * t_vals)

# "Time" is the hyperboloid parameter
# Intrinsic proper time on brane: τ = t (for this param)
proper_time = t_vals

fig, ax = plt.subplots(figsize=(8, 6))
ax.plot(t_vals, w_4_brane, 'b-', lw=2, label='Brane embedding (dS_3 shape)')
ax.axhline(1/H, color='gray', ls=':', alpha=0.5, label=f'w_4 minimum = 1/H = {1/H}')
ax.fill_between(t_vals, -1, 1/H - 0.1, alpha=0.1, color='red', label='Pre-brane region (not traversed)')
ax.set_xlabel('coordinate t (on brane)')
ax.set_ylabel(r'$w_4$ (ambient fourth dim)')
ax.set_title('Option B: brane embedded in flat E^4, intrinsic geometry = dS\nBrane accelerates through ambient; ambient stays flat.')
ax.legend(loc='upper center')
ax.grid(alpha=0.3)
ax.set_ylim(0.5, 10)
plt.tight_layout()
plt.savefig('/home/claude/test12_option_B_embedding.png', dpi=120)
print("Saved: test12_option_B_embedding.png")

# -------------------------------------------------------------------
# Comparison of options
# -------------------------------------------------------------------
print("""
-------------------------------------------------------------------
COMPARISON OF OPTIONS A AND B
-------------------------------------------------------------------

                     Option A                    Option B
Ambient geometry:    S^4 (curved)                E^4 (flat)
Brane geometry:      S^3 slice of S^4           dS_3 embedded in E^4
Local SR recovery:   Local E^4 approx           Exact (ambient is E^4)
Thermal origin:      Ambient feature            Brane-intrinsic (Unruh-like)
Matsubara mechanism: Natural in ambient         Natural in brane EFT
Aesthetic cost:      Ambient is curved          Requires embedding function
Paper 1 fit:         Partial (ambient ≠ flat)   Preserved (ambient = flat)

VERDICT: BOTH ARE SELF-CONSISTENT.

The choice between them is a matter of:
  1. Aesthetic/interpretive preference
  2. Ease of development of the Matsubara mechanism
  3. Whether you want the ambient to be fundamentally flat

My recommendation: GO WITH OPTION B.

Reasons:
  - It preserves Paper 1's flat-E^4 commitment intact.
  - The thermal mechanism becomes observer-dependent (brane-intrinsic),
    which is actually PHYSICALLY nicer — it parallels Unruh's
    observer-dependent temperature, and Unruh is on much firmer
    conceptual footing than "the universe's ambient is a 4-sphere".
  - The embedding-function route gives you a natural place to store
    the "brane action" that Section 8.2 of Paper 1 acknowledges is
    missing — the action that dictates f(x,t).
  - Option B explicitly separates "ambient geometry" (flat, stable,
    passive) from "brane dynamics" (curved, active). This is the
    right division of labour: it's the brane's motion that generates
    dS behaviour, not the ambient's shape.

But Option B DOES require:
  - Writing down the specific embedding ansatz f(x,t).
  - Showing that it's compatible with the blocked-radiation cooling
    mechanism (L ∝ ρ) — i.e., the dynamics that determines f comes
    from the thermodynamic argument.
  - Checking that brane-intrinsic observers see T_dS as claimed.
    This last is a Unruh-analogue calculation; should be tractable.

STATUS: Geometry mismatch is RESOLVED in principle. Both options work.
Option B is preferred and has specific technical requirements for full
development.
""")
