Theory Surface_Isometry_Calculus

theory Surface_Isometry_Calculus
  imports Surface_Reparametrization
begin

section ‹Composition and inverse charts›

lemma parameter_jacobian_matrix:
  "parameter_jacobian f p = matrix_det (matrix (frechet_derivative f (at p)))"
  by (simp add: parameter_jacobian_def det_2 matrix_def mult.commute)

lemma parameter_jacobian_compose:
  assumes f: "f differentiable at p" and g: "g differentiable at (f p)"
  shows "parameter_jacobian (g ∘ f) p =
    parameter_jacobian g (f p) * parameter_jacobian f p"
proof -
  have lin: "linear (frechet_derivative g (at (f p)))"
    using g unfolding frechet_derivative_works
    by (meson bounded_linear.linear has_derivative_bounded_linear)
  have lin_f: "linear (frechet_derivative f (at p))"
    using f unfolding frechet_derivative_works
    by (meson bounded_linear.linear has_derivative_bounded_linear)
  show ?thesis
    unfolding parameter_jacobian_matrix frechet_derivative_compose[OF f g]
    by (simp add: matrix_compose[OF lin_f lin] det_mul)
qed

lemma derivative_inverse_chart:
  assumes domain_open: "open V" and q: "q ∈ V"
    and g: "g differentiable at q" and f: "f differentiable at (g q)"
    and inverse: "⋀y. y ∈ V ⟹ f (g y) = y"
  shows "frechet_derivative f (at (g q)) (frechet_derivative g (at q) a) = a"
proof -
  have comp: "((f ∘ g) has_derivative
    (frechet_derivative f (at (g q)) ∘ frechet_derivative g (at q))) (at q)"
    using diff_chain_at[of g _ q f] f g unfolding frechet_derivative_works by blast
  have ident: "((f ∘ g) has_derivative id) (at q)"
    by (rule has_derivative_transform_within_open[OF has_derivative_id domain_open q],
      simp add: inverse)
  show ?thesis using fun_cong[OF has_derivative_unique[OF comp ident], where x=a] by simp
qed

context surface_coordinate_change
begin

lemma compose_coordinate_change:
  assumes target_change: "surface_coordinate_change W Z V g"
  shows "surface_coordinate_change W Z U (g ∘ f)"
proof -
  interpret target_change: surface_coordinate_change W Z V g by (rule target_change)
  show ?thesis
  proof
    show "open U" by (rule open_source)
    show "3-smooth_on U (g ∘ f)"
      by (rule smooth_on_compose[OF target_change.smooth_change smooth_change open_source
        Y.open_domain maps_into])
    show "(g ∘ f) ` U ⊆ W" using maps_into target_change.maps_into by auto
    show "parameter_jacobian (g ∘ f) p ≠ 0" if p: "p ∈ U" for p
      by (simp add: parameter_jacobian_compose[OF change_differentiable[OF p]
        target_change.change_differentiable[OF target_point[OF p]]]
        nonsingular[OF p] target_change.nonsingular[OF target_point[OF p]])
  qed
qed

text ‹A smooth right inverse on an open target domain is itself a coordinate
change. The parameter domains can be restrictions of larger charts.›

lemma inverse_coordinate_change:
  assumes X: "regular_surface_patch U X"
    and smooth: "3-smooth_on V g" and into: "g ` V ⊆ U"
    and inverse: "⋀q. q ∈ V ⟹ f (g q) = q"
  shows "surface_coordinate_change U X V g"
proof -
  have diff: "g differentiable at q" if "q ∈ V" for q
    using smooth_on_imp_differentiable_on[OF smooth] Y.open_domain that
    by (simp add: differentiable_on_eq_differentiable_at)
  have nonzero: "parameter_jacobian g q ≠ 0" if q: "q ∈ V" for q
  proof -
    have gp: "g q ∈ U" using into q by auto
    have lin: "linear (frechet_derivative g (at q))"
      using diff[OF q] unfolding frechet_derivative_works
      by (meson bounded_linear.linear has_derivative_bounded_linear)
    have inj: "inj (frechet_derivative g (at q))"
      by (rule injI, metis derivative_inverse_chart[OF Y.open_domain q diff[OF q]
        change_differentiable[OF gp] inverse])
    show ?thesis using det_nz_iff_inj[OF lin] inj
      by (simp add: parameter_jacobian_matrix)
  qed
  show ?thesis using X Y.open_domain smooth into nonzero
    by (unfold_locales, auto simp: regular_surface_patch_def)
qed

end

context surface_coordinate_change
begin

text ‹A change of parameters is a local isometry from the pullback
  immersion to the original immersion. This connects coordinate-change
  examples directly to the common isometry interface.›

lemma pullback_local_isometry:
  "surface_local_isometry U (Y ∘ f) V Y f"
  using composite_regular Y.regular_surface_patch_axioms smooth_change maps_into
    metric_pullback
  by (unfold_locales, auto simp: regular_surface_patch_def)

end

context regular_surface_patch
begin

lemma identity_local_isometry:
  "surface_local_isometry U X U X id"
  by unfold_locales (auto simp: id_def intro: smooth_on_id)

end

context surface_local_isometry
begin

lemma restrict_local_isometry:
  assumes source_open: "open A" and source_subset: "A ⊆ U"
    and target_open: "open B" and target_subset: "B ⊆ V"
    and into: "f ` A ⊆ B"
  shows "surface_local_isometry A X B Y f"
proof -
  have source: "regular_surface_patch A X"
    by (rule X.restrict_patch[OF source_open source_subset])
  have target: "regular_surface_patch B Y"
    by (rule Y.restrict_patch[OF target_open target_subset])
  have smooth: "3-smooth_on A f"
    by (rule smooth_on_subset[OF smooth_map source_subset])
  show ?thesis using source target smooth into preserves_metric source_subset
    by (unfold_locales, auto simp: regular_surface_patch_def)
qed

lemma compose_local_isometry:
  assumes target_change: "surface_local_isometry V Y W Z g"
  shows "surface_local_isometry U X W Z (g ∘ f)"
proof -
  interpret target_change: surface_local_isometry V Y W Z g by (rule target_change)
  have smooth: "3-smooth_on U (g ∘ f)"
    by (rule smooth_on_compose[OF target_change.smooth_map smooth_map X.open_domain
      Y.open_domain maps_into])
  have into: "(g ∘ f) ` U ⊆ W" using maps_into target_change.maps_into by auto
  have metric: "first_fundamental_form X p a b = first_fundamental_form Z ((g ∘ f) p)
    (frechet_derivative (g ∘ f) (at p) a)
    (frechet_derivative (g ∘ f) (at p) b)" if p: "p ∈ U" for p a b
    by (simp add: preserves_metric[OF p] target_change.preserves_metric[OF change.target_point[OF p]]
      frechet_derivative_compose[OF map_differentiable[OF p]
        target_change.map_differentiable[OF change.target_point[OF p]]])
  show ?thesis using X.regular_surface_patch_axioms target_change.Y.regular_surface_patch_axioms
    smooth into metric by (unfold_locales, auto simp: regular_surface_patch_def)
qed

lemma inverse_local_isometry:
  assumes smooth: "3-smooth_on V g" and into: "g ` V ⊆ U"
    and inverse: "⋀q. q ∈ V ⟹ f (g q) = q"
  shows "surface_local_isometry V Y U X g"
proof -
  have diff: "g differentiable at q" if "q ∈ V" for q
    using smooth_on_imp_differentiable_on[OF smooth] Y.open_domain that
    by (simp add: differentiable_on_eq_differentiable_at)
  have metric: "first_fundamental_form Y q a b = first_fundamental_form X (g q)
    (frechet_derivative g (at q) a) (frechet_derivative g (at q) b)"
    if q: "q ∈ V" for q a b
  proof -
    have gp: "g q ∈ U" using into q by auto
    show ?thesis
      by (simp add: preserves_metric[OF gp] inverse[OF q]
        derivative_inverse_chart[OF Y.open_domain q diff[OF q] map_differentiable[OF gp] inverse])
  qed
  show ?thesis using Y.regular_surface_patch_axioms X.regular_surface_patch_axioms
    smooth into metric by (unfold_locales, auto simp: regular_surface_patch_def)
qed

end
end