Library NumAnalysis.FEM.poly_LagPd1_ref

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.
From NumAnalysis Require Import geometry multi_index poly_Pdk poly_LagP1k.

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

Section Unit_Vertices.

Context {d : nat}.

[RR9557v1] Def 1434, p. 55.
See also Def 1365, p. 40.
Definition vtx_ref (i : [0..d]) : 'R^d :=
  match ord_eq_dec i ord0 with
  | left _ ⇒ 0
  | right Hi ⇒ kron (lower_S Hi)
  end.

Lemma vtx_ref_0 : ∀ i, i = ord0 → vtx_ref i = 0.
Proof. intros; unfold vtx_ref; case (ord_eq_dec _ _); easy. Qed.

Lemma vtx_ref_S : ∀ {i} (Hi : i ≠ ord0), vtx_ref i = kron (lower_S Hi).
Proof. intros; unfold vtx_ref; case (ord_eq_dec _ _); easy. Qed.

Lemma vtx_ref_SF : liftF_S vtx_ref = kron.
Proof.
fun_ext2; unfold liftF_S;
    rewrite (vtx_ref_S (lift_S_not_first _)) lower_lift_S; easy.
Qed.

[RR9557v1] Lem 1436, p. 55.
Lemma vtx_ref_aff_indep : aff_indep_ms vtx_ref.
Proof.
intros L HL.
rewrite (lc_kron_r_decomp L) -HL; apply lc_ext_r; intros; extF.
rewrite -(minus_zero_r (kron _ _)) frameF_ms_eq !fct_minus_eq skipF_first.
rewrite vtx_ref_SF constF_correct vtx_ref_0; easy.
Qed.

Lemma vtx_ref_aff_basis : aff_basis_ms fullset vtx_ref.
Proof.
apply aff_indep_aff_basis;
    [apply has_aff_dim_Rn | easy | apply vtx_ref_aff_indep].
Qed.

Lemma vtx_ref_aff_gen : aff_gen_ms fullset vtx_ref.
Proof. apply vtx_ref_aff_basis. Qed.

Lemma vtx_ref_aff_span : full (aff_span_ms vtx_ref).
Proof. apply full_fullset, eq_sym, vtx_ref_aff_gen. Qed.

Lemma bc_vtx_ref_uniq :
  ∀ (x_ref : 'R^d) (L : 'R^d.+1), sum L = 1 →
    barycenter_ms L vtx_ref = x_ref → L = baryc_coord_ms vtx_ref x_ref.
Proof.
move=>>; apply: bc_uniq; [apply vtx_ref_aff_indep | apply vtx_ref_aff_span].
Qed.

Lemma bc_vtx_ref_am : aff_map_ms (baryc_coord_ms vtx_ref).
Proof.
intros; apply bc_am; [apply vtx_ref_aff_indep | intro; apply vtx_ref_aff_span].
Qed.

Lemma am_ext_vtx_ref :
  ∀ {f g : 'R^d → 'R^d}, aff_map_ms f → aff_map_ms g →
    (∀ i , f (vtx_ref i) = g (vtx_ref i)) → f = g.
Proof.
move=>> Hf Hg; apply am_ext_gen_full_ms; [easy.. | apply vtx_ref_aff_gen].
Qed.

End Unit_Vertices.

Section LagPd1_ref_Facts.

Context {d : nat}.

[RR9557v1] Def 1541, p. 81.
For simplices (P1 in dim d), with x = (x_i)_{i=0..d-1}:
  • LagPd1_ref 0 x = 1 - \sum{i=0}^{d-1} x_i,
  • LagPd1_ref i x = x(i-1), for i=1..d.
Definition LagPd1_ref (i : [0..d]) : FRd d :=
  match ord_eq_dec i ord0 with
    | left _ ⇒ fun x_ref ⇒ 1 - sum x_ref
    | right Hi ⇒ fun x_ref ⇒ x_ref (lower_S Hi)
    end.

Lemma LagPd1_ref_0 :
  ∀ {i}, i = ord0 → LagPd1_ref i = fun x_ref ⇒ 1 - sum x_ref.
Proof. intros; unfold LagPd1_ref; case (ord_eq_dec _ _); easy. Qed.

Lemma LagPd1_ref_S :
  ∀ {i} (Hi : i ≠ ord0), LagPd1_ref i = fun x_ref ⇒ x_ref (lower_S Hi).
Proof.
move=>>; unfold LagPd1_ref; case (ord_eq_dec _ _);
    [| intros H; rewrite (lower_S_ext H)]; easy.
Qed.

Lemma LagPd1_ref_SF : ∀ x_ref, liftF_S (LagPd1_ref^~ x_ref) = x_ref.
Proof.
intro; extF; unfold liftF_S.
rewrite (LagPd1_ref_S (lift_S_not_first _)) lower_lift_S; easy.
Qed.

Lemma LagPd1_ref_0F :
  ∀ {i} x_ref, i = ord0 →
    LagPd1_ref i x_ref = 1 - sum (liftF_S (LagPd1_ref^~ x_ref)).
Proof. intros; subst; rewrite LagPd1_ref_0// LagPd1_ref_SF; easy. Qed.

Lemma LagPd1_ref_0F_f :
  ∀ {i}, i = ord0 →
    LagPd1_ref i = 1 - fun x_ref ⇒ sum (liftF_S (LagPd1_ref^~ x_ref)).
Proof. intros; fun_ext; apply LagPd1_ref_0F; easy. Qed.

Lemma LagPd1_ref_liftF_S :
  ∀ (x_ref : 'R^d.+1),
    sum x_ref = 1 → LagPd1_ref^~ (liftF_S x_ref) = x_ref.
Proof.
intros x_ref Hx_ref; extF i; destruct (ord_eq_dec i ord0) as [-> | Hi].
rewrite LagPd1_ref_0// -Hx_ref sum_ind_l minus_plus_r; easy.
rewrite LagPd1_ref_S liftF_lower_S; easy.
Qed.

[RR9557v1] Lem 1543, Eq (9.33), p. 81.
Lemma LagPd1_ref_sum : ∀ x_ref, sum (LagPd1_ref^~ x_ref) = 1.
Proof. intro; rewrite sum_ind_l LagPd1_ref_0F// plus_minus_l; easy. Qed.

Lemma LagPd1_ref_sum_f : sum LagPd1_ref = 1.
Proof. fun_ext; rewrite fct_sum_eq LagPd1_ref_sum; easy. Qed.

Lemma LagPd1_ref_barycF :
  ∀ x_ref, barycenter_ms (LagPd1_ref^~ x_ref) vtx_ref = x_ref.
Proof.
intros; extF; rewrite baryc_ms_eq; [| apply LagPd1_ref_sum].
rewrite lc_ind_l vtx_ref_0// scal_zero_r plus_zero_l LagPd1_ref_SF.
rewrite vtx_ref_SF fct_lc_r_eq lc_r_kron_l; easy.
Qed.

[RR9557v1] Lem 1560 (with reference vertices), p. 87.
LagPd1_ref are the barycentric coordinates wrt vtx_ref.
Lemma LagPd1_ref_bcF :
  ∀ x_ref, LagPd1_ref^~ x_ref = baryc_coord_ms vtx_ref x_ref.
Proof.
intro; apply bc_vtx_ref_uniq; [apply LagPd1_ref_sum | apply LagPd1_ref_barycF].
Qed.

Lemma LagPd1_ref_bc_scatter : LagPd1_ref = scatter (baryc_coord_ms vtx_ref).
Proof. extF i; fun_ext; move: i; apply extF_rev; apply LagPd1_ref_bcF. Qed.

Lemma LagPd1_ref_bc_gather : baryc_coord_ms vtx_ref = gather LagPd1_ref.
Proof. rewrite LagPd1_ref_bc_scatter gather_scatter; easy. Qed.

Lemma LagPd1_ref_barycF_rev :
  ∀ {L : 'R^d.+1}, sum L = 1 →
    LagPd1_ref^~ (barycenter_ms L vtx_ref) = L.
Proof.
intros; rewrite LagPd1_ref_bcF bc_ms_correct;
    apply eq_sym, bc_vtx_ref_uniq; easy.
Qed.

Lemma LagPd1_ref_am : ∀ i, aff_map_ms (LagPd1_ref i).
Proof.
apply am_gather_rev_ms; rewrite -LagPd1_ref_bc_gather; apply bc_vtx_ref_am.
Qed.

[RR9557v1] Lem 1543, Eq (9.32), p. 81.
Lemma LagPd1_ref_kron_vtxF : ∀ i, LagPd1_ref^~ (vtx_ref i) = kron i.
Proof. intro; rewrite LagPd1_ref_bcF; apply bc_kronF_r, vtx_ref_aff_indep. Qed.

Lemma LagPd1_ref_kron_vtx : ∀ i j, LagPd1_ref j (vtx_ref i) = kron i j.
Proof. intros i j; move: j; apply extF_rev, LagPd1_ref_kron_vtxF. Qed.

Lemma LagPd1_ref_vtx_skipF : ∀ i j, LagPd1_ref i (skipF i vtx_ref j) = 0.
Proof.
intros; unfold skipF; rewrite LagPd1_ref_kron_vtx.
apply kron_is_0, ord_neq_compat, skip_ord_correct_m.
Qed.

Lemma LagPd1_ref_S_Monom :
  liftF_S LagPd1_ref = castF (pbinom_1_r d) (liftF_S (Monom_dk d 1)).
Proof.
extF i; fun_ext; move: i; apply extF_rev;
    rewrite -fct_castF_eq -fct_liftF_S_eq LagPd1_ref_SF Monom_d1_S_eq.
rewrite castF_comp castF_id; easy.
Qed.

Lemma LagPd1_ref_S_is_Pd1 : inclF (liftF_S LagPd1_ref) (Pdk d 1).
Proof.
intro; rewrite LagPd1_ref_S_Monom;
    unfold castF, liftF_S; apply lin_span_inclF_diag.
Qed.

[RR9557v1] Lem 1543, p. 81.
Lemma LagPd1_ref_is_Pd1 : inclF LagPd1_ref (Pdk d 1).
Proof.
intros i; destruct (ord_eq_dec i ord0) as [-> | Hi].
rewrite LagPd1_ref_0F_f//; apply: lin_span_minus_closed.
apply Pdk_const; easy.
apply (Pdk_sum _ (liftF_S LagPd1_ref));
    [apply LagPd1_ref_S_is_Pd1 | fun_ext; rewrite fct_sum_eq; easy].
rewrite -(lift_lower_S Hi); apply LagPd1_ref_S_is_Pd1.
Qed.

Lemma LagPd1_ref_lin_indep : lin_indep LagPd1_ref.
Proof.
intros L HL; extF; rewrite -lc_r_kron_r.
rewrite -LagPd1_ref_kron_vtxF -fct_lc_r_eq HL; easy.
Qed.

[RR9557v1] Lem 1543, p. 81.
Lemma LagPd1_ref_basis : basis (Pdk d 1) LagPd1_ref.
Proof.
apply lin_indep_basis; [rewrite -(pbinomS_1_r d); apply Pdk_has_dim |
    apply LagPd1_ref_is_Pd1 | apply LagPd1_ref_lin_indep].
Qed.

Lemma Pd1_has_dim : has_dim (Pdk d 1) d.+1.
Proof. apply (Dim _ _ _ LagPd1_ref_basis). Qed.

Lemma LagPd1_ref_baryc_lc :
  ∀ L i, sum L = 1 → LagPd1_ref i (lin_comb L vtx_ref) = L i.
Proof.
move=>> HL; rewrite -baryc_ms_eq// -{2}(LagPd1_ref_barycF_rev HL); easy.
Qed.

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

Lemma LagPd1_ref_ge_0 :
  ∀ i (x_ref : 'R^d), K_geom_ref x_ref → 0 ≤ LagPd1_ref i x_ref.
Proof.
move=>> [L HL1 HL2];
    rewrite -baryc_ms_correct baryc_ms_eq// LagPd1_ref_baryc_lc//.
Qed.

Lemma LagPd1_ref_le_1 :
  ∀ i (x_ref : 'R^d), K_geom_ref x_ref → LagPd1_ref i x_ref ≤ 1.
Proof.
replace (1 : R) with (1 : R_Ring) by easy.
move=>> [L HL1 HL2];
    rewrite -baryc_ms_correct baryc_ms_eq// LagPd1_ref_baryc_lc// -HL2.
apply sum_nonneg_ub_R; easy.
Qed.

Lemma LagPd1_ref_inj : injective (gather LagPd1_ref).
Proof.
move⇒ x_ref y_ref /extF_rev H; extF;
    rewrite -(LagPd1_ref_SF x_ref) -(LagPd1_ref_SF y_ref); apply H.
Qed.

Lemma LagPd1_ref_surjS :
  surjS fullset (fun x ⇒ sum x = 1) (gather LagPd1_ref).
Proof.
intros L HL; ∃ (liftF_S L); split; [| apply LagPd1_ref_liftF_S]; easy.
Qed.

Lemma LagPd1_ref_bijS : bijS fullset (fun x ⇒ sum x = 1) (gather LagPd1_ref).
Proof.
apply injS_surjS_bijS; [apply inhabited_ms |..].
intros _ [x_ref _]; apply LagPd1_ref_sum.
apply inj_injS, LagPd1_ref_inj.
apply LagPd1_ref_surjS.
Qed.

End LagPd1_ref_Facts.

Section Face_hyperplane_ref_Def.

Context {d : nat}.

[RR9557v1] Def 1562, p. 88.
Note that Hface_ref i is the face hyperplane opposite reference vertex \hat{v}i
Definition Hface_ref (i : [0..d]) : 'R^d → Prop :=
  aff_span_ms (skipF i vtx_ref).

[RR9557v1] Lem 1564, p. 88.
Lemma Hface_ref_is_Ker : ∀ i, Hface_ref i = Ker (LagPd1_ref i).
Proof.
intro; unfold Hface_ref; apply subset_ext_equiv; split.
intros _ [L HL]; apply (Ker_cas (LagPd1_ref_am _)); [easy |].
intros j; rewrite Ker_equiv; apply LagPd1_ref_vtx_skipF.
move⇒ x_ref /Ker_equiv Hx_ref; rewrite -(LagPd1_ref_barycF x_ref).
rewrite baryc_ms_correct (baryc_skip_zero i)//; [apply Aff_span |].
rewrite -(plus_zero_l (sum _)) -Hx_ref -sum_skipF.
1,2: apply invertible_eq_one, LagPd1_ref_sum; easy.
Qed.

Lemma Hface_ref_equiv :
  ∀ i x_ref, Hface_ref i x_ref ↔ LagPd1_ref i x_ref = 0.
Proof. intros; rewrite Hface_ref_is_Ker; apply Ker_equiv. Qed.

[RR9557v1] Lem 1564, Eq (9.58), p. 88.
Lemma Hface_ref_0_eq :
  ∀ {i}, i = ord0 → Hface_ref i = fun x_ref ⇒ sum x_ref = 1.
Proof.
intros; subst; apply subset_ext; intro; rewrite Hface_ref_equiv LagPd1_ref_0//.
apply: minus_zero_sym_equiv.
Qed.

[RR9557v1] Lem 1564, Eq (9.59), p. 88.
Lemma Hface_ref_S_eq :
  ∀ {i} (Hi : i ≠ ord0),
    Hface_ref i = fun x_ref ⇒ x_ref (lower_S Hi) = 0.
Proof.
intros; apply subset_ext; intro; rewrite Hface_ref_equiv LagPd1_ref_S//.
Qed.

End Face_hyperplane_ref_Def.

Section Face_hyperplane_ref_injection_Facts.

We need a dimension which is structurally nonzero. We take d = d1.+1 with d1 : nat.
Context {d1 : nat}.
Let d := d1.+1.

Definition inj_Hface_ref (i : [0..d]) : 'R^d1 → 'R^d :=
  match ord_eq_dec i ord0 with
  | left _ ⇒ part1F0
  | right Hi ⇒ insert0F (lower_S Hi)
  end.

Lemma inj_Hface_ref_0 : ∀ {i}, i = ord0 → inj_Hface_ref i = part1F0.
Proof. intros; unfold inj_Hface_ref; case (ord_eq_dec _ _); easy. Qed.

Lemma inj_Hface_ref_S :
  ∀ {i} (Hi : i ≠ ord0), inj_Hface_ref i = insert0F (lower_S Hi).
Proof.
move=>>; unfold inj_Hface_ref; case (ord_eq_dec _ _);
    [| intros H; rewrite (lower_S_ext H)]; easy.
Qed.

Lemma inj_Hface_ref_am : ∀ i, aff_map_ms (inj_Hface_ref i).
Proof.
intros i; destruct (ord_eq_dec i ord0).
rewrite inj_Hface_ref_0//; apply part1F_am.
rewrite inj_Hface_ref_S; apply: insert0F_am.
Qed.

Lemma inj_Hface_ref_Rg : ∀ i, Rg (inj_Hface_ref i) = Hface_ref i.
Proof.
intros i; destruct (ord_eq_dec i ord0).
rewrite inj_Hface_ref_0// Hface_ref_0_eq//; apply: part1F_Rg.
rewrite inj_Hface_ref_S Hface_ref_S_eq; apply insertF_Rg.
Qed.

Lemma inj_Hface_ref_funS :
  ∀ i, funS fullset (Hface_ref i) (inj_Hface_ref i).
Proof. intro; rewrite -inj_Hface_ref_Rg; easy. Qed.

Lemma inj_Hface_ref_injS : ∀ i, injS fullset (inj_Hface_ref i).
Proof.
intros i; destruct (ord_eq_dec i ord0);
    [rewrite inj_Hface_ref_0// |rewrite inj_Hface_ref_S];
    move=>> _ _; apply insertF_inj.
Qed.

Lemma inj_Hface_ref_surjS :
  ∀ i, surjS fullset (Hface_ref i) (inj_Hface_ref i).
Proof.
intro; apply surjS_RgS_equiv, inter_left; rewrite inj_Hface_ref_Rg//.
Qed.

Lemma inj_Hface_ref_bijS :
  ∀ i, bijS fullset (Hface_ref i) (inj_Hface_ref i).
Proof.
intros; apply (injS_surjS_bijS inhabited_ms).
apply inj_Hface_ref_funS.
apply inj_Hface_ref_injS.
apply inj_Hface_ref_surjS.
Qed.

End Face_hyperplane_ref_injection_Facts.

Section Pdk_Facts.

Factorization result.

Context {d k : nat}.
Hypothesis Hd : d ≠ 0.

[RR9557v1] Lem 1621, direct way, pp. 104-105.
Lemma factor_zero_on_last_Hface_ref :
  ∀ {p}, Pdk d k.+1 p →
    (∀ x_ref, Hface_ref ord_max x_ref → p x_ref = 0) →
    ∃ q, Pdk d k q ∧ p = LagPd1_ref ord_max × q.
Proof.
assert (H0 : ∀ n, (ord_max : [0..n]) = lower_S ord_max_not_0)
    by (intro; apply eq_sym, lower_S_max).
intros p Hp1; destruct d as [| d1]; [easy |].
intros Hp2; destruct (PSdSk_split k p Hp1) as [p0 [q [Hp0 [Hq Hp3]]]].
∃ q; split; [easy |]; fun_ext x_ref.
rewrite Hp3 fct_mult_eq (LagPd1_ref_S ord_max_not_0).
rewrite -(plus_zero_l (x_ref (lower_S _) × _)); repeat f_equal; [| easy].
pose (y_ref := widenF_S x_ref); fold y_ref;
    rewrite -(Hp2 (insertFmax 0 y_ref)).
rewrite Hp3 widenF_S_insertF_max insertF_correct_l// mult_zero_l plus_zero_r//.
rewrite Hface_ref_equiv (LagPd1_ref_S ord_max_not_0) insertF_correct_l; easy.
Qed.

End Pdk_Facts.