Library NumAnalysis.Algebra.Finite_dim.Finite_dim_AS_aff_span

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 finite affine span in affine spaces.

Description

Some results are only valid when the ring of scalars is commutative, or being ordered, they 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.

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_span_Subset_Facts.

Context {K : Ring}.
Context {V : ModuleSpace K}.
Context {E : AffineSpace V}.

Lemma aff_span_normal :
  ∀ {n} (A : 'E^n) L, sum L = 1 → aff_span A (barycenter L A).
Proof. intros; apply Aff_span, invertible_eq_one; easy. Qed.

Lemma aff_span_eq :
  ∀ {n} (A : 'E^n), aff_span A = baryc_closure (inF^~ A).
Proof.
intros n A; apply subset_ext_equiv; split; intros C HC.
induction HC; apply Barycenter_closure; [easy | apply invalF_refl].
induction HC as [m L C HL HC].
destruct (baryc_injF_ex L C HL) as [p [N [D [HN [HD1 [HD2 ->]]]]]].
clear L HL; apply ((invalF_trans _ D _)^~ HC) in HD2.
destruct (baryc_unfun0F N D A) as [L [HL1 [HL2 ->]]]; easy.
Qed.

Lemma aff_span_inclF_diag : ∀ {n} (A : 'E^n), inclF A (aff_span A).
Proof.
intros n A i; rewrite -baryc_l_kron_r; apply Aff_span.
rewrite kron_sum_r//; apply invertible_one.
Qed.

Lemma aff_span_ub : ∀ {n} (A : 'E^n) C i, C = A i → aff_span A C.
Proof. intros; subst; apply aff_span_inclF_diag. Qed.

Lemma aff_span_incl_equiv :
  ∀ (PE : E → Prop) {n} (A : 'E^n),
    incl PE (aff_span A) ↔
    ∀ G, PE G → ∃ L, sum L = 1 ∧ G = barycenter L A.
Proof.
intros PE n A; split; intros H G HG.
destruct (aff_span_EX (H _ HG)) as [L HL]; ∃ L; easy.
destruct (H _ HG) as [L [HL ->]]; apply Aff_span, invertible_eq_one; easy.
Qed.

Lemma aff_span_nil :
  nonzero_struct K → ∀ (A : 'E^0), aff_span A = emptyset.
Proof.
intros; apply incl_empty; intros G [L HL]; contradict HL; rewrite sum_nil.
apply noninvertible_zero; easy.
Qed.

Lemma aff_span_one :
  ∀ {n} (A : E), aff_span (constF n.+1 A) = singleton A.
Proof.
intros; apply subset_ext_equiv; split.
intros _ [L HL]; apply baryc_constF; easy.
intros G HG; rewrite HG
    -{2}(baryc_constF A (kron (@ord0 n) : 'K^n.+1) (constF n.+1 A))//;
    [apply Aff_span |]; apply invertible_eq_one, kron_sum_r; easy.
Qed.

Lemma aff_span_one_alt :
  ∀ {n} {A : 'E^n.+1} G, (∀ i, A i = G) → aff_span A = singleton G.
Proof.
intros n A G H; replace A with (constF n.+1 G);
    [apply aff_span_one | extF; rewrite constF_correct; easy].
Qed.

Lemma aff_span_inclF :
  ∀ {n1 n2} (A1 : 'E^n1) (A2 : 'E^n2), invalF A1 A2 → inclF A1 (aff_span A2).
Proof.
move=>> HA i; destruct (HA i) as [i2 Hi2]; rewrite Hi2; apply aff_span_inclF_diag.
Qed.

Lemma aff_spanF_ex :
  ∀ {n1 n2} (A1 : 'E^n1) (A2 : 'E^n2),
    inclF A1 (aff_span A2) ↔
    ∃ M12, ∀ i1,
      invertible (sum (M12 i1)) ∧ A1 i1 = barycenter (M12 i1) A2.
Proof.
intros n1 n2 A1 A2; split; intros HA.
assert (HA' : ∀ i1, ∃ L2,
    invertible (sum L2) ∧ A1 i1 = barycenter L2 A2).
  intros i1; destruct (HA i1) as [L2]; ∃ L2; easy.
apply (choiceF _ HA').
intros i1; destruct HA as [M HM], (HM i1) as [HM1a HM1b]; rewrite HM1b; easy.
Qed.

Lemma aff_spanF_ex1 :
  ∀ {n1 n2} (A1 : 'E^n1) (A2 : 'E^n2),
    inclF A1 (aff_span A2) ↔
    ∃ M12, ∀ i1, sum (M12 i1) = 1 ∧ A1 i1 = barycenter (M12 i1) A2.
Proof.
move=>>; rewrite aff_spanF_ex; split; move⇒ [M12 /all_and_equiv [HM12 HA1]].
∃ (fun i1 ⇒ scal (/ sum (M12 i1)) (M12 i1)); intros i1.
apply baryc_normalized; easy.
∃ M12; intros; rewrite HM12; split; [apply invertible_one | easy].
Qed.

Lemma aff_span_monot_inclF :
  ∀ {n1 n2} (A1 : 'E^n1) (A2 : 'E^n2),
    inclF A1 (aff_span A2) → incl (aff_span A1) (aff_span A2).
Proof.
move=>> HA1 _ [L1 HL1]; apply aff_spanF_ex1 in HA1; destruct HA1 as [M HM].
apply all_and_equiv in HM; destruct HM as [HM HA1].
apply aff_span_ex; ∃ (fun i2 ⇒ lin_comb L1 (M^~ i2)); split.
2: apply barycenter2_r; easy.
replace (sum _) with (sum L1); try easy.
rewrite -lc_sum_r (lc_ext_r 1).
rewrite lc_ones_r; easy.
intros i1; rewrite (HM i1); easy.
Qed.

Lemma aff_span_monot_invalF :
  ∀ {n1 n2} (A1 : 'E^n1) (A2 : 'E^n2),
    invalF A1 A2 → incl (aff_span A1) (aff_span A2).
Proof. intros; apply aff_span_monot_inclF, aff_span_inclF; easy. Qed.

Lemma aff_span_ext :
  ∀ {n1 n2} (A1 : 'E^n1) (A2 : 'E^n2),
    inclF A1 (aff_span A2) → inclF A2 (aff_span A1) →
    aff_span A1 = aff_span A2.
Proof.
intros; apply subset_ext_equiv; split; apply aff_span_monot_inclF; easy.
Qed.

Lemma aff_span_inv_frameF_orig :
  ∀ {n} i0 (O : E) (B : 'V^n), aff_span (inv_frameF i0 O B) O.
Proof.
intros n i0 O B; rewrite -{2}(transl_zero O); apply (aff_span_ub _ _ i0).
unfold inv_frameF; rewrite translF_insertF insertF_correct_l; easy.
Qed.

Lemma aff_span_exs :
  ∀ {n1 n2} {A2 : 'E^n2} {G1 : 'E^n1},
    inclF G1 (aff_span A2) →
    ∃ L, (∀ i, sum (L i) = 1) ∧ G1 = fun i ⇒ barycenter (L i) A2.
Proof.
move⇒ n1 n2 A2 G1 HG1.
destruct (choiceF (fun i L ⇒ sum L = 1 ∧ G1 i = barycenter L A2)) as [L HL].
  intros i; destruct (aff_span_EX (HG1 i)) as [L HL]; ∃ L; easy.
apply all_and_equiv in HL; ∃ L; split; try apply extF; easy.
Qed.

End Affine_span_Subset_Facts.

Section Affine_span_Affine_Facts.

Context {K : Ring}.
Context {V : ModuleSpace K}.
Context {E : AffineSpace V}.

Context {n : nat}.
Variable A : 'E^n.

Lemma aff_span_decomp_ex : baryc_surjL (aff_span A) A.
Proof. move=>> HG; eexists (baryc_coord _ _); apply bc_correct; easy. Qed.

Lemma aff_span_lb :
  ∀ {PE}, compatible_as PE → inclF A PE → incl (aff_span A) PE.
Proof. intros PE HPE HA B [L HL]; apply HPE; easy. Qed.

End Affine_span_Affine_Facts.

Section Affine_combination_L_Facts.

Properties of baryc_surjL, baryc_injL and baryc_bijL.

Context {K : Ring}.
Context {V : ModuleSpace K}.
Context {E : AffineSpace V}.
Variable PE : E → Prop.

Context {n : nat}.
Variable A : 'E^n.

Lemma baryc_surjL_injL_bijL :
  baryc_surjL PE A → baryc_injL A → baryc_bijL PE A.
Proof.
intros HA1 HA2 B HB; destruct (HA1 _ HB) as [L HL].
∃ L; split; [| intros L' [HL' ->]; apply HA2]; easy.
Qed.

Lemma baryc_bijL_surjL : baryc_bijL PE A → baryc_surjL PE A.
Proof. intros HA B HB; destruct (HA _ HB) as [L [HL _]]; ∃ L; easy. Qed.

Lemma baryc_bijL_injL :
  compatible_as PE → inclF A PE → baryc_bijL PE A → baryc_injL A.
Proof.
intros HPE HA1 HA2 L L' HL HL' H;
    destruct (HA2 (barycenter L A)) as [LB [_ HLB]].
apply HPE; [apply invertible_eq_one |]; easy.
apply trans_eq with LB; [symmetry |]; apply HLB; easy.
Qed.

End Affine_combination_L_Facts.

Section Affine_span_R_Facts.

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

Lemma aff_span_cas : ∀ {n} (A : 'E^n), compatible_as (aff_span A).
Proof.
intros; apply cas_equiv, eq_sym; rewrite aff_span_eq.
apply baryc_closure_idem_R.
Qed.

Lemma aff_span_equiv : ∀ {n} (A : 'E^n), aff_span A = span_as (inF^~ A).
Proof.
intros n A; apply subset_ext_equiv; split.
intros _ [L HL]; apply span_as_cas; [easy| ].
intros i; apply span_as_incl; ∃ i; easy.
apply span_as_lub; [apply aff_span_cas |].
intros x [i Hi]; rewrite Hi; apply aff_span_inclF_diag.
Qed.

Lemma aff_span_glb :
  ∀ {n} (A : 'E^n),
    aff_span A = (fun B ⇒ ∀ PE, compatible_as PE → inclF A PE → PE B).
Proof.
intros; apply subset_ext_equiv; split.
intros _ [L HL] PE HPE1 HPE2; apply HPE1; easy.
intros B HB; apply HB; [apply aff_span_cas | apply aff_span_inclF_diag].
Qed.

Lemma lin_span_aff_span_aux :
  ∀ {n} i0 {O} {A : 'E^n.+1}, aff_span A O →
    lin_span (frameF i0 A) = vectP (aff_span A) O.
Proof.
intros n i0 O A HO; rewrite (vectP_orig_indep (A i0) HO).
2: { apply cas_cms_equiv_R; try apply aff_span_inclF_diag.
    move=>> HL HC; apply aff_span_cas; easy. }
apply eq_sym, subset_ext_equiv; split; unfold vectP, preimage; intros u Hu.
apply aff_span_EX in Hu; destruct Hu as [L [HL1 HL2]].
rewrite (baryc_orig_equiv (A i0)) in HL2; [| apply invertible_eq_one; easy].
rewrite transl_correct_r HL1 scal_one in HL2; rewrite HL2.
unfold frameF; rewrite vectF_skipF (lc_skipF i0)
    vectF_correct vect_zero scal_zero_r plus_zero_l; easy.
induction Hu as [L]; unfold frameF; rewrite vectF_skipF (transl_lc i0).
rewrite translF_skipF translF_vectF insertF_skipF.
apply Aff_span, invertible_eq_one, sum_insertF_baryc.
Qed.

Lemma lin_span_aff_span :
  ∀ {n} i0 (O : E) {u : 'V^n},
    lin_span u = vectP (aff_span (inv_frameF i0 O u)) O.
Proof.
intros; rewrite -(lin_span_aff_span_aux i0).
rewrite frameF_inv_frameF; easy.
apply aff_span_inv_frameF_orig.
Qed.

Lemma aff_span_lin_span :
  ∀ {n} i0 {O} {A : 'E^n.+1}, aff_span A O →
    aff_span A = translP (lin_span (frameF i0 A)) O.
Proof.
intros n i0 O A HO; apply (vectP_inj O).
rewrite vectP_translP (lin_span_aff_span i0 (A i0)) inv_frameF_frameF.
apply vectP_orig_indep; [easy | apply cas_cms].
apply aff_span_inclF_diag.
apply invertible_equiv_R, two_not_zero_R.
apply aff_span_cas.
Qed.

End Affine_span_R_Facts.

Section ModuleSpace_AffineSpace_R_Facts.

Context {E : ModuleSpace R_Ring}.

Lemma aff_span_ext_ms :
  ∀ {n1 n2} (A1 : 'E^n1) (A2 : 'E^n2),
    inclF A1 (aff_span_ms A2) → inclF A2 (aff_span_ms A1) →
    aff_span_ms A1 = aff_span_ms A2.
Proof. move=>>; apply aff_span_ext. Qed.

Lemma lin_span_aff_span_ms :
  ∀ {n} i0 O {u : 'E^n}, lin_span u =
    fun v ⇒ aff_span_ms (constF n.+1 O + insert0F i0 u) (O + v).
Proof.
intros; rewrite -inv_frameF_ms_eq -vectP_ms_eq; apply lin_span_aff_span.
Qed.

Lemma aff_span_lin_span_ms :
  ∀ {n} i0 {O} {A : 'E^n.+1}, aff_span_ms A O →
    aff_span_ms A = fun B ⇒ lin_span (skipF i0 A - constF n (A i0)) (B - O).
Proof.
intros; rewrite -frameF_ms_eq -translP_ms_eq; apply aff_span_lin_span; easy.
Qed.

End ModuleSpace_AffineSpace_R_Facts.