Library NumAnalysis.Algebra.Finite_dim.Finite_dim_AS_aff_map

This file is part of the Rocq Numerical Analysis library
Copyright (C) Boldo, Clément, Martin, Mayero, Mouhcine
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the COPYING file for more details.

Brief description

Support for affine maps in finite-dimensional affine spaces.

Description

Results that are only valid when the ring of scalars is commutative, or being ordered, are only stated in the case of the ring of real numbers R_Ring.

Usage

This module may be used through the import of NumAnalysis.Algebra.Finite_dim.Finite_dim_AS, NumAnalysis.Algebra.Finite_dim.Finite_dim, NumAnalysis.Algebra.Algebra, NumAnalysis.Algebra.Algebra_wDep, NumAnalysis.LM.LM_wDep, or NumAnalysis.FEM.FEM_wDep, where it is exported.

From NumAnalysis Require Import ssr_wMC.

From Coquelicot Require Import Hierarchy.
Close Scope R_scope.

From NumAnalysis Require Import Subsets_wDep.
From NumAnalysis Require Import Hierarchy_compl.
From NumAnalysis Require Import Monoid Group Ring ModuleSpace AffineSpace.
From NumAnalysis Require Import Finite_dim_MS Finite_dim_AS_def.
From NumAnalysis Require Import Finite_dim_AS_aff_span Finite_dim_AS_aff_gen.
From NumAnalysis Require Import Finite_dim_AS_aff_indep Finite_dim_AS_aff_basis.

Local Open Scope Monoid_scope.
Local Open Scope Group_scope.
Local Open Scope Ring_scope.
Local Open Scope ModuleSpace_scope.
Local Open Scope AffineSpace_scope.

Section Affine_mapping_Facts.

Context {K : Ring}.
Context {V1 V2 : ModuleSpace K}.
Context {E1 : AffineSpace V1}.
Context {E2 : AffineSpace V2}.
Context {PE1 : E1 → Prop}.
Hypothesis HPE1 : compatible_as PE1.

Context {f : E1 → E2}.

Lemma am_normal :
  (∀ {n} L (A1 : 'E1^n),
    sum L = 1 → f (barycenter L A1) = barycenter L (mapF f A1)) → aff_map f.
Proof.
intros Hf n L A1 HL.
assert (HL' : invertible (/ sum L)) by now apply inv_invertible.
rewrite !(baryc_homogeneous _ HL' HL); apply Hf.
rewrite -scal_sum_r; apply mult_inv_l; easy.
Qed.

Lemma am_normal_rev :
  aff_map f → ∀ {n} L (A1 : 'E1^n),
    sum L = 1 → f (barycenter L A1) = barycenter L (mapF f A1).
Proof. move⇒ Hf =>> HL; apply Hf, invertible_eq_one; easy. Qed.

Lemma am_normal_equiv :
  aff_map f ↔ ∀ {n} L (A1 : 'E1^n),
    sum L = 1 → f (barycenter L A1) = barycenter L (mapF f A1).
Proof. split; [apply am_normal_rev | apply am_normal]. Qed.

End Affine_mapping_Facts.

Section Affine_mapping_Baryc_coord_R_Facts.

Context {V : ModuleSpace R_Ring}.
Context {E : AffineSpace V}.

Context {n : nat}.
Context {A : 'E^n.+1}.
Hypothesis HA : aff_indep A.

Lemma baryc_bc_sum :
  ∀ {p} L (B : 'E^p), sum L = 1 → inclF B (aff_span A) →
    sum (barycenter_ms L (mapF (baryc_coord A) B)) = 1.
Proof.
intros p L B HL HB; rewrite baryc_ms_eq// -lc_sum_r_alt (lc_ext_r 1);
    [rewrite lc_ones_r | intro; rewrite mapF_correct; apply bc_correct]; easy.
Qed.

Lemma baryc_bc_baryc :
  ∀ {p} L (B : 'E^p), sum L = 1 → inclF B (aff_span A) →
    barycenter (barycenter_ms L (mapF (baryc_coord A) B)) A = barycenter L B.
Proof.
intros p L B HL HB; rewrite baryc_ms_eq// -(barycenter2_r_alt _ _ B)//.
apply invertible_eq_one; easy.
1,2: intro; rewrite mapF_correct; apply bc_correct; easy.
Qed.

Lemma bc_amS :
  ∀ {p} L (B : 'E^p), sum L = 1 → inclF B (aff_span A) →
    baryc_coord A (barycenter L B) = barycenter_ms L (mapF (baryc_coord A) B).
Proof.
intros; apply eq_sym, bc_uniq;
    [| apply aff_span_cas; [apply invertible_eq_one |] |
    apply baryc_bc_sum | apply baryc_bc_baryc]; easy.
Qed.

Lemma bc_am :
  full (aff_span A) → aff_map (baryc_coord A : E → fct_ModuleSpace _ _).
Proof. intro; apply am_normal; move=>> HL; apply bc_amS; easy. Qed.

End Affine_mapping_Baryc_coord_R_Facts.

Section Affine_mapping_R_Facts0a.

Context {V1 V2 : ModuleSpace R_Ring}.
Context {E1 : AffineSpace V1}.
Context {E2 : AffineSpace V2}.

Context {f g : E1 → E2}.
Hypothesis Hf : aff_map f.
Hypothesis Hg : aff_map g.

Context {n : nat}.
Variable A1 : 'E1^n.+1.

Lemma am_ext_span :
  (∀ i, f (A1 i) = g (A1 i)) →
  ∀ x1, aff_span A1 x1 → f x1 = g x1.
Proof.
intros H x1 [L HL]; rewrite Hf// Hg//; apply baryc_eq_r;
    extF; rewrite mapF_correct; easy.
Qed.

End Affine_mapping_R_Facts0a.

Section Affine_mapping_R_Facts0b.

Context {V1 V2 : ModuleSpace R_Ring}.
Context {E1 : AffineSpace V1}.
Context {E2 : AffineSpace V2}.

Context {f g : E1 → E2}.
Hypothesis Hf : aff_map f.
Hypothesis Hg : aff_map g.

Context {n : nat}.
Context {A1 : 'E1^n.+1}.
Hypothesis HA1 : aff_gen fullset A1.

Lemma am_ext_gen_full : (∀ i, f (A1 i) = g (A1 i)) → f = g.
Proof.
intro; fun_ext; apply (am_ext_span Hf Hg A1); [| rewrite -HA1]; easy.
Qed.

End Affine_mapping_R_Facts0b.

Section Affine_mapping_R_Facts1a.

Context {V1 V2 : ModuleSpace R_Ring}.
Context {E1 : AffineSpace V1}.
Context {E2 : AffineSpace V2}.
Context {PE1 : E1 → Prop}.
Hypothesis HPE1 : compatible_as PE1.

Context {f : E1 → E2}.
Hypothesis Hf : aff_map f.

Lemma am_aff_span :
  ∀ {n} (A1 : 'E1^n), image f (aff_span A1) = aff_span (mapF f A1).
Proof.
intros; apply subset_ext_equiv; split.
apply aff_span_incl_equiv; intros _ [B1 HB1].
destruct (aff_span_EX HB1) as [L [HL ->]]; ∃ L; split;
    [| apply Hf, invertible_eq_one]; easy.
apply aff_span_lb; [apply (image_cas (aff_span_cas _) Hf) |
    apply mapF_inclF, aff_span_inclF_diag].
Qed.

Lemma am_aff_gen :
  ∀ {n} {A1 : 'E1^n}, inclF A1 PE1 →
    aff_gen PE1 A1 → aff_gen (image f PE1) (mapF f A1).
Proof. move=>> HA1 ->; rewrite am_aff_span. easy. Qed.

Hypothesis Hf1 : injS PE1 f.

Lemma am_aff_indep_injS :
  ∀ {n} {A1 : 'E1^n.+1}, inclF A1 PE1 →
    aff_indep A1 → aff_indep (mapF f A1).
Proof.
move=>> HA1; rewrite !aff_indep_decomp_uniq_equiv; intros H1 L L' HL HL' H.
assert (HLa : invertible (sum L)) by now apply invertible_eq_one.
assert (HL'a : invertible (sum L')) by now apply invertible_eq_one.
apply H1; [easy.. |].
apply Hf1; [apply HPE1; easy.. |].
rewrite !Hf//.
Qed.

Lemma am_aff_dep_injS :
  ∀ {n} {A1 : 'E1^n.+1}, inclF A1 PE1 →
    aff_dep (mapF f A1) → aff_dep A1.
Proof. move=>> HA1; rewrite -contra_equiv; apply am_aff_indep_injS; easy. Qed.

Lemma am_aff_basis_injS :
  ∀ {n} {A1 : 'E1^n.+1}, inclF A1 PE1 →
    aff_basis PE1 A1 → aff_basis (image f PE1) (mapF f A1).
Proof.
move=>> H1 [H2 H3]; split; [apply am_aff_gen | apply am_aff_indep_injS]; easy.
Qed.

Lemma am_has_aff_dim_injS :
  ∀ {n}, has_aff_dim PE1 n → has_aff_dim (image f PE1) n.
Proof.
intros n [A HA]; apply (Aff_dim _ _ (mapF f A)), am_aff_basis_injS;
    [apply aff_gen_inclF, HA | easy].
Qed.

End Affine_mapping_R_Facts1a.

Section Affine_mapping_R_Facts1b.

Context {V1 V2 : ModuleSpace R_Ring}.
Context {E1 : AffineSpace V1}.
Context {E2 : AffineSpace V2}.

Context {f : E1 → E2}.
Hypothesis Hf : aff_map f.
Hypothesis Hf1 : injective f.

Lemma am_aff_indep :
  ∀ {n} {A1 : 'E1^n.+1}, aff_indep A1 → aff_indep (mapF f A1).
Proof.
move=>>; apply (am_aff_indep_injS cas_fullset); [| apply inj_injS |]; easy.
Qed.

Lemma am_aff_dep :
  ∀ {n} {A1 : 'E1^n.+1}, aff_dep (mapF f A1) → aff_dep A1.
Proof. move=>>; rewrite -contra_equiv; apply am_aff_indep; easy. Qed.

Lemma am_aff_basis :
  ∀ {n} {A1 : 'E1^n.+1},
    aff_basis fullset A1 → aff_basis (Rg f) (mapF f A1).
Proof.
move=>> [H1 H2]; split; [apply am_aff_gen | apply am_aff_indep]; easy.
Qed.

Lemma am_has_aff_dim :
  ∀ {n}, has_aff_dim (@fullset E1) n → has_aff_dim (Rg f) n.
Proof.
intro; apply (am_has_aff_dim_injS cas_fullset); [| apply inj_injS]; easy.
Qed.

End Affine_mapping_R_Facts1b.

Section Affine_mapping_R_Facts2a.

Context {V1 V2 : ModuleSpace R_Ring}.
Context {E1 : AffineSpace V1}.
Context {E2 : AffineSpace V2}.
Context {PE1 : E1 → Prop}.
Hypothesis HPE1 : compatible_as PE1.

Context {f : E1 → E2}.
Hypothesis Hf : aff_map f.
Hypothesis Hf1 : injS PE1 f.
Hypothesis Hf2' : bijective f.
Let fm1 := f_inv Hf2'.
Let Hfm1 : aff_map fm1.
Proof. apply am_bij_compat; easy. Qed.
Let Hfm1a : canS PE1 f fm1.
Proof. intros x _; unfold fm1; rewrite f_inv_can_l; easy. Qed.
Let HPE2 : compatible_as (preimage fm1 PE1).
Proof. apply cas_preimage; easy. Qed.

Lemma am_aff_gen_rev :
  ∀ {n} {A1 : 'E1^n},
    inclF A1 PE1 → aff_gen (image f PE1) (mapF f A1) → aff_gen PE1 A1.
Proof.
intros n A1 HA1; replace A1 with (mapF id A1) at 2 by easy.
rewrite -{2}(image_invol_canS Hfm1a) -(f_inv_id_l Hf2') mapF_comp.
apply am_aff_gen; [apply am_bij_compat | apply image_inclF]; easy.
Qed.

Lemma am_aff_gen_equiv :
  ∀ {n} {A1 : 'E1^n},
    inclF A1 PE1 → aff_gen (image f PE1) (mapF f A1) ↔ aff_gen PE1 A1.
Proof. intros; split; [apply am_aff_gen_rev | apply am_aff_gen]; easy. Qed.

Lemma am_aff_indep_injS_rev :
  ∀ {n} {A1 : 'E1^n.+1}, inclF A1 PE1 →
    aff_indep (mapF f A1) → aff_indep A1.
Proof.
intros n A1 HA1; replace A1 with (mapF id A1) at 2 by easy.
rewrite -(f_inv_id_l Hf2') mapF_comp;
    apply (am_aff_indep_injS HPE2); [easy |..].
apply inj_injS, f_inv_inj.
rewrite f_inv_preimage; apply image_inclF; easy.
Qed.

Lemma am_aff_indep_injS_equiv :
  ∀ {n} {A1 : 'E1^n.+1},
    inclF A1 PE1 → aff_indep (mapF f A1) ↔ aff_indep A1.
Proof.
intros; split; [apply am_aff_indep_injS_rev |
    apply (am_aff_indep_injS HPE1)]; easy.
Qed.

Lemma am_aff_dep_injS_rev :
  ∀ {n} {A1 : 'E1^n.+1},
    inclF A1 PE1 → aff_dep A1 → aff_dep (mapF f A1).
Proof.
move=>> HA1; rewrite -contra_equiv; apply am_aff_indep_injS_rev; easy.
Qed.

Lemma am_aff_dep_injS_equiv :
  ∀ {n} {A1 : 'E1^n.+1},
    inclF A1 PE1 → aff_dep (mapF f A1) ↔ aff_dep A1.
Proof.
intros; split; [apply (am_aff_dep_injS HPE1) |
    apply am_aff_dep_injS_rev]; easy.
Qed.

Lemma am_aff_basis_injS_rev :
  ∀ {n} {A1 : 'E1^n.+1}, inclF A1 PE1 →
    aff_basis (image f PE1) (mapF f A1) → aff_basis PE1 A1.
Proof.
move=>> HA1; apply modus_ponens_and;
    [apply am_aff_gen_rev | apply am_aff_indep_injS_rev]; easy.
Qed.

Lemma am_aff_basis_injS_equiv :
  ∀ {n} {A1 : 'E1^n.+1}, inclF A1 PE1 →
    aff_basis (image f PE1) (mapF f A1) ↔ aff_basis PE1 A1.
Proof.
intros; split; [apply am_aff_basis_injS_rev | apply am_aff_basis_injS]; easy.
Qed.

Lemma am_has_aff_dim_injS_rev :
  ∀ {n}, has_aff_dim (image f PE1) n → has_aff_dim PE1 n.
Proof.
intros n [A1 HA1]; apply Aff_dim with (mapF fm1 A1), am_aff_basis_injS_rev.
rewrite -(image_invol_canS Hfm1a); rewrite f_inv_image.
apply preimage_inclF, aff_basis_inclF; easy.
rewrite -mapF_comp f_inv_id_r; easy.
Qed.

Lemma am_has_aff_dim_injS_equiv :
  ∀ {n}, has_aff_dim (image f PE1) n ↔ has_aff_dim PE1 n.
Proof.
intros; split; [apply am_has_aff_dim_injS_rev |
    apply am_has_aff_dim_injS]; easy.
Qed.

End Affine_mapping_R_Facts2a.

Section Affine_mapping_R_Facts2b.

Context {V1 V2 : ModuleSpace R_Ring}.
Context {E1 : AffineSpace V1}.
Context {E2 : AffineSpace V2}.

Context {f : E1 → E2}.
Hypothesis Hf : aff_map f.
Hypothesis Hf1 : bijective f.
Let Hf1' := bij_inj Hf1.
Let fm1 := f_inv Hf1.
Let Hfm1 : aff_map fm1.
Proof. apply am_bij_compat; easy. Qed.
Let HPE2 : compatible_as (preimage fm1 fullset).
Proof. apply cas_preimage; easy. Qed.

Lemma am_aff_indep_rev :
  ∀ {n} {A1 : 'E1^n.+1}, aff_indep (mapF f A1) → aff_indep A1.
Proof. move=>>; apply (am_aff_indep_injS_rev cas_fullset); easy. Qed.

Lemma am_aff_indep_equiv :
  ∀ {n} {A1 : 'E1^n.+1}, aff_indep (mapF f A1) ↔ aff_indep A1.
Proof. intros; split; [apply am_aff_indep_rev | apply am_aff_indep]; easy. Qed.

Lemma am_aff_dep_rev :
  ∀ {n} {A1 : 'E1^n.+1}, aff_dep A1 → aff_dep (mapF f A1).
Proof. move=>>; rewrite -contra_equiv; apply am_aff_indep_rev; easy. Qed.

Lemma am_aff_dep_equiv :
  ∀ {n} {A1 : 'E1^n.+1}, aff_dep (mapF f A1) ↔ aff_dep A1.
Proof. intros; split; [apply am_aff_dep | apply am_aff_dep_rev]; easy. Qed.

Lemma am_aff_basis_rev :
  ∀ {n} {A1 : 'E1^n.+1},
    aff_basis (Rg f) (mapF f A1) → aff_basis fullset A1.
Proof.
move=>>; apply modus_ponens_and;
    [apply am_aff_gen_rev | apply am_aff_indep_rev]; easy.
Qed.

Lemma am_aff_basis_equiv :
  ∀ {n} {A1 : 'E1^n.+1},
    aff_basis (Rg f) (mapF f A1) ↔ aff_basis fullset A1.
Proof. intros; split; [apply am_aff_basis_rev | apply am_aff_basis]; easy. Qed.

Lemma am_has_aff_dim_rev :
  ∀ {n}, has_aff_dim (Rg f) n → has_aff_dim (@fullset E1) n.
Proof. intro; apply (am_has_aff_dim_injS_rev cas_fullset); easy. Qed.

Lemma am_has_aff_dim_equiv :
  ∀ {n}, has_aff_dim (Rg f) n ↔ has_aff_dim (@fullset E1) n.
Proof.
intros; split; [apply am_has_aff_dim_rev | apply am_has_aff_dim]; easy.
Qed.

End Affine_mapping_R_Facts2b.

Section ModuleSpace_AffineSpace_Affine_mapping_R_Facts1.

Context {E : ModuleSpace R_Ring}.

Context {n : nat}.
Context {A : 'E^n.+1}.
Hypothesis HA : aff_indep A.

Lemma bc_am_ms : full (aff_span_ms A) → aff_map_ms (baryc_coord_ms A).
Proof. apply bc_am; easy. Qed.

End ModuleSpace_AffineSpace_Affine_mapping_R_Facts1.

Section ModuleSpace_AffineSpace_Affine_mapping_R_Facts2.

Context {E1 E2 : ModuleSpace R_Ring}.

Context {f g : E1 → E2}.
Hypothesis Hf : aff_map f.
Hypothesis Hg : aff_map g.

Context {n : nat}.
Variable A1 : 'E1^n.+1.

Lemma am_ext_span_ms :
  (∀ i, f (A1 i) = g (A1 i)) →
  ∀ x1, aff_span A1 x1 → f x1 = g x1.
Proof. apply am_ext_span; easy. Qed.

Hypothesis HA1 : aff_gen fullset A1.

Lemma am_ext_gen_full_ms : (∀ i, f (A1 i) = g (A1 i)) → f = g.
Proof. apply am_ext_gen_full; easy. Qed.

Lemma am_aff_span_ms :
  ∀ {n} (A1 : 'E1^n), image f (aff_span_ms A1) = aff_span_ms (mapF f A1).
Proof. apply am_aff_span; easy. Qed.

Hypothesis Hf1 : injective f.

Lemma am_aff_indep_ms :
  ∀ {n} {A1 : 'E1^n.+1}, aff_indep A1 → aff_indep (mapF f A1).
Proof. apply am_aff_indep; easy. Qed.

Lemma am_aff_basis_ms :
  ∀ {n} {A1 : 'E1^n.+1},
    aff_basis fullset A1 → aff_basis (Rg f) (mapF f A1).
Proof. apply am_aff_basis; easy. Qed.

Lemma am_has_aff_dim_ms :
  ∀ {n}, has_aff_dim (@fullset E1) n → has_aff_dim (Rg f) n.
Proof. apply am_has_aff_dim; easy. Qed.

End ModuleSpace_AffineSpace_Affine_mapping_R_Facts2.