"""
Test: Equivalence principle from unified w4 coupling
====================================================

Standard status:
The equivalence principle (EP) comes in several forms:
  - Weak (WEP): Inertial mass m_i = gravitational mass m_g.
    Tested to ~10^-15 (MICROSCOPE mission).
  - Einstein (EEP): Locally, gravity is indistinguishable from 
    acceleration. Foundation of GR.
  - Strong (SEP): Includes self-gravitating bodies; tested via lunar
    laser ranging and pulsar timing.

In Newtonian mechanics, m_i in F = m_i * a and m_g in F_g = m_g * g
are *conceptually distinct* and their equality is empirical. GR takes
the equality as a postulate (geometrisation of gravity).

Framework claim:
In the framework, mass-energy has a *single* role: coupling to w4.
That coupling determines both:
  (a) How the object advances in w4 (its proper-time rate) -- the
      "gravitational" aspect.
  (b) How the object responds to being displaced on the brane -- the
      "inertial" aspect.

If (a) and (b) are manifestations of the same coupling, then m_i = m_g
isn't an empirical coincidence; it's a structural identity.

Test: show that from the postulate alone, the quantity that determines
an object's w4 advance rate is the same quantity that determines its
resistance to acceleration on the brane.
"""

import numpy as np
import sympy as sp

print("="*72)
print("TEST: Equivalence principle from unified w4 coupling")
print("="*72)
print()

# Set up: a brane-confined object with mass-energy m.
# The object's state involves:
#   - Position on brane: (x, y, z)
#   - Brane-time advance: w4 coordinate
# Mass-energy couples to w4. Let's characterise what "coupling strength" m is.

# Action argument:
# The simplest relativistic action for a particle is
#   S = -m * integral(d(tau))
# where tau is proper time. This gives both:
#   - Relativistic dynamics (inertial mass from dp/dt)
#   - Gravitational coupling (via g_munu in the proper time element)

# In the framework, proper time IS the w4 advance. So the action becomes:
#   S = -m * integral(d(w4_advance))
# 
# Now, the key question: does m in this action play two conceptually 
# distinct roles (inertial + gravitational), or is it one role?

print("ACTION-LEVEL ARGUMENT:")
print("-"*72)
print()
print("Particle action in the framework:")
print()
print("  S = -m * integral(d(w4_advance_along_worldline))")
print()
print("This is ONE quantity (m = coupling strength to w4) appearing in")
print("ONE integrand (the w4-advance element).")
print()

# Derive equations of motion
t, x, y, z = sp.symbols('t x y z', real=True)
m, c = sp.symbols('m c', positive=True)
# Flat spacetime case:
# d(w4_advance) = sqrt(1 - v^2/c^2) dt  (proper time element, weak field)
# Action: S = -m*c^2 * integral sqrt(1 - v^2/c^2) dt
# In non-relativistic limit: 
#   sqrt(1 - v^2/c^2) ≈ 1 - v^2/(2c^2)
#   L = -m*c^2 * (1 - v^2/(2c^2)) = -m*c^2 + (1/2) m v^2
# First term is constant, second is kinetic energy.
# Kinetic energy is (1/2) m v^2 -- so the "m" in kinetic energy is the
# same m as in the action (= w4 coupling).

# In a gravitational potential Phi (weak field):
# d(w4_advance) = sqrt(1 - v^2/c^2 + 2 Phi/c^2) dt
# Non-rel limit: sqrt(...) ≈ 1 - v^2/(2c^2) + Phi/c^2
# L = -mc^2 - (1/2)mv^2 + m Phi  ... wait let me redo:
# Actually L = -mc^2 * sqrt(1 - v^2/c^2 + 2*Phi/c^2)
# ≈ -mc^2 * (1 - v^2/(2c^2) + Phi/c^2)  
# = -mc^2 + (1/2)m v^2 - m Phi
# (after flipping sign convention: positive KE, potential energy +m*Phi)
# The gravitational potential energy is m * Phi, where m is the SAME m.

v = sp.Symbol('v', real=True)
Phi = sp.Symbol('Phi', real=True)

# Proper time element in weak gravitational field + slow motion:
dtau_dt = sp.sqrt(1 + 2*Phi/c**2 - v**2/c**2)
L = -m * c**2 * dtau_dt

# Expand for small v/c and small Phi/c^2:
L_expanded = sp.series(L, v, 0, 3).removeO()
L_expanded = sp.series(L_expanded, Phi, 0, 2).removeO()
L_expanded = sp.simplify(L_expanded)

print(f"Particle Lagrangian in weak field (expanded):")
print(f"  L = {L_expanded}")
print()
print("Interpretation:")
print("  -m*c^2      : rest-mass energy term")
print("  +(1/2)m*v^2 : kinetic energy -- coefficient m is 'inertial mass'")
print("  +m*Phi      : gravitational potential energy -- coefficient m is")
print("                'gravitational mass'")
print()
print("Both m's are the SAME SYMBOL, because they come from the same")
print("action coefficient, which is the same w4 coupling.")
print()
print("=> m_inertial = m_gravitational is structurally enforced, not")
print("   imposed.")
print()

# Now derive the equations of motion to see this explicitly.
# Euler-Lagrange for free particle in potential Phi:
# L = (1/2) m v^2 - m Phi  (non-rel, dropping constant rest-mass term)

# m * a = -m * grad(Phi)
# a = -grad(Phi)

print("EQUATIONS OF MOTION:")
print("-"*72)
print()
print("From Euler-Lagrange on L_nonrel = (1/2)*m*v^2 - m*Phi:")
print()
print("  d/dt(m * v) = -m * grad(Phi)")
print("       m * a  = -m * grad(Phi)")
print("  =>        a = -grad(Phi)")
print()
print("The m cancels. Test particle acceleration in gravity is")
print("independent of m -- this is the weak equivalence principle.")
print()
print("In the framework: the cancellation is structural because the")
print("m on the left (from kinetic term) and the m on the right (from")
print("potential term) are the SAME m (the w4 coupling), not two")
print("coincidentally-equal quantities.")
print()

# Let me also address the Einstein EP (locally gravity = acceleration).
# In GR this is geometric. In the framework?

print("EINSTEIN EQUIVALENCE PRINCIPLE (LOCAL INDISTINGUISHABILITY):")
print("-"*72)
print()
print("Claim: locally, a freely-falling observer cannot distinguish gravity")
print("from inertial motion.")
print()
print("Framework account:")
print("  - Gravity is differential w4 advance across the brane.")
print("  - A freely-falling observer follows a geodesic of the induced")
print("    brane geometry.")
print("  - Locally (small neighbourhood), a geodesic looks straight in")
print("    the induced metric.")
print("  - The induced metric is Lorentzian (from the postulate + ER).")
print("  - Locally, 'straight in Lorentzian metric' is indistinguishable")
print("    from 'uniform motion in flat spacetime'.")
print("  - Therefore local free-fall observers see flat spacetime = no")
print("    gravity felt.")
print()
print("The key framework move: the induced brane metric is all the local")
print("observer has access to. They cannot directly observe the ambient")
print("w4 structure. Their local physics IS their induced metric, which")
print("is flat locally for geodesic observers -- recovering EEP.")
print()

# Let's also check strong equivalence principle considerations:
# SEP states that even self-gravitating bodies fall the same. This 
# requires the gravitational binding energy contributes to both inertial 
# and gravitational mass equally.
# 
# In GR, this is enforced by nonlinear coupling.
# In the framework, gravitational binding energy is... what exactly?
# 
# Binding energy in the framework would be the extent to which a 
# configuration's w4-embedding differs from the unbound case. A bound 
# configuration has a deeper 'well' in w4. This energy is mass-energy, 
# and mass-energy couples to w4. So binding energy also couples to w4, 
# and does so with the same rule as rest-mass energy.

print("STRONG EQUIVALENCE PRINCIPLE:")
print("-"*72)
print()
print("SEP: self-gravitating bodies fall the same as test particles.")
print("This requires gravitational binding energy to contribute equally")
print("to inertial and gravitational mass.")
print()
print("Framework account:")
print("  - Binding energy IS mass-energy (energy localised in the brane's")
print("    embedding configuration).")
print("  - All mass-energy couples to w4 in the same way.")
print("  - Therefore binding energy couples to w4, and does so through")
print("    the same mechanism as rest-mass.")
print("  - A self-gravitating body's total w4 coupling is simply the sum")
print("    of all its mass-energy contributions, including binding.")
print("  - The SEP 'equal contribution to m_i and m_g' requirement is")
print("    automatic: there's only one mass-energy quantity, and it has")
print("    only one coupling.")
print()

print("="*72)
print("VERDICT")
print("="*72)
print()
print("In the framework, m_inertial = m_gravitational is a STRUCTURAL")
print("IDENTITY, not an empirical coincidence.")
print()
print("Both quantities trace to the same thing: the object's mass-energy")
print("coupling to the w4 direction. There is no separate 'inertial")
print("coupling' and 'gravitational coupling' to be equal by accident.")
print()
print("This homes WEP, EEP, and SEP on a single postulate without")
print("requiring any of them to be additionally assumed.")
print()
print("Contrast:")
print("  - Newtonian: WEP is empirical.")
print("  - GR: WEP is assumed (geometrisation postulate).")
print("  - Framework: WEP is structurally enforced by the coupling structure.")
