#!/usr/bin/env python3
"""
solve_for_nuclear_L.py

Work backwards: Given known nuclear forces, what L makes our equation work?
F = L²/(γmr³) → L = √(F × γmr³)
"""

import numpy as np
import scipy.constants as const

def solve_for_L(name, F_target, mass_kg, radius_m):
    """Given force, mass, and radius, solve for required L"""
    
    c = const.c
    hbar = const.hbar
    
    # Start with non-relativistic
    L_squared = F_target * mass_kg * radius_m**3
    L = np.sqrt(L_squared)
    
    # Check velocity this implies
    # For spinning sphere: v = L/(I/r) = 5L/(2mr²) × r = 5L/(2mr)
    v_spin = 5 * L / (2 * mass_kg * radius_m)
    
    # For orbital motion: v = L/(mr)
    v_orbital = L / (mass_kg * radius_m)
    
    print(f"\n{name}:")
    print(f"  Target force: {F_target:.2e} N")
    print(f"  Solved L = {L:.2e} J·s = {L/hbar:.3f}ℏ")
    print(f"  If spinning ball: v = {v_spin/c:.3f}c")
    print(f"  If orbital: v = {v_orbital/c:.3f}c")
    
    # Now iterate with relativity
    if v_orbital < 0.9 * c:
        for i in range(5):
            beta = v_orbital / c
            gamma = 1.0 / np.sqrt(1 - beta**2)
            L_squared_rel = F_target * gamma * mass_kg * radius_m**3
            L_rel = np.sqrt(L_squared_rel)
            v_orbital = L_rel / (mass_kg * radius_m)
        
        print(f"  With relativity: L = {L_rel:.2e} J·s = {L_rel/hbar:.3f}ℏ")
    
    return L, L_rel if v_orbital < 0.9 * c else L

def analyze_nuclear_forces():
    """What L do real nuclear forces require?"""
    
    print("SOLVING FOR NUCLEAR ANGULAR MOMENTUM")
    print("="*60)
    print("Working backwards from known forces")
    
    # Constants
    mp = const.m_p
    r_proton = 0.875e-15  # m
    
    # Different force scales from literature
    forces = [
        ("Typical nuclear", 1e4),      # ~10 kN
        ("Strong nuclear", 1e5),       # ~100 kN  
        ("Your target", 8.2e5),        # ~820 kN
        ("Nucleon-nucleon", 2e4),      # ~20 kN at 1 fm
        ("QCD string tension", 1.6e5), # ~0.18 GeV/fm
    ]
    
    L_values = []
    
    for name, F in forces:
        L_nr, L_rel = solve_for_L(name, F, mp, r_proton)
        L_values.append(L_rel / const.hbar)
    
    print("\n" + "="*60)
    print("PATTERN ANALYSIS:")
    print(f"L values range: {min(L_values):.1f}ℏ to {max(L_values):.1f}ℏ")
    print(f"Average: {np.mean(L_values):.1f}ℏ")
    
    print("\nINSIGHT:")
    print("Nuclear forces require L ~ 10-30ℏ")
    print("Much larger than atomic L = 1ℏ")
    print("This explains why nuclear forces are stronger!")

def explore_what_L_means():
    """What physical quantity does L represent?"""
    
    print("\n\nWHAT DOES L REPRESENT?")
    print("="*60)
    
    hbar = const.hbar
    
    print("CLUES:")
    print("1. Has units of angular momentum [J·s]")
    print("2. L = 1ℏ for atoms (perfect)")
    print("3. L ~ 10-30ℏ for nuclei (from forces)")
    print("4. NOT spin (that's ℏ/2)")
    
    print("\nPOSSIBILITIES:")
    print("a) Effective angular momentum of bound system")
    print("b) Phase space volume of interaction")
    print("c) Circulation quantum at that scale")
    print("d) Something entirely new?")
    
    # Dimensional analysis
    print("\nDIMENSIONAL CHECK:")
    print("L² appears in force formula")
    print("L²/(mr³) must give force")
    print("[J²s²]/[kg·m³] = [N] ✓")

def main():
    analyze_nuclear_forces()
    explore_what_L_means()
    
    print("\n" + "="*70)
    print("CONCLUSION:")
    print("Nuclear L is 10-30× larger than atomic L")
    print("This isn't spin - it's something else")
    print("The 'quantum of binding' at each scale?")

if __name__ == "__main__":
    main()
