Library NumAnalysis.FEM.geom_transf_affine

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.

Bibliography

[Ern] Alexandre Ern, Éléments finis, Aide-mémoire, Dunod/L'Usine Nouvelle, 2005, https://www.dunod.com/sciences-techniques/aide-memoire-elements-finis.
[RR9557v1] François Clément and Vincent Martin, Finite element method. Detailed proofs to be formalized in Coq, RR-9557, first version, Inria Paris, 2024, https://inria.hal.science/hal-04713897v1.

From NumAnalysis Require Import stdlib_wR ssr_wMC.

From Coquelicot Require Import Hierarchy.
Close Scope R_scope.

From NumAnalysis Require Import Algebra_wDep.
From NumAnalysis Require Import geometry multi_index poly_Pdk poly_LagPd1_ref.

Local Open Scope R_scope. Local Open Scope Monoid_scope.
Local Open Scope Group_scope.
Local Open Scope Ring_scope.

Section T_geom_Facts1.

Context {d : nat}.
Variable vtx : [0..d] → 'R^d.

[Ern] Eq (3.23), p. 58.
[RR9557v1] Def 1547, p. 82.
Definition T_geom : 'R^d → 'R^d :=
  fun x_ref ⇒ barycenter_ms (LagPd1_ref^~ x_ref) vtx.

Lemma T_geom_lc :
  ∀ x_ref, T_geom x_ref = lin_comb (LagPd1_ref^~ x_ref) vtx.
Proof. intro; rewrite -baryc_ms_eq//; apply LagPd1_ref_sum. Qed.

[RR9557v1] Lem 1550, p. 83.
Lemma T_geom_am : aff_map_ms T_geom.
Proof.
apply am_lm_0, lm_ext
    with (fun x ⇒ lin_comb (LagPd1_ref^~ x - LagPd1_ref^~ 0) vtx).
intros; rewrite lc_minus_l fct_minus_eq !T_geom_lc; easy.
apply fct_lc_l_lm; intro; apply: am_lm_0_rev; apply LagPd1_ref_am.
Qed.

[RR9557v1] Lem 1550, Eq (9.39), p. 83.
Lemma T_geom_vtx : ∀ i, T_geom (vtx_ref i) = vtx i.
Proof.
intro; unfold T_geom;
    rewrite LagPd1_ref_kron_vtxF baryc_ms_correct baryc_l_kron_r; easy.
Qed.

Lemma T_geom_vtxF : mapF T_geom vtx_ref = vtx.
Proof. extF; apply T_geom_vtx. Qed.

Lemma T_geom_baryc :
  ∀ L, sum L = 1 →
    T_geom (barycenter_ms L vtx_ref) = barycenter_ms L vtx.
Proof.
move=>> HL; rewrite T_geom_am; [rewrite T_geom_vtxF; easy |].
rewrite HL; apply invertible_one.
Qed.

End T_geom_Facts1.

Section T_geom_ref_Facts.

Context {d : nat}.

[RR9557v1] Lem 1549, p. 82.
Lemma T_geom_ref :
  ∀ vtx, vtx = vtx_ref → T_geom vtx = (id : 'R^d → 'R^d).
Proof.
intros; subst; apply: am_ext_vtx_ref;
    [apply T_geom_am | easy | apply T_geom_vtx].
Qed.

Lemma T_geom_scal_ref :
  ∀ a vtx, invertible a → vtx = vtx_ref →
    @T_geom d (mapF (scal a) vtx) = scal a.
Proof.
intros; fun_ext; rewrite T_geom_lc lc_scal_r -T_geom_lc T_geom_ref; easy.
Qed.

End T_geom_ref_Facts.

Section T_geom_f_Facts2.

Context {d : nat}.

Lemma T_geom_inj_l : injective (@T_geom d).
Proof. move⇒ v1 v2 H; extF; rewrite -(T_geom_vtx v1) H T_geom_vtx; easy. Qed.

Lemma T_geom_comp :
  ∀ (vtx1 vtx2 : [0..d] → 'R^d),
    T_geom vtx1 \o T_geom vtx2 = T_geom (mapF (T_geom vtx1) vtx2).
Proof.
intros; apply: am_ext_vtx_ref; [apply comp_am_ms |..]; [apply T_geom_am.. |].
intro; rewrite comp_correct !T_geom_vtx; easy.
Qed.

End T_geom_f_Facts2.

Section T_geom_inv_Facts.

Context {d : nat}.
Context {vtx : [0..d] → 'R^d}.
Hypothesis Hvtx : aff_indep_ms vtx.

Lemma T_geom_inj : injective (T_geom vtx).
Proof.
move=>> /(aff_indep_decomp_uniq Hvtx
    _ _ (LagPd1_ref_sum _) (LagPd1_ref_sum _)); apply LagPd1_ref_inj.
Qed.

Lemma T_geom_surj : surjective (T_geom vtx).
Proof.
intros x; destruct (aff_indep_aff_gen_R _ has_dim_Rn Hvtx x) as [L [HL ->]],
    (LagPd1_ref_surjS L HL) as [x_ref [_ <-]]; ∃ x_ref; easy.
Qed.

[RR9557v1] Lem 1550, pp. 83-84.
Lemma T_geom_bij : bijective (T_geom vtx).
Proof. apply bij_equiv; split; [apply T_geom_inj | apply T_geom_surj]. Qed.

[RR9557v1] Lem 1550, p. 83.
Definition T_geom_inv : 'R^d → 'R^d := f_inv T_geom_bij.

Lemma T_geom_inv_id_l : T_geom_inv \o (T_geom vtx) = id.
Proof. apply f_inv_id_l. Qed.

Lemma T_geom_inv_id_r : T_geom vtx \o T_geom_inv = id.
Proof. apply f_inv_id_r. Qed.

Lemma T_geom_inv_can_l : cancel (T_geom vtx) T_geom_inv.
Proof. apply f_inv_can_l. Qed.

Lemma T_geom_inv_can_r : cancel T_geom_inv (T_geom vtx).
Proof. apply f_inv_can_r. Qed.

Lemma T_geom_inv_am : aff_map_ms T_geom_inv.
Proof. apply: am_bij_compat; apply T_geom_am. Qed.

Lemma T_geom_inv_vtxF : mapF T_geom_inv vtx = vtx_ref.
Proof. rewrite -(T_geom_vtxF vtx) -mapF_comp T_geom_inv_id_l; easy. Qed.

[RR9557v1] Lem 1550, Eq (9.42), p. 83.
Lemma T_geom_inv_vtx : ∀ i, T_geom_inv (vtx i) = vtx_ref i.
Proof. intro; rewrite -T_geom_inv_vtxF; easy. Qed.

Lemma T_geom_inv_baryc :
  ∀ L, sum L = 1 →
    T_geom_inv (barycenter_ms L vtx) = barycenter_ms L vtx_ref.
Proof.
intros; apply T_geom_inj; rewrite T_geom_inv_can_r T_geom_baryc; easy.
Qed.

Let K_geom_ref : 'R^d → Prop := convex_hull vtx_ref.
Let K_geom : 'R^d → Prop := convex_hull vtx.

Lemma T_geom_K_geom_incl : incl K_geom_ref (preimage (T_geom vtx) K_geom).
Proof.
move=>> [L HL1 HL2]; unfold K_geom, preimage; rewrite T_geom_baryc; easy.
Qed.

Lemma T_geom_inv_K_geom_incl : incl K_geom (preimage T_geom_inv K_geom_ref).
Proof.
move=>> [L HL1 HL2]; unfold K_geom, preimage; rewrite T_geom_inv_baryc; easy.
Qed.

[RR9557v1] Lem 1550, Eq (9.40), pp. 83-84.
Lemma T_geom_K_geom_eq : image (T_geom vtx) K_geom_ref = K_geom.
Proof.
apply subset_ext_equiv; split; [apply image_incl_equiv, T_geom_K_geom_incl |
    rewrite -(f_inv_preimage T_geom_bij); apply T_geom_inv_K_geom_incl].
Qed.

Lemma T_geom_inv_K_geom_eq : image T_geom_inv (K_geom) = K_geom_ref.
Proof.
rewrite -T_geom_K_geom_eq -image_comp T_geom_inv_id_l image_id; easy.
Qed.

Lemma T_geom_bijS_K_geom_spec :
  bijS_spec K_geom_ref K_geom (T_geom vtx) T_geom_inv.
Proof.
repeat split.
intros _ [x_ref H]; apply T_geom_K_geom_incl; easy.
intros _ [x H]; apply T_geom_inv_K_geom_incl; easy.
intros x_ref _; apply T_geom_inv_can_l.
intros x _; apply T_geom_inv_can_r.
Qed.

Lemma T_geom_bijS_K_geom : bijS K_geom_ref K_geom (T_geom vtx).
Proof. apply (BijS _ T_geom_bijS_K_geom_spec). Qed.

End T_geom_inv_Facts.

Section T_geom_inv_ref_Facts.

Context {d : nat}.

Lemma T_geom_inv_ref :
  ∀ vtx (H : aff_indep_ms vtx),
    vtx = vtx_ref → T_geom_inv H = (id : 'R^d → 'R^d).
Proof. intros; subst; apply f_inv_is_id, T_geom_ref; easy. Qed.

End T_geom_inv_ref_Facts.

Section T_geom_permutF_Def.

Context {d : nat}.
Variable vtx : [0..d] → 'R^d.

pi_d is a permutation of 0..d. The intention is to switch vertices.
Variable pi_d : [0..d] → [0..d].

[RR9557v1] Lem 1586, p. 96.
See also Def 1578, p. 92.
Definition T_geom_permutF : 'R^d → 'R^d := T_geom (permutF pi_d vtx).

End T_geom_permutF_Def.

Section T_geom_permutF_Facts.

Context {d : nat}.
Context {vtx : [0..d] → 'R^d}.
Hypothesis Hvtx : aff_indep_ms vtx.

Context {pi_d : [0..d] → [0..d]}.
Hypothesis Hpi_d : injective pi_d.
Let pi_d_bij := injF_bij Hpi_d.
Let pi_d_inv := f_inv pi_d_bij.
Let pi_d_inv_bij := f_inv_bij pi_d_bij.
Let pi_d_inv_inj := f_inv_inj pi_d_bij.

[RR9557v1] Lem 1586, p. 96.
[RR9557v1] Lem 1586, p. 96.
Lemma T_geom_permutF_am : aff_map_ms (T_geom_permutF vtx pi_d).
Proof. apply T_geom_am. Qed.

Lemma T_geom_permutF_inv_am : aff_map_ms T_geom_permutF_inv.
Proof. apply: am_bij_compat T_geom_permutF_am. Qed.

Lemma T_geom_permutF_Pdk :
  ∀ k p, Pdk d k p → Pdk d k (p \o T_geom_permutF vtx pi_d).
Proof. intros; apply Pdk_pullback_am; [apply T_geom_permutF_am |]; easy. Qed.

Lemma T_geom_permutF_inv_Pdk :
  ∀ k p, Pdk d k p → Pdk d k (p \o T_geom_permutF_inv).
Proof. intros; apply Pdk_pullback_am; [apply T_geom_permutF_inv_am | easy]. Qed.

[RR9557v1] Lem 1586, Eq (9.75), pp. 96-97.
Lemma T_geom_permutF_eq :
  ∀ x_ref,
    T_geom_permutF vtx pi_d x_ref =
      barycenter_ms (permutF pi_d_inv (LagPd1_ref^~ x_ref)) vtx.
Proof.
intro; unfold T_geom_permutF, T_geom;
    rewrite !baryc_ms_correct baryc_permutF_r//;
    rewrite LagPd1_ref_sum; apply invertible_one.
Qed.

Lemma T_geom_permutF_skipF :
  ∀ i j,
    T_geom_permutF vtx pi_d (skipF i vtx_ref j) =
      T_geom vtx (skipF (pi_d i) vtx_ref (skip_f_ord Hpi_d i j)).
Proof.
intros; unfold T_geom_permutF; rewrite !T_geom_vtx skip_f_ord_correct; easy.
Qed.

End T_geom_permutF_Facts.

Section T_geom_transpF_Def.

Context {d : nat}.
Variable vtx : [0..d] → 'R^d.

Definition T_geom_transpF (i0 : [0..d]) : 'R^d → 'R^d :=
  T_geom_permutF vtx (transp_ord ord_max i0).

End T_geom_transpF_Def.

Section T_geom_transpF_Facts.

Context {d : nat}.
Context {vtx : [0..d] → 'R^d}.
Hypothesis Hvtx : aff_indep_ms vtx.

Definition T_geom_transpF_inv (i0 : [0..d]) : 'R^d → 'R^d :=
  T_geom_permutF_inv Hvtx (transp_ord_inj ord_max i0).

End T_geom_transpF_Facts.

Section inj_Hface_Facts.

We need a dimension which is structurally nonzero. We take d = d1.+1 with d1 : nat.
Context {d1 : nat}.
Let d := d1.+1.
Variable vtx : [0..d] → 'R^d.

[RR9557v1] Def 1578, p. 92
(with l=d-1=d1 and pi_l = theta^d_i (i>0) from Lem 1368, p. 41,
and with theta^d_i j = j if j < i, and j+1 otherwise).
Definition inj_Hface (i : [0..d]) : 'R^d1 → 'R^d :=
  T_geom vtx \o inj_Hface_ref i.

[RR9557v1] Lem 1584, pp. 94-95.
Lemma inj_Hface_am : ∀ i, aff_map_ms (inj_Hface i).
Proof.
intro; apply comp_am_ms; [apply inj_Hface_ref_am | apply T_geom_am].
Qed.

[RR9557v1] Lem 1585, p. 95.
Lemma inj_Hface_comp :
  ∀ i k p, Pdk d k p → Pdk d1 k (p \o inj_Hface i).
Proof. intros; apply Pdk_pullback_am; [apply inj_Hface_am | easy]. Qed.

End inj_Hface_Facts.