"""F0000 — Geometric scaling lemmas (axiomatic layer)
Pillar : Geometry (root layer — F0001–F0031 are downstream consequences)
Spine  : Dilation r → λr on embedded surface Σ ⊂ R³
Chain  : metric g → second fundamental form b → shape operator S = g⁻¹b
         → curvatures → determinant → area element → γ scaling
Status : Axiomatic — CAS verifies the scaling algebra; the lemmas
         themselves are standard differential geometry.
"""

def run():
    from sympy import symbols, Matrix, simplify, zeros, pi, det

    lam = symbols('lam', positive=True)
    gamma_s = symbols('gamma_s', positive=True)
    V, ell = symbols('V ell', positive=True)

    # 2×2 metric and second fundamental form
    g11, g12, g22 = symbols('g11 g12 g22', real=True)
    b11, b12, b22 = symbols('b11 b12 b22', real=True)

    g = Matrix([[g11, g12], [g12, g22]])
    b = Matrix([[b11, b12], [b12, b22]])

    # 3×3 Jacobian entries
    y1, y2, y3, y4, y5, y6, y7, y8, y9 = symbols('y1:10', real=True)
    e1, e2, e3, e4, e5, e6, e7, e8, e9 = symbols('e1:10', real=True)
    Y = Matrix([[y1, y2, y3], [y4, y5, y6], [y7, y8, y9]])
    E = Matrix([[e1, e2, e3], [e4, e5, e6], [e7, e8, e9]])

    # Step 1: γ scaling — A_d' = γ·A_d
    A_d = V / ell
    ell_p = ell / gamma_s
    A_d_p = V / ell_p
    assert simplify(A_d_p - gamma_s * A_d) == 0, "FAIL Step 1"
    print("  Step 1  PASS — γ scaling: A_d' = γ·A_d")

    # Step 2: Metric dilation g_λ = λ²g
    g_lam = lam**2 * g
    assert simplify(g_lam - lam**2 * g) == zeros(2, 2), "FAIL Step 2"
    print("  Step 2  PASS — Metric dilation: g_λ = λ²·g")

    # Step 3: Second fundamental form b_λ = λb
    b_lam = lam * b
    assert simplify(b_lam - lam * b) == zeros(2, 2), "FAIL Step 3"
    print("  Step 3  PASS — Second fundamental form: b_λ = λ·b")

    # Step 4: Shape operator S_λ = S/λ
    S = g.inv() * b
    S_lam = g_lam.inv() * b_lam
    res4 = simplify(S_lam - S / lam)
    for i in range(2):
        for j in range(2):
            assert simplify(res4[i, j]) == 0, f"FAIL Step 4 ({i},{j})"
    print("  Step 4  PASS — Shape operator: S_λ = S/λ")

    # Step 5: Gaussian curvature K_λ = K/λ²
    K_orig = S.det()
    K_lam = S_lam.det()
    assert simplify(K_lam - K_orig / lam**2) == 0, "FAIL Step 5"
    print("  Step 5  PASS — Gaussian curvature: K_λ = K/λ²")

    # Step 6: Mean curvature H_λ = H/λ
    H_orig = S.trace() / 2
    H_lam = S_lam.trace() / 2
    assert simplify(H_lam - H_orig / lam) == 0, "FAIL Step 6"
    print("  Step 6  PASS — Mean curvature: H_λ = H/λ")

    # Step 7: Determinant identity det(λY+E) = λ³ det(Y+E/λ)
    from sympy import expand
    lhs7 = (lam * Y + E).det()
    rhs7 = lam**3 * (Y + E / lam).det()
    assert simplify(expand(lhs7) - expand(rhs7)) == 0, "FAIL Step 7"
    print("  Step 7  PASS — det(λY+E) = λ³·det(Y+E/λ)")

    # Step 8: Pure dilation det(λY) = λ³ det(Y)
    assert simplify((lam * Y).det() - lam**3 * Y.det()) == 0, "FAIL Step 8"
    print("  Step 8  PASS — det(λY) = λ³·det(Y)")

    # Step 9: Area element det(g_λ) = λ⁴ det(g)
    assert simplify(g_lam.det() - lam**4 * g.det()) == 0, "FAIL Step 9"
    print("  Step 9  PASS — Area element: det(g_λ) = λ⁴·det(g)")

    # Step 10: Inverse metric g_λ⁻¹ = g⁻¹/λ²
    res10 = simplify(g_lam.inv() - g.inv() / lam**2)
    for i in range(2):
        for j in range(2):
            assert simplify(res10[i, j]) == 0, f"FAIL Step 10 ({i},{j})"
    print("  Step 10 PASS — Inverse metric: g_λ⁻¹ = g⁻¹/λ²")

    # Step 11: Self-test — wrong metric exponent λ³
    g_wrong = lam**3 * g
    S_wrong = g_wrong.inv() * b_lam
    res11 = simplify(S_wrong - S / lam)
    any_nonzero = any(simplify(res11[i, j]) != 0 for i in range(2) for j in range(2))
    assert any_nonzero, "FAIL Step 11: wrong exponent not detected"
    print("  Step 11 PASS — Wrong metric exponent (λ³) detected")

    print("  ✓ F0000 — 11/11 PASS")


if __name__ == "__main__":
    run()
