Theory Gauss_Equation

theory Gauss_Equation
  imports Regular_Surface_Patch
begin

section ‹The Gauss equation and metric determination of curvature›

subsection ‹Differentiating the lower connection›

text ‹Pair the actual second derivative with a tangent vector. Commuting the
  third derivatives cancels the highest-order terms in the difference of
  these derivatives.›

definition lower_connection where
  "lower_connection X p a b c = inner (patch_second_derivative X p a b) (patch_derivative X p c)"

context regular_surface_patch
begin

lemma second_derivative_differentiable:
  assumes "p ∈ U"
  shows "(λq. patch_second_derivative X q a b) differentiable (at p)"
  using smooth_on_imp_differentiable_on[OF patch_second_derivative_c1[of b a]] assms open_domain
  unfolding patch_second_derivative_def
  by (simp add: differentiable_on_eq_differentiable_at)

lemma lower_connection_derivative:
  assumes p: "p ∈ U"
  shows "frechet_derivative (λq. lower_connection X q a b c) (at p) d =
    inner (frechet_derivative (λq. patch_second_derivative X q a b) (at p) d)
      (patch_derivative X p c) +
    inner (patch_second_derivative X p a b) (patch_second_derivative X p d c)"
proof -
  have da: "((λq. patch_second_derivative X q a b) has_derivative
    frechet_derivative (λq. patch_second_derivative X q a b) (at p)) (at p)"
    using second_derivative_differentiable[OF p, of a b] unfolding frechet_derivative_works .
  have dc: "((λq. patch_derivative X q c) has_derivative
    frechet_derivative (λq. patch_derivative X q c) (at p)) (at p)"
    using patch_direction_differentiable[OF p, of c] unfolding frechet_derivative_works .
  have product: "((λq. lower_connection X q a b c) has_derivative
    (λh. inner (patch_second_derivative X p a b) (patch_second_derivative X p h c) +
      inner (frechet_derivative (λq. patch_second_derivative X q a b) (at p) h)
        (patch_derivative X p c))) (at p)"
    unfolding lower_connection_def patch_second_derivative_def
    using bounded_bilinear.FDERIV[OF bounded_bilinear_inner da dc]
    unfolding patch_second_derivative_def by simp
  show ?thesis using fun_cong[OF frechet_derivative_at[OF product], where x=d]
    by (simp add: add.commute)
qed

lemma lower_connection_commutator:
  assumes p: "p ∈ U"
  shows "frechet_derivative (λq. lower_connection X q b c d) (at p) a -
    frechet_derivative (λq. lower_connection X q a c d) (at p) b =
    inner (patch_second_derivative X p b c) (patch_second_derivative X p a d) -
    inner (patch_second_derivative X p a c) (patch_second_derivative X p b d)"
  unfolding lower_connection_derivative[OF p]
  by (simp add: patch_third_derivative_commute[OF p])

lemma second_derivative_inner_decomposition:
  assumes p: "p ∈ U"
  shows "inner (patch_second_derivative X p a b) (patch_second_derivative X p c d) =
    first_fundamental_form X p (patch_connection X p a b) (patch_connection X p c d) +
    second_fundamental_form X p a b * second_fundamental_form X p c d"
proof -
  have unit: "inner (gauss_map X p) (gauss_map X p) = 1"
    using gauss_map_unit[OF p] by (simp add: dot_square_norm)
  show ?thesis
    by (subst (1 2) gauss_formula[OF p],
      simp add: inner_add_left inner_add_right unit first_fundamental_form_def
        gauss_map_orthogonal_derivative[OF p] inner_commute)
qed

subsection ‹The Gauss equation›

text ‹The remaining inner products split into tangent and normal contributions.
  Moving the tangent terms to the left gives the intrinsic expression whose
  right side is the determinant pattern of the second fundamental form.›

theorem gauss_equation:
  assumes p: "p ∈ U"
  shows "frechet_derivative (λq. lower_connection X q b c d) (at p) a -
    frechet_derivative (λq. lower_connection X q a c d) (at p) b -
    first_fundamental_form X p (patch_connection X p b c) (patch_connection X p a d) +
    first_fundamental_form X p (patch_connection X p a c) (patch_connection X p b d) =
    second_fundamental_form X p b c * second_fundamental_form X p a d -
    second_fundamental_form X p a c * second_fundamental_form X p b d"
  unfolding lower_connection_commutator[OF p] second_derivative_inner_decomposition[OF p]
  by simp

lemma lower_connection_metric:
  assumes p: "p ∈ U"
  shows "lower_connection X p a b c =
    first_fundamental_form X p (patch_connection X p a b) c"
  unfolding lower_connection_def
  by (subst gauss_formula[OF p],
    simp add: inner_add_left first_fundamental_form_def
      gauss_map_orthogonal_derivative[OF p])

lemma metric_differentiable:
  assumes "p ∈ U"
  shows "(λq. first_fundamental_form X q a b) differentiable at p"
  unfolding first_fundamental_form_def
  by (intro differentiable_inner patch_direction_differentiable[OF assms])

subsection ‹Coordinate formulas for the second form›

text ‹These bilinear coordinate formulas will also give the determinant
  transformation law under changes of parameters.›

lemma second_derivative_linear_left:
  assumes p: "p ∈ U"
  shows "linear (λa. patch_second_derivative X p a b)"
  unfolding patch_second_derivative_def
  by (rule linear_frechet_derivative, rule patch_direction_differentiable[OF p])

lemma second_derivative_coordinates_right:
  assumes p: "p ∈ U"
  shows "patch_second_derivative X p a b =
    b$1 *R patch_second_derivative X p a (axis 1 1) +
    b$2 *R patch_second_derivative X p a (axis 2 1)"
proof -
  have b: "b = b$1 *R axis 1 1 + b$2 *R axis 2 1"
    by (simp add: vec_eq_iff forall_2 axis_def)
  have lin: "linear (λb. patch_second_derivative X p a b)"
    unfolding patch_second_derivative_symmetric[OF p, where a=a]
    by (rule second_derivative_linear_left[OF p])
  show ?thesis using linear_add[OF lin, of "b$1 *R axis 1 1" "b$2 *R axis 2 1"]
    by (simp add: linear_scale[OF lin] flip: b)
qed

end

context regular_surface_patch
begin

lemma second_form_coordinates_right:
  assumes p: "p ∈ U"
  shows "second_fundamental_form X p a b =
    b$1 * second_fundamental_form X p a (axis 1 1) +
    b$2 * second_fundamental_form X p a (axis 2 1)"
  unfolding second_fundamental_form_def[folded patch_second_derivative_def]
  by (subst second_derivative_coordinates_right[OF p], simp add: inner_add_left)

lemma second_form_coordinates:
  assumes p: "p ∈ U"
  shows "second_fundamental_form X p a b =
    a$1*b$1 * second_fundamental_form X p (axis 1 1) (axis 1 1) +
    a$1*b$2 * second_fundamental_form X p (axis 1 1) (axis 2 1) +
    a$2*b$1 * second_fundamental_form X p (axis 2 1) (axis 1 1) +
    a$2*b$2 * second_fundamental_form X p (axis 2 1) (axis 2 1)"
proof -
  have left: "second_fundamental_form X p a c =
    a$1 * second_fundamental_form X p (axis 1 1) c +
    a$2 * second_fundamental_form X p (axis 2 1) c" for c
    using second_form_coordinates_right[OF p, where a=c and b=a]
    by (simp add: second_fundamental_form_symmetric[OF p])
  show ?thesis
    by (subst second_form_coordinates_right[OF p], unfold left,
      simp add: algebra_simps)
qed

lemma second_form_gram_determinant:
  assumes p: "p ∈ U"
  shows "second_fundamental_form X p u u * second_fundamental_form X p v v -
    second_fundamental_form X p u v * second_fundamental_form X p v u =
    (u$1 * v$2 - u$2 * v$1)^2 *
    (second_fundamental_form X p (axis 1 1) (axis 1 1) *
     second_fundamental_form X p (axis 2 1) (axis 2 1) -
     second_fundamental_form X p (axis 1 1) (axis 2 1) *
     second_fundamental_form X p (axis 2 1) (axis 1 1))"
  unfolding second_form_coordinates[OF p, where a=u and b=u]
    second_form_coordinates[OF p, where a=v and b=v]
    second_form_coordinates[OF p, where a=u and b=v]
    second_form_coordinates[OF p, where a=v and b=u]
  by (simp add: algebra_simps power2_eq_square)

end

subsection ‹The metric determines Gaussian curvature›

text ‹Equality of metrics holds on an open domain, so their derivatives agree
  there as well. The metric formula determines the connection uniquely;
  the two Gauss equations therefore have equal intrinsic sides.›

locale same_surface_metric = X: regular_surface_patch U X + Y: regular_surface_patch U Y
  for U X Y +
  assumes same_metric: "⋀p a b. p ∈ U ⟹
    first_fundamental_form X p a b = first_fundamental_form Y p a b"
begin

lemma metric_derivatives_equal:
  assumes p: "p ∈ U"
  shows "frechet_derivative (λq. first_fundamental_form X q a b) (at p) =
    frechet_derivative (λq. first_fundamental_form Y q a b) (at p)"
  using Y.open_domain p same_metric by (meson frechet_derivative_transform_within_open)

lemma connections_equal:
  assumes p: "p ∈ U"
  shows "patch_connection X p a b = patch_connection Y p a b"
proof -
  have paired: "first_fundamental_form X p (patch_connection X p a b) c =
    first_fundamental_form X p (patch_connection Y p a b) c" for c
    using X.connection_metric_formula[OF p, of a b c]
      Y.connection_metric_formula[OF p, of a b c]
    unfolding metric_derivatives_equal[OF p] same_metric[OF p] by linarith
  let ?v = "patch_connection X p a b - patch_connection Y p a b"
  have zero: "first_fundamental_form X p ?v ?v = 0"
    using paired[of ?v] X.patch_derivative_linear[OF p]
    unfolding first_fundamental_form_def
    by (simp add: linear_diff inner_diff_left)
  show ?thesis using X.metric_positive_definite[OF p, of ?v] zero by auto
qed

lemma lower_connections_equal:
  assumes p: "p ∈ U"
  shows "lower_connection X p a b c = lower_connection Y p a b c"
  unfolding X.lower_connection_metric[OF p] Y.lower_connection_metric[OF p]
    connections_equal[OF p] same_metric[OF p] by rule

lemma lower_connection_derivatives_equal:
  assumes p: "p ∈ U"
  shows "frechet_derivative (λq. lower_connection X q a b c) (at p) =
    frechet_derivative (λq. lower_connection Y q a b c) (at p)"
  by (intro frechet_derivative_transform_within_open[OF X.open_domain p] lower_connections_equal)

theorem gaussian_curvature_equal:
  assumes p: "p ∈ U"
  shows "gaussian_curvature X p = gaussian_curvature Y p"
proof -
  have determinants:
    "second_fundamental_form X p (axis 2 1) (axis 2 1) *
      second_fundamental_form X p (axis 1 1) (axis 1 1) -
      second_fundamental_form X p (axis 1 1) (axis 2 1) *
      second_fundamental_form X p (axis 2 1) (axis 1 1) =
     second_fundamental_form Y p (axis 2 1) (axis 2 1) *
      second_fundamental_form Y p (axis 1 1) (axis 1 1) -
      second_fundamental_form Y p (axis 1 1) (axis 2 1) *
      second_fundamental_form Y p (axis 2 1) (axis 1 1)"
    using X.gauss_equation[OF p, of "axis 2 1" "axis 2 1" "axis 1 1" "axis 1 1"]
      Y.gauss_equation[OF p, of "axis 2 1" "axis 2 1" "axis 1 1" "axis 1 1"]
    unfolding lower_connection_derivatives_equal[OF p] connections_equal[OF p]
      same_metric[OF p] by linarith
  show ?thesis unfolding gaussian_curvature_def same_metric[OF p]
    using determinants by (simp add: mult.commute)
qed

end

subsection ‹Equality on a common neighborhood›

text ‹The two patches may have different parameter domains. Only metric equality
  on a common open neighborhood of the point is needed.›

theorem local_metric_determines_curvature:
  assumes X: "regular_surface_patch U X"
    and Y: "regular_surface_patch V Y"
    and W: "open W" "W ⊆ U" "W ⊆ V" "p ∈ W"
    and metric: "⋀q a b. q ∈ W ⟹
      first_fundamental_form X q a b = first_fundamental_form Y q a b"
  shows "gaussian_curvature X p = gaussian_curvature Y p"
proof -
  interpret X: regular_surface_patch U X by (rule X)
  interpret Y: regular_surface_patch V Y by (rule Y)
  interpret equal: same_surface_metric W X Y
    using X.restrict_patch[OF W(1,2)] Y.restrict_patch[OF W(1,3)] metric
    by (unfold_locales, auto simp: regular_surface_patch_def)
  show ?thesis by (rule equal.gaussian_curvature_equal[OF W(4)])
qed

end