"""
Test 11: Quantifying the correlated prediction

Paper 2's distinctive claim is: the SAME brane-thermality parameter
controls both
  (a) deviation of w(z) from -1
  (b) Lorentz-violation signature at cosmological scales

If this correlation is real and quantifiable, it's a genuinely novel
prediction. If not, the "unified mechanism" claim is weaker than it
sounds.

The task here: identify the dimensionless parameter that controls both
deviations, and compute the leading-order relationship.

METHOD:
Both deviations should be controlled by the departure from exact de Sitter,
which we parameterised in Test 10 as deviation from n = 1 in L ∝ ρ^n.

Let ε = n - 1. Then:
  - w_eff = 2ε(1 + w_internal) - 1
  - Deviation from de Sitter: δw = w_eff - (-1) = 2ε(1 + w_internal)

For the LIV side: deviations from exact SO(3,1) in the emergent-Lorentz
story. If Matsubara periodicity β = 1/T is the analytic-continuation
mechanism, then imperfect thermal equilibrium (T drifting) = imperfect
analytic continuation = residual SO(4) contamination in the effective
group structure.

Specifically: if T drifts with time at rate dT/dt = T × H × f(ε),
where f is a model-dependent function of the deviation parameter, then
the Matsubara periodicity is only approximate, and the mismatch shows
up as an effective LIV parameter.

Let's work this out carefully.
"""

import numpy as np
import matplotlib.pyplot as plt

print("=" * 72)
print("TEST 11: Quantifying the correlated prediction")
print("=" * 72)

# -------------------------------------------------------------------
# Part 1: The dark-energy-side deviation
# -------------------------------------------------------------------
print("""
-------------------------------------------------------------------
PART 1: The w(z) deviation from -1 in terms of ε = n - 1
-------------------------------------------------------------------

From Test 8: w_eff = 2(n-1)(1 + w_internal) - 1.

Write n = 1 + ε. Then:
    w_eff = 2ε(1 + w_internal) - 1
    δw ≡ w_eff - (-1) = 2ε(1 + w_internal)

For dust (w_internal = 0, matter-dominated): δw = 2ε
For radiation (w_internal = 1/3):            δw = 8ε/3

So the deviation is LINEAR in ε at leading order, with coefficient of
order 2-3 depending on what the dominant brane-confined component is.

For current observational bounds:
  - Planck + SNIa + BAO constrain w = -1 ± 0.05 (95% CL, roughly)
  - So |δw| ≲ 0.05
  - Giving |ε| ≲ 0.025 for dust-dominated, |ε| ≲ 0.019 for radiation

This is a meaningful bound on ε.
""")

# -------------------------------------------------------------------
# Part 2: The LIV-side deviation — this is where it gets harder
# -------------------------------------------------------------------
print("""
-------------------------------------------------------------------
PART 2: The LIV deviation from ε — THIS IS THE HARD PART
-------------------------------------------------------------------

For the correlated-prediction claim to hold, ε must ALSO control the
magnitude of LIV at some scale.

STRATEGY 1: Use the KMS-condition logic.
  Perfect thermal equilibrium → perfect Matsubara periodicity →
  perfect analytic continuation (propagator level) → Lorentz recovery.
  Imperfect thermal equilibrium → drift in T → imperfect periodicity.

  The imperfection can be characterised by how fast T changes in units
  of T itself: (dT/dt) / T^2, which is dimensionless.

  For exact de Sitter, T = H/(2π) = const, so (dT/dt)/T^2 = 0.
  For deviation: dT/dt = (dH/dt)/(2π).

  The Hubble rate evolution (Friedmann + continuity) gives:
      dH/dt = -4πG(ρ + p) = -4πG × ρ × (1 + w_eff)
  
  For w_eff near -1: dH/dt ≈ -4πG × ρ × (1 + w_eff) = -4πG × ρ × δw
  
  Note this is proportional to δw itself. So the thermal drift rate
  tracks the w-deviation — good, this is the linkage we need.

  In units of T^2 = (H/2π)^2:
      (dT/dt)/T^2 = (dH/dt)/(2π) × (2π/H)^2
                  = (dH/dt) × 2π / H^2
                  = -4πG ρ δw × 2π / H^2
                  = -8π^2 G ρ δw / H^2
                  = -8π^2 δw / 3   [using H^2 = 8πG ρ / 3]
                  = -(8π^2 / 3) × δw

  So the dimensionless thermal-drift parameter is:
      η_LIV ~ |(dT/dt)/T^2| = (8π^2 / 3) × |δw| ≈ 26.3 × |δw|

  This is the LEADING dimensionless parameter characterising the
  imperfection of the Matsubara analytic continuation.

  So to LEADING ORDER: η_LIV and δw are the SAME deviation parameter,
  up to an order-of-magnitude prefactor of about 26.

STRATEGY 2: This is only the propagator-level statement.
  Whether η_LIV translates into an OBSERVABLE LIV parameter (like
  a modified dispersion relation E^2 = p^2 c^2 + m^2 c^4 + ξ E^3/M_Pl)
  depends on the specific LIV channel. We can't compute this without
  a more detailed model of how the residual SO(4)-contamination
  appears in the effective field theory on the brane.

  For now: assume η_LIV sets the overall scale of LIV effects, with
  channel-dependent prefactors of order unity.
""")

# -------------------------------------------------------------------
# Part 3: Numerical illustration of the correlation
# -------------------------------------------------------------------
print("""
-------------------------------------------------------------------
PART 3: Numerical illustration
-------------------------------------------------------------------
""")

# ε ranges from -0.025 (phantom) to +0.025 (quintessence) — the observational window
epsilons = np.linspace(-0.025, 0.025, 51)

# Dust-dominated (w_internal = 0)
delta_w_dust = 2 * epsilons  # since δw = 2ε for w_internal=0

# LIV parameter at leading order
eta_LIV = (8 * np.pi**2 / 3) * np.abs(delta_w_dust)

# Plot the correlation
fig, axes = plt.subplots(1, 2, figsize=(13, 5))

axes[0].plot(epsilons, delta_w_dust, 'b-', label='δw (dust-dominated)')
axes[0].axhline(0, color='k', lw=0.5)
axes[0].axvline(0, color='k', lw=0.5)
axes[0].set_xlabel('ε = n - 1')
axes[0].set_ylabel('δw = w_eff + 1')
axes[0].set_title('DE deviation vs ε')
axes[0].grid(alpha=0.3)
axes[0].legend()

axes[1].plot(np.abs(delta_w_dust), eta_LIV, 'r-')
axes[1].set_xlabel(r'$|\delta w|$')
axes[1].set_ylabel(r'$\eta_{LIV}$ (dimensionless thermal drift)')
axes[1].set_title(r'LIV drift vs DE deviation: $\eta_{LIV} \approx 26 |\delta w|$')
axes[1].grid(alpha=0.3)

# Observational bounds
axes[1].axvline(0.05, color='gray', linestyle='--', label='DE obs. bound (|δw|<0.05)')
axes[1].legend()

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

# -------------------------------------------------------------------
# Part 4: Sanity check against known LIV bounds
# -------------------------------------------------------------------
print("""
-------------------------------------------------------------------
PART 4: Sanity check against known LIV bounds
-------------------------------------------------------------------

The leading-order prediction is:
    η_LIV ~ 26 × |δw|

Using the observational DE bound |δw| < 0.05:
    η_LIV ≲ 1.3

This is the dimensionless thermal-drift parameter. The question is
whether this is already in conflict with LIV observations.

LIV bounds vary dramatically by channel:
  - Photon dispersion (GRBs, Fermi LAT): ξ ≲ 10^-18 at GeV-TeV
  - Electron dispersion: ξ ≲ 10^-16 or tighter
  - Gravitational wave propagation (GW170817): δc/c ≲ 10^-15

BUT these bounds are on LOCAL, HIGH-ENERGY LIV parameters. Paper 2's
prediction is for COSMOLOGICAL-SCALE LIV, which is a different beast —
effectively a long-wavelength, slow-time effect controlled by the Hubble
rate.

The relevant comparison is not photon dispersion at high energy but
things like:
  - Frame-dragging / preferred-frame effects at cosmological scales
    (PPN parameters α_1, α_2, α_3): bounded to ~10^-7 or tighter
  - Variation of fundamental constants with cosmic time: dα/α / H ~ 10^-6
  - CMB anomalies (alignments, hemispheric asymmetry) consistent with
    ~ few percent LIV at horizon scales

So "η_LIV ~ 1" translates approximately to "order-unity preferred-frame
effects at the Hubble scale", which IS already ruled out by many orders
of magnitude IF interpreted in the standard PPN sense.

This is a problem. Let's check what bound the cosmological PPN limits
put on δw:

If η_LIV ≲ 10^-7 (cosmological PPN bound), then |δw| ≲ 10^-7 / 26
~ 4 × 10^-9.

That is MORE STRINGENT than the DE bound by a factor of ~10^7.

In other words: if the correlation is real at the leading-order level
computed here, then existing cosmological PPN bounds already constrain
δw to be smaller than what we can directly measure from SNIa/BAO.

This has two possible readings:

  READING 1 (bad for Paper 2): The mechanism is already ruled out.
  The correlation predicts η_LIV and δw should be of similar magnitude
  (up to the factor of 26), but observations show cosmological LIV is
  many orders of magnitude smaller than the current DE-w uncertainty.
  If δw really is of order 0.01 (as is still allowed by DE data), then
  η_LIV should be of order 0.2, which is catastrophically inconsistent
  with PPN bounds. The mechanism is in tension with data.

  READING 2 (rescuable): The naive (8π^2/3)|δw| coefficient is wrong.
  The true translation from thermal drift to observable LIV involves
  a suppression factor we haven't computed. For instance, if there's a
  screening mechanism that makes η_LIV inaccessible to PPN-type
  measurements, the correlation could be preserved in structure but
  with an additional hierarchy.

  Which reading is right depends on whether the PPN parameters actually
  couple to η_LIV at the level of effective field theory. This is a
  serious calculation that hasn't been done.

STATUS: The correlated prediction, as currently formulated, appears to
be in TENSION with existing cosmological LIV bounds at the naive
leading-order level. This tension is either:
  - Fatal to the mechanism (Reading 1)
  - A sign that the effective coupling to observable LIV channels is
    suppressed (Reading 2), requiring a detailed EFT calculation to settle.

This is the single most important calculation needed before Paper 2
can be written. Test 11 identifies the problem but does not resolve it.
""")

# -------------------------------------------------------------------
# Numerical illustration of the bound tension
# -------------------------------------------------------------------
print("""
Illustrative numbers:

δw allowed by DE data: |δw| < 0.05
η_LIV predicted (naive): ~1.3
η_LIV allowed by PPN: ~10^-7

Ratio: naive prediction / allowed = 1.3 / 10^-7 ~ 10^7

This is the factor by which the naive correlation overpredicts LIV.

To rescue the mechanism, Paper 2 would need to show that the
naive (8π^2/3) coefficient is suppressed by ~10^7 through a specific
EFT mechanism. That is not impossible — decoupling of soft modes
is a familiar story — but it's not guaranteed either, and it would
materially weaken the "correlated prediction" as an observational
handle.
""")
