"""
Test 3 EXTENDED: GW polarisations — proper DOF counting and dispersion
======================================================================

Previous test 3 asserted that the framework reproduces GR's 2 tensor 
modes, but the argument was thin. This extension does the work:

1. Start from the brane embedding explicitly. Perturb around flat brane
   in E^4. 
2. Compute the induced metric perturbation h_ij on the brane.
3. Derive the linearised equations of motion from the brane action
   (Nambu-Goto-like, generalised).
4. Gauge-fix and count physical propagating modes.
5. Check the dispersion relation (should be omega = c*k — GWs move at c).

Setup:
------
Flat background: brane at w4 = w0(t) = u0*t, with intrinsic coordinates
(x, y, z). Perturbation: the brane's w4 height depends on position:
  w4(x, y, z, t) = u0*t + W(x, y, z, t)
where W is small.

Also allow *tangential* perturbations — the brane can slide in the 
ambient (x, y, z) directions. But these are pure gauge (coordinate
relabelling of brane points), so we can set them to zero by choice.

Wait — that's not quite right for a full analysis. Let me be careful.
A 3-brane in E^4 with one transverse direction has ONE physical normal
perturbation. That gives only 1 scalar mode, which cannot reproduce 
GR's 2 tensor modes.

Resolution: the framework is NOT a simple hypersurface-in-E^4 picture
where gravity reduces to the single normal displacement. The framework
includes the *advance rate* u as an independent structural element.
Perturbations include:
  (A) normal displacement W(x,y,z,t)  — 1 mode
  (B) advance rate variation u(x,y,z,t) — 1 mode (but constrained)

Hmm, that's still only 2, and they'd be scalar modes not tensor.

Let me reconsider. Perhaps I was wrong in test 3. Let's work through
carefully.
"""

import numpy as np
import sympy as sp

print("="*72)
print("TEST 3 EXTENDED: Proper DOF analysis for GW modes")
print("="*72)
print()

# The honest question: does a 3-brane in E^4 support 2 tensor modes,
# or only scalar modes?
#
# Standard ER (Euclidean Relativity) literature (Montanus, Almeida, etc.)
# treats the brane as a 4D Euclidean manifold with proper time as a 
# spatial direction. In that picture, gravity is...... not obviously 
# tensorial.
#
# This is actually a genuine difficulty for the framework. Let me 
# think through it.

print("THE GENUINE ISSUE:")
print("-"*72)
print()
print("A 3-brane in E^4 (codimension 1) has at each point:")
print("  - 1 normal direction (w4)")
print("  - 3 tangent directions (spatial brane coords)")
print()
print("A perturbation of the embedding is a function W(x,y,z,t) giving the")
print("w4 displacement at each brane point. This is 1 scalar field.")
print()
print("But GWs have 2 tensor polarisation modes, not 1 scalar. So either:")
print("  (a) The framework only reproduces scalar gravity (wrong) or")
print("  (b) The GW modes come from something other than normal")
print("      displacement.")
print()

# This is where I need to think carefully. What IS a GW in the framework?
# 
# Option (b): GWs are not about W(x,y,z,t) at all. GWs are about the 
# INDUCED METRIC on the brane. The induced metric g_ij on the brane is
# computed from the ambient embedding. Perturbations of g_ij can come from:
#   - Normal displacement (1 d.o.f.)
#   - Tangential reparameterisation (gauge)
#   - DIFFERENTIAL ADVANCE RATE u(x,y,z,t) across the brane
#
# The advance rate u is not a separate ambient coordinate — it's the rate
# at which the brane sweeps through w4 AT a given point. If u varies over
# the brane, the INDUCED 4D metric (including time) picks up off-diagonal
# terms.
#
# Hmm, but that's 1 scalar too.
#
# Actually — let me look at this differently. In GR, the metric is a 
# rank-2 symmetric tensor with 6 independent spatial components. The 2 
# physical GW modes are what's left after gauge-fixing and constraints.
# 
# The framework claims gravity IS the embedding. In the simplest version
# (codimension-1 brane in E^4), the embedding has fewer d.o.f. than the 
# metric. This is actually a TENSION in the framework.

print("POSSIBLE RESOLUTIONS:")
print("-"*72)
print()
print("Option 1: HIGHER-CODIMENSION EMBEDDING")
print("  If the brane is embedded in a higher-dimensional ambient space")
print("  (say E^10), there are more normal directions, and the embedding")
print("  has enough d.o.f. to match GR. But this modifies the postulate:")
print("  it's no longer 'E^4 with one w4 direction'.")
print()
print("Option 2: COMPOSITE MODE STRUCTURE")
print("  Combine (normal displacement) + (differential advance rate) +")
print("  (intrinsic brane curvature) — maybe together these give enough")
print("  d.o.f. to reproduce 2 tensor modes. Requires detailed calculation.")
print()
print("Option 3: THE FRAMEWORK ONLY PRODUCES SCALAR GRAVITY")
print("  If this is true, the framework disagrees with observation:")
print("  LIGO has detected tensor GWs. This would be a falsification.")
print()
print("Option 4: GAUSS-CODAZZI STRUCTURE")
print("  For a submanifold of dim D in a higher-dim ambient, the intrinsic")
print("  Ricci tensor is related to ambient Ricci + extrinsic curvature.")
print("  The Gauss-Codazzi equations provide 6 components of intrinsic")
print("  curvature from fewer independent embedding functions, because")
print("  the embedding has NONLINEAR structure. The 'extra' intrinsic")
print("  d.o.f. come from derivatives of the single embedding function.")
print("  This might give enough structure for 2 tensor modes.")
print()

# Let me try to make Option 4 explicit.
# 
# Consider a brane given by w4 = W(x,y,z,t). The induced 4D metric on
# the brane (with brane time) is:
#   g_mu_nu = eta_mu_nu + partial_mu W * partial_nu W  (Euclidean signature)
# (for small W, expanding to second order)
# 
# For ANY 4D vector field F_mu = partial_mu W, the induced metric has
# symmetric perturbation:
#   delta g_mu_nu = F_mu F_nu  (at leading nonlinear order)
# or
#   delta g_mu_nu ~ partial_mu partial_nu W  (linearly, in some gauge)
#
# Hmm, that's not quite right either. Let me try sympy.

print("EXPLICIT LINEARISED INDUCED METRIC CALCULATION:")
print("-"*72)
print()

# Coordinates on the brane: x^mu = (t, x, y, z)
# Embedding: X^A = (t, x, y, z, W(t,x,y,z)) in E^5 with flat metric
# (using E^5 with Lorentzian signature because the brane inherits that)
# 
# Actually, let me use the framework's language: ambient is E^4 (Euclidean),
# brane intrinsic has 3 space + 1 "advance direction". The Lorentzian
# signature on the brane comes from the projection.
#
# Cleaner approach: work in the *final* (3,1) signature on the brane,
# since GR works in that signature and we want to compare to GR's GW modes.

t, x, y, z = sp.symbols('t x y z', real=True)
W = sp.Function('W')(t, x, y, z)

# The induced metric on the brane from embedding in (1,3)+1 = (1,4)-ish
# -- actually let me just assume the embedding contribution gives a 
# metric perturbation of the form:
# h_mu_nu ~ f(partial W) terms

# Simpler: in linearised theory, any metric perturbation can be decomposed
# via the 3+1 helicity decomposition:
#   h_00 = 2 phi
#   h_0i = B_i (vector)
#   h_ij = 2 psi delta_ij + (partial_i partial_j - (1/3) delta_ij box) E 
#           + (partial_i F_j + partial_j F_i) + h^TT_ij
# where h^TT is transverse-traceless (2 dof), F is transverse vector (2 dof),
# E is scalar (1 dof), B is vector (3 dof, 2 after constraints), 
# phi and psi are scalars.
#
# GR's gauge freedom removes some, constraints remove others, leaving 2 tensor.
#
# Framework question: which of these helicity components are generated by
# perturbations of the embedding?

print("3+1 helicity decomposition of metric perturbation h_mu_nu:")
print("  Scalars: phi (in h_00), psi (trace of h_ii), E (longitudinal h_ij)")
print("  Vectors: B_i (in h_0i), F_i (transverse h_ij)")  
print("  Tensor:  h_ij^TT (transverse-traceless)")
print()
print("Total: 4 scalar + 2*2 vector + 2 tensor = 10 metric components ✓")
print()
print("GR gauge fixing (4 coord choices) kills some of these. Constraints")
print("(4 from G_0mu = 0 on each Cauchy slice) kill more. What propagates: 2.")
print()

# Now: what does a single embedding function W(t,x,y,z) generate under 
# linearised perturbation?
# 
# If the embedding is X^A = (x^mu, W(x)), the induced metric in the 
# (x^mu) coordinates is g_mu_nu = eta_mu_nu + partial_mu W partial_nu W.
# At LEADING (linear) order in W, delta g_mu_nu = 0 (quadratic!).
# The leading perturbation is SECOND ORDER in W.
#
# So a single scalar embedding perturbation gives only h_mu_nu = O(W^2) 
# of the specific form F_mu F_nu where F = partial W. This is NOT a 
# general metric perturbation — it's highly constrained.
#
# In fact, h_mu_nu = partial_mu W * partial_nu W has only 1 d.o.f. (W).
# You cannot make 2 independent tensor modes out of this.

print("CRITICAL CALCULATION:")
print("-"*72)
print()
print("For embedding X^A = (x^mu, W(x)) with flat ambient Euclidean E^4:")
print()
print("  g_mu_nu = eta_mu_nu + partial_mu W * partial_nu W")
print()
print("At linear order in W: delta g_mu_nu = 0 (the perturbation is QUADRATIC)")
print("At leading nonlinear order: h_mu_nu = partial_mu W * partial_nu W")
print()
print("This h_mu_nu has the form F_mu F_nu where F_mu = partial_mu W.")
print("Only 1 underlying degree of freedom (W). Cannot support 2 independent")
print("tensor modes.")
print()
print("IMPLICATION: A simple codimension-1 embedding of a 3-brane in E^4")
print("does NOT reproduce GR's 2 tensor GW modes.")
print()
print("This is a GENUINE FAILURE of the naive framework picture.")
print()

print("="*72)
print("HONEST VERDICT FOR TEST 3 EXTENDED")
print("="*72)
print()
print("The naive framework (simple codim-1 3-brane in E^4) does NOT")
print("reproduce GR's 2 tensor GW modes. It gives at most 1 scalar mode.")
print()
print("This is a genuine issue the framework must address. Options:")
print()
print("1. REINTERPRETATION: Maybe 'GWs' in the framework aren't embedding")
print("   ripples at all, but something else (e.g., intrinsic brane field")
print("   modes). This is ad hoc but possible.")
print()
print("2. HIGHER CODIMENSION: The brane is embedded in E^D with D > 4,")
print("   giving more normal directions. Kaluza-Klein-like. Modifies the")
print("   single-postulate story.")
print()
print("3. INTRINSIC METRIC AS INDEPENDENT: Treat g_mu_nu on the brane as")
print("   not fully determined by the embedding — as a partially independent")
print("   structure. This makes the framework closer to standard GR with")
print("   extra interpretive overlay, less parsimonious.")
print()
print("4. ACCEPT THE LIMIT: The framework's geometric account might only")
print("   reach as far as scalar aspects of gravity (time dilation, Λ,")
print("   cosmological expansion, horizon thermodynamics). Tensor GWs")
print("   might be outside its geometric account — they'd still exist")
print("   (the framework doesn't forbid them) but their existence would")
print("   be a feature of brane-fields not the embedding.")
print()
print("I flagged this in my previous response but waved it through too")
print("easily. A proper paper needs to address this. It may be that the")
print("framework's scope is more limited than the full 'GR is brane")
print("kinematics' claim suggests.")
print()
print("This is the kind of issue that distinguishes the 'framework points")
print("at something real' reading from the 'framework is loose enough to")
print("appear to home many things' reading. Tensor GW modes are a place")
print("where the postulate does NOT obviously deliver.")
