Library NumAnalysis.FEM.poly_LagPd1

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

[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.FEM Require Import R_compl geometry multi_index poly_Pdk.
From NumAnalysis Require Import poly_LagPd1_ref geom_transf_affine.

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

Section LagPd1_Facts.

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

[RR9557v1] Lem 1552, p. 84.
Definition LagPd1 (i : [0..d]) : FRd d :=
  fun x ⇒ LagPd1_ref i (T_geom_inv Hvtx x).

Lemma LagPd1_eq : ∀ i, LagPd1 i = LagPd1_ref i \o (T_geom_inv Hvtx).
Proof. easy. Qed.

Lemma LagPd1_0 :
  ∀ i, i = ord0 → LagPd1 i = fun x ⇒ 1 - sum (T_geom_inv Hvtx x).
Proof. intros; rewrite LagPd1_eq LagPd1_ref_0; easy. Qed.

Lemma LagPd1_S :
  ∀ {i} (Hi : i ≠ ord0),
    LagPd1 i = fun x ⇒ T_geom_inv Hvtx x (lower_S Hi).
Proof. intros; rewrite LagPd1_eq LagPd1_ref_S; easy. Qed.

[RR9557v1] Lem 1560, p. 87.
Lemma LagPd1_S_eq : ∀ x, liftF_S (LagPd1^~ x) = T_geom_inv Hvtx x.
Proof.
intro; extF; unfold liftF_S.
rewrite (LagPd1_S (lift_S_not_first _)) lower_lift_S; easy.
Qed.

[RR9557v1] Lem 1560, Eq (9.52), p. 87.
Lemma LagPd1_S_can_l : ∀ x, liftF_S (LagPd1^~ (T_geom vtx x)) = x.
Proof. intro; rewrite LagPd1_S_eq; apply T_geom_inv_can_l. Qed.

[RR9557v1] Lem 1560, Eq (9.52), p. 87.
Lemma LagPd1_S_can_r : ∀ x, T_geom vtx (liftF_S (LagPd1^~ x)) = x.
Proof. intro; rewrite LagPd1_S_eq; apply T_geom_inv_can_r. Qed.

[RR9557v1] Lem 1554, Eq (9.46), p. 85.
Lemma LagPd1_sum : ∀ x, sum (LagPd1^~ x) = 1.
Proof. intros; apply LagPd1_ref_sum. Qed.

Lemma LagPd1_barycF : ∀ x, barycenter_ms (LagPd1^~ x) vtx = x.
Proof. intro; unfold LagPd1; rewrite -LagPd1_S_eq; apply LagPd1_S_can_r. Qed.

[RR9557v1] Lem 1560, p. 87.
LagPd1 are the barycentric coordinates wrt vtx.
Lemma LagPd1_bcF : ∀ x, LagPd1^~ x = baryc_coord_ms vtx x.
Proof.
intros; apply bc_uniq; [easy | | apply LagPd1_sum | apply LagPd1_barycF].
rewrite -(T_geom_vtxF vtx) -(am_aff_span (T_geom_am _)) -vtx_ref_aff_gen.
rewrite Rg_is_full//; apply T_geom_surj; easy.
Qed.

Lemma LagPd1_am : ∀ i, aff_map_ms (LagPd1 i).
Proof.
intro; apply comp_am_ms; [apply T_geom_inv_am | apply LagPd1_ref_am].
Qed.

[RR9557v1] Lem 1554, Eq (9.45), p. 85.
Lemma LagPd1_kron_vtx : ∀ i, LagPd1^~ (vtx i) = kron i.
Proof. intro; rewrite -LagPd1_ref_kron_vtxF -(T_geom_inv_vtx Hvtx); easy. Qed.

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

Lemma LagPd1_ge_0 : ∀ i x, K_geom x → 0 ≤ LagPd1 i x.
Proof. move=>> H; apply LagPd1_ref_ge_0, T_geom_inv_K_geom_incl; easy. Qed.

Lemma LagPd1_le_1 : ∀ i x, K_geom x → LagPd1 i x ≤ 1.
Proof. move=>> H; apply LagPd1_ref_le_1, T_geom_inv_K_geom_incl; easy. Qed.

[RR9557v1] Lem 1560, p. 87.
LagPd1 are the barycentric coordinates wrt vtx.
Lemma LagPd1_baryc : ∀ x, barycenter_ms (LagPd1^~ x) vtx = x.
Proof.
intros x; rewrite -{2}(LagPd1_S_can_r x); unfold T_geom; rewrite LagPd1_S_eq//.
Qed.

Lemma LagPd1_is_Pd1 : inclF LagPd1 (Pdk d 1).
Proof.
intro; rewrite LagPd1_eq; apply Pdk_pullback_am;
    [apply T_geom_inv_am | apply LagPd1_ref_is_Pd1].
Qed.

Lemma LagPd1_lin_indep : lin_indep LagPd1.
Proof.
intros L HL; extF; rewrite -lc_r_kron_r.
rewrite -LagPd1_kron_vtx -fct_lc_r_eq HL; easy.
Qed.

[RR9557v1] Lem 1554, p. 85.
Lemma LagPd1_basis : basis (Pdk d 1) LagPd1.
Proof.
apply lin_indep_basis;
    [apply Pd1_has_dim | apply LagPd1_is_Pd1 | apply LagPd1_lin_indep].
Qed.

[RR9557v1] Lem 1555, p. 85.
Lemma LagPd1_decomp_vtx :
  ∀ {p}, Pdk d 1 p → p = lin_comb (mapF p vtx) LagPd1.
Proof.
intros p Hp; destruct (basis_decomp_ex LagPd1_basis p Hp) as [L ->].
apply lc_ext_l; intro; rewrite mapF_correct fct_lc_r_eq LagPd1_kron_vtx.
apply eq_sym, lc_r_kron_r.
Qed.

End LagPd1_Facts.

Section Face_hyperplane_Def.

Context {d : nat}.

[RR9557v1] Lem 1565, pp. 89-90.
Note that Hface vtx i is the face hyperplane opposite vertex v_i.
Definition Hface (vtx : [0..d] → 'R^d) (i : [0..d]) : 'R^d → Prop :=
  image (T_geom vtx) (Hface_ref i).

Lemma Hface_aff_span : ∀ vtx i, Hface vtx i = aff_span_ms (skipF i vtx).
Proof.
intros; unfold Hface, Hface_ref; rewrite am_aff_span_ms; [| apply T_geom_am].
rewrite mapF_skipF T_geom_vtxF; easy.
Qed.

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

[RR9557v1] Lem 1563, Eq (9.57), pp. 88-89.
Lemma Hface_is_Ker : ∀ i, Hface vtx i = Ker (LagPd1 Hvtx i).
Proof.
intro; unfold Hface;
    rewrite LagPd1_eq Ker_comp Hface_ref_is_Ker f_inv_preimage; easy.
Qed.

Lemma Hface_equiv : ∀ i x, Hface vtx i x ↔ LagPd1 Hvtx i x = 0.
Proof. intros; rewrite Hface_is_Ker; apply Ker_equiv. Qed.

End Face_hyperplane_Def.

Section Face_hyperplane_Facts.

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

Lemma T_geom_Hface_incl :
  ∀ i, incl (Hface_ref i) (preimage (T_geom vtx) (Hface vtx i)).
Proof. easy. Qed.

Lemma T_geom_inv_Hface_incl :
  ∀ i, incl (Hface vtx i) (preimage (T_geom_inv Hvtx) (Hface_ref i)).
Proof. intro; rewrite f_inv_preimage; easy. Qed.

Lemma T_geom_bijS_Hface_spec :
  ∀ i,
    bijS_spec (Hface_ref i) (Hface vtx i) (T_geom vtx) (T_geom_inv Hvtx).
Proof.
intro; repeat split.
intros _ [x_ref H]; apply T_geom_Hface_incl; easy.
intros _ [x H]; apply T_geom_inv_Hface_incl; easy.
intros x_ref _; apply T_geom_inv_can_l.
intros x _; apply T_geom_inv_can_r.
Qed.

Lemma T_geom_bijS_Hface :
  ∀ i, bijS (Hface_ref i) (Hface vtx i) (T_geom vtx).
Proof. intro; apply (BijS _ (T_geom_bijS_Hface_spec _)). Qed.

End Face_hyperplane_Facts.

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, Eq (9.77), pp. 96-97.
Lemma LagPd1_eq_permutF :
  ∀ i, LagPd1 Hvtx i =
    permutF pi_d_inv LagPd1_ref i \o T_geom_permutF_inv Hvtx Hpi_d.
Proof.
intros i; fun_ext x; move: i; apply extF_rev.
apply (aff_indep_decomp_uniq Hvtx); [apply LagPd1_sum |..]; unfold comp.
rewrite -fct_sum_eq sum_permutF// LagPd1_ref_sum_f; easy.
rewrite -baryc_ms_correct LagPd1_baryc
    -{1}(T_geom_permutF_inv_can_r Hvtx Hpi_d x) T_geom_permutF_eq; easy.
Qed.

[RR9557v1] Lem 1586, Eq (9.78), pp. 96-97.
Lemma T_geom_permutF_Hface :
  ∀ i, image (T_geom_permutF vtx pi_d) (Hface_ref i) = Hface vtx (pi_d i).
Proof.
intros i; unfold Hface; rewrite !am_aff_span_ms;
    [| apply T_geom_am | apply T_geom_permutF_am].
apply aff_span_ext_ms; apply aff_span_inclF; intros j.
∃ (skip_f_ord Hpi_d i j);
    rewrite !mapF_correct; apply T_geom_permutF_skipF.
∃ (skip_f_ord pi_d_inv_inj (pi_d i) j);
    rewrite !mapF_correct T_geom_permutF_skipF.
do 2 f_equal; rewrite -{1}(f_inv_can_l pi_d_bij i).
rewrite -skip_f_ord_comp_alt skip_f_ord_id// f_inv_id_r; easy.
Qed.

End T_geom_permutF_Facts.

Section T_geom_transpF_Facts.

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

Lemma LagPd1_eq_transpF :
  ∀ i0 j, LagPd1 Hvtx j =
    transpF ord_max i0 LagPd1_ref j \o T_geom_transpF_inv Hvtx i0.
Proof.
intros i0 j.
rewrite transpF_sym (LagPd1_eq_permutF Hvtx (transp_ord_inj ord_max i0)).
rewrite (transp_ord_inv ord_max i0); easy.
Qed.

Lemma T_geom_transpF_Hface :
  ∀ i0, image (T_geom_transpF vtx i0) (Hface_ref ord_max) = Hface vtx i0.
Proof.
intros i0; assert (H0 : transp_ord ord_max i0 ord_max = i0)
    by now apply transp_ord_correct_l0.
rewrite -{2}H0; apply T_geom_permutF_Hface, transp_ord_inj; easy.
Qed.

End T_geom_transpF_Facts.

Section Pdk_Facts.

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

[RR9557v1] Lem 1623, direct way, p. 105
(with the transposition instead of the circular permutation, see Rem 1622, p. 105.
Lemma factor_zero_on_Hface :
  ∀ {p} i, Pdk d k.+1 p →
    (∀ x, Hface vtx i x → p x = 0) →
    ∃ q, Pdk d k q ∧ p = LagPd1 Hvtx i × q.
Proof.
intros p i Hp1 Hp2; pose (p_ref := p \o T_geom_transpF vtx i).
assert (H0 : p = p_ref \o T_geom_transpF_inv Hvtx i)
    by now unfold p_ref; rewrite -comp_assoc f_inv_id_r comp_id_r.
assert (H1 : Pdk d k.+1 p_ref) by now apply T_geom_permutF_Pdk.
assert (H2 : ∀ x_ref, Hface_ref ord_max x_ref → p_ref x_ref = 0).
    intros x_ref Hx; unfold p_ref; apply Hp2.
    rewrite -(T_geom_transpF_Hface i); easy.
apply (factor_zero_on_last_Hface_ref Hd H1) in H2;
    destruct H2 as [q_ref [Hq1 Hq2]].
∃ (q_ref \o T_geom_transpF_inv Hvtx i); split.
apply T_geom_permutF_inv_Pdk; easy.
rewrite (LagPd1_eq_transpF _ i) transpF_correct_l1//
    -pullback_f_mult_compat -Hq2; easy.
Qed.

End Pdk_Facts.

Section inj_Hface_invS_Facts.

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

[RR9557v1] Lem 1584, pp. 94-95.
See also Lem 1581, Eq (9.69), p. 93
(with pi_l = theta^d_i (i>0) from Lem 1368, p. 41).
Lemma inj_Hface_bijS :
  ∀ i, bijS fullset (Hface vtx i) (inj_Hface vtx i).
Proof.
intro; apply bijS_comp_compat with (Hface_ref i);
    [apply inj_Hface_ref_bijS | apply T_geom_bijS_Hface; easy].
Qed.

Definition inj_Hface_invS (i : [0..d]) : 'R^d → 'R^d1 :=
  f_invS (inj_Hface_bijS i).

End inj_Hface_invS_Facts.