Theory Spherical_Patches

theory Spherical_Patches
  imports Sphere_Surface
begin

section ‹Arbitrary regular patches on spheres›

context regular_surface_patch
begin

lemma normal_line_characterization:
  assumes p: "p ∈ U"
    and orth: "⋀a. inner w (patch_derivative X p a) = 0"
  shows "w = inner w (gauss_map X p) *R gauss_map X p"
proof -
  let ?N = "gauss_map X p"
  let ?t = "w - inner w ?N *R ?N"
  have unit: "inner ?N ?N = 1" using gauss_map_unit[OF p]
    by (simp add: dot_square_norm)
  have nt: "inner ?N ?t = 0"
    by (simp add: inner_diff_right unit inner_commute)
  have tangent: "?t ∈ tangent_plane X p"
    using tangent_plane_normal_kernel[OF p] nt by simp
  obtain a where a: "?t = patch_derivative X p a"
    using tangent unfolding tangent_plane_def by auto
  have wt: "inner w ?t = 0" unfolding a by (rule orth)
  have "inner ?t ?t = 0" by (simp add: inner_diff_left wt nt)
  then show ?thesis by simp
qed

end

locale sphere_radius_patch = regular_surface_patch U X for U X +
  fixes center :: surface_vector and radius :: real
  assumes positive_radius: "0 < radius"
    and on_sphere: "p ∈ U ⟹ norm (X p - center) = radius"
begin

lemma position_orthogonal:
  assumes p: "p ∈ U"
  shows "inner (X p - center) (patch_derivative X p a) = 0"
proof -
  have original: "(X has_derivative patch_derivative X p) (at p)"
    using immersion_differentiable[OF p] unfolding patch_derivative_def frechet_derivative_works .
  have dx: "((λq. X q - center) has_derivative patch_derivative X p) (at p)"
    using has_derivative_diff[OF original has_derivative_const[of center]] by simp
  have prod: "((λq. inner (X q - center) (X q - center)) has_derivative
    (λh. inner (X p - center) (patch_derivative X p h) + inner (patch_derivative X p h) (X p - center))) (at p)"
    by (rule bounded_bilinear.FDERIV[OF bounded_bilinear_inner dx dx])
  have zero: "((λq. inner (X q - center) (X q - center)) has_derivative (λh. 0)) (at p)"
    by (rule has_derivative_transform_within_open[OF has_derivative_const open_domain p],
      simp add: dot_square_norm on_sphere)
  show ?thesis using fun_cong[OF has_derivative_unique[OF prod zero], where x=a]
    by (simp add: inner_commute)
qed

lemma position_normal:
  assumes p: "p ∈ U"
  shows "X p - center = inner (X p - center) (gauss_map X p) *R gauss_map X p"
  by (rule normal_line_characterization[OF p position_orthogonal[OF p]])

lemma position_orientation_square:
  assumes p: "p ∈ U"
  shows "inner (X p - center) (gauss_map X p)^2 = radius^2"
proof -
  have "radius = abs (inner (X p - center) (gauss_map X p))"
    using arg_cong[OF position_normal[OF p], of norm]
    by (simp add: on_sphere[OF p] gauss_map_unit[OF p])
  then show ?thesis by (metis power2_abs)
qed

lemma position_second_derivative:
  assumes p: "p ∈ U"
  shows "inner (X p - center) (patch_second_derivative X p a b) = -first_fundamental_form X p a b"
proof -
  have original: "(X has_derivative patch_derivative X p) (at p)"
    using immersion_differentiable[OF p] unfolding patch_derivative_def frechet_derivative_works .
  have dx: "((λq. X q - center) has_derivative patch_derivative X p) (at p)"
    using has_derivative_diff[OF original has_derivative_const[of center]] by simp
  have dv: "((λq. patch_derivative X q b) has_derivative
    (λh. patch_second_derivative X p h b)) (at p)"
    using patch_direction_differentiable[OF p, of b]
    unfolding patch_second_derivative_def frechet_derivative_works .
  have prod: "((λq. inner (X q - center) (patch_derivative X q b)) has_derivative
    (λh. inner (X p - center) (patch_second_derivative X p h b) +
      inner (patch_derivative X p h) (patch_derivative X p b))) (at p)"
    by (rule bounded_bilinear.FDERIV[OF bounded_bilinear_inner dx dv])
  have zero: "((λq. inner (X q - center) (patch_derivative X q b)) has_derivative (λh. 0)) (at p)"
    by (rule has_derivative_transform_within_open[OF has_derivative_const open_domain p],
      simp add: position_orthogonal)
  show ?thesis using fun_cong[OF has_derivative_unique[OF prod zero], where x=a]
    unfolding first_fundamental_form_def by linarith
qed

lemma position_orientation_nonzero:
  assumes p: "p ∈ U"
  shows "inner (X p - center) (gauss_map X p) ≠ 0"
  using position_orientation_square[OF p] positive_radius by auto

lemma spherical_second_form:
  assumes p: "p ∈ U"
  shows "second_fundamental_form X p a b =
    -inverse (inner (X p - center) (gauss_map X p)) * first_fundamental_form X p a b"
proof -
  let ?s = "inner (X p - center) (gauss_map X p)"
  have eq: "?s * second_fundamental_form X p a b = -first_fundamental_form X p a b"
    using position_second_derivative[OF p, of a b]
    by (subst (asm) position_normal[OF p],
      simp add: second_fundamental_form_def[folded patch_second_derivative_def] inner_commute)
  show ?thesis using eq position_orientation_nonzero[OF p]
    by (simp add: field_simps)
qed

theorem spherical_curvature:
  assumes p: "p ∈ U"
  shows "gaussian_curvature X p = 1 / radius^2"
proof -
  let ?I = "first_fundamental_form X p"
  let ?B = "second_fundamental_form X p"
  let ?s = "inner (X p - center) (gauss_map X p)"
  let ?e = "axis 1 1 :: surface_parameter"
  let ?f = "axis 2 1 :: surface_parameter"
  let ?d = "?I ?e ?e * ?I ?f ?f - (?I ?e ?f)^2"
  have num: "?B ?e ?e * ?B ?f ?f - ?B ?e ?f * ?B ?f ?e = inverse (radius^2) * ?d"
  proof -
    have "?B ?e ?e * ?B ?f ?f - ?B ?e ?f * ?B ?f ?e = (inverse ?s)^2 * ?d"
      unfolding spherical_second_form[OF p]
      by (simp add: first_fundamental_form_symmetric algebra_simps power2_eq_square)
    then show ?thesis by (simp add: power_inverse position_orientation_square[OF p])
  qed
  have "?d ≠ 0" using metric_determinant_positive[OF p] by linarith
  then show ?thesis unfolding gaussian_curvature_def num by (simp add: divide_inverse)
qed

theorem no_local_isometry_to_plane:
  assumes "U ≠ {}"
  shows "¬ surface_local_isometry U X V plane_patch f"
proof
  assume iso: "surface_local_isometry U X V plane_patch f"
  interpret iso: surface_local_isometry U X V plane_patch f by (rule iso)
  obtain p where p: "p ∈ U" using assms by blast
  show False using iso.theorema_egregium[OF p] spherical_curvature[OF p]
    plane_curvature positive_radius by simp
qed

theorem no_local_isometry_different_radii:
  assumes nonempty: "U ≠ {}"
    and target: "sphere_radius_patch V Y other_center other_radius"
    and different: "radius ≠ other_radius"
  shows "¬ surface_local_isometry U X V Y f"
proof
  assume iso: "surface_local_isometry U X V Y f"
  interpret iso: surface_local_isometry U X V Y f by (rule iso)
  interpret target: sphere_radius_patch V Y other_center other_radius by (rule target)
  obtain p where p: "p ∈ U" using nonempty by blast
  have eq: "1 / radius^2 = 1 / other_radius^2"
    using iso.theorema_egregium[OF p] spherical_curvature[OF p]
      target.spherical_curvature[OF iso.change.target_point[OF p]] by simp
  have "radius^2 = other_radius^2" using eq by (simp add: divide_inverse)
  then show False using positive_radius target.positive_radius different by (simp add: power2_eq_iff)
qed

end

text ‹The unit sphere is the centered radius-one specialization.›

locale spherical_patch = regular_surface_patch U X for U X +
  assumes on_sphere: "p ∈ U ⟹ norm (X p) = 1"
begin

sublocale sphere: sphere_radius_patch U X 0 1
  by unfold_locales (auto simp: on_sphere)

lemmas position_orthogonal = sphere.position_orthogonal[simplified]
lemmas position_normal = sphere.position_normal[simplified]
lemmas position_orientation_unit = sphere.position_orientation_square[simplified]
lemmas position_second_derivative = sphere.position_second_derivative[simplified]

lemma spherical_second_form:
  assumes p: "p ∈ U"
  shows "second_fundamental_form X p a b =
    -inner (X p) (gauss_map X p) * first_fundamental_form X p a b"
proof -
  let ?s = "inner (X p) (gauss_map X p)"
  have eq: "?s * second_fundamental_form X p a b = -first_fundamental_form X p a b"
    using position_second_derivative[OF p, of a b]
    by (subst (asm) position_normal[OF p],
      simp add: second_fundamental_form_def[folded patch_second_derivative_def] inner_commute)
  have "second_fundamental_form X p a b = ?s * (?s * second_fundamental_form X p a b)"
    using position_orientation_unit[OF p] by (simp add: power2_eq_square mult.assoc[symmetric])
  then show ?thesis by (simp add: eq)
qed

theorem spherical_curvature:
  "p ∈ U ⟹ gaussian_curvature X p = 1"
  using sphere.spherical_curvature by simp

lemmas no_local_isometry_to_plane = sphere.no_local_isometry_to_plane

end
end