(* This program 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 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program 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      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
(** * lin_dep_facts.v *)
Set Implicit Arguments.
Unset Strict Implicit.
Require Export lin_dependence.
Require Export lin_comb_facts.
Require Export subseqs.
Require Export seq_set_facts.
Require Export distinct_facts.
(** - If $a_i\neq0$ and $\sum_ka_kv_k=0$, then $v_i=-a_i^{-1}\sum_{k\neq i}a_kv_k$ *)
intros.
assert
(a i mX v i ='
a i mX field_inverse (a i) mX (min sum (omit (mult_by_scalars a v) i)) in _).
apply Trans with (mult_by_scalars a v i); auto with algebra.
apply
Trans
with
((a i rX field_inverse (a i)) mX (min sum (omit (mult_by_scalars a v) i)));
auto with algebra.
apply Trans with (one mX (min sum (omit (mult_by_scalars a v) i)));
auto with algebra.
apply Trans with (min sum (omit (mult_by_scalars a v) i)); auto with algebra.
assert
(mult_by_scalars a v i +' sum (omit (mult_by_scalars a v) i) ='
(zero V) in _).
apply Trans with (sum (mult_by_scalars a v)); auto with algebra.
apply Sym.
apply
(seqsum_is_elt_plus_omitseq (M:=V:abelian_monoid) (mult_by_scalars a v)).
2: apply MODULE_comp; auto with algebra.
2: apply Sym.
2: apply FIELD_inverse_r; auto with algebra.
apply Sym.
apply GROUP_law_inverse.
apply Trans with (sum (mult_by_scalars a v)); auto with algebra.
apply
Trans with (mult_by_scalars a v i +' sum (omit (mult_by_scalars a v) i));
auto with algebra.
apply Sym.
apply
(seqsum_is_elt_plus_omitseq (M:=V:abelian_monoid) (mult_by_scalars a v));
auto with algebra.
set (expr := field_inverse (a i) mX (min sum (omit (mult_by_scalars a v) i)))
in *.
cut (one mX v i =' one mX expr in _).
intro.
apply Trans with (one mX expr); auto with algebra.
apply Trans with (one mX v i); auto with algebra.
apply Trans with ((field_inverse (a i) rX a i) mX v i).
apply MODULE_comp; auto with algebra.
apply Sym.
auto with algebra.
apply Trans with ((field_inverse (a i) rX a i) mX expr); auto with algebra.
apply Trans with (field_inverse (a i) mX a i mX expr); auto with algebra.
apply Trans with (field_inverse (a i) mX a i mX v i); auto with algebra.
Qed.
simpl in |- *.
intros.
generalize H; elim y.
intros yv yp Hy.
simpl in yp.
simpl in Hy.
simpl in |- *.
unfold not in Hy.
case yp; auto.
tauto.
Qed.
intros.
set (Sx := union s (single x)) in *.
split.
intro.
unfold lin_dep in H1.
elim H1; clear H1; intros.
elim H1; clear H1; intros.
elim H1; clear H1; intros.
elim H1; clear H1; intros.
elim H2; clear H2; intros.
generalize x0 x1 x2 H1 H2 H3.
clear H3 H2 H1 x2 x1 x0; intros n a x' Hx' Ha Hlc.
assert (~ (forall i : fin (S n), in_part (Map_embed x' i) s)).
red in |- *; intro.
assert (exists y : seq (S n) s, Map_embed y =' Map_embed x' in _).
unfold seq in |- *.
apply subset_seq_castable; auto with algebra.
inversion H2.
repeat red in H; apply H.
red in |- *.
exists n.
exists a.
exists x0.
split.
assert (distinct (Map_embed x')).
apply Map_embed_preserves_distinct; auto with algebra.
assert (distinct (Map_embed x0)).
apply distinct_comp with (Map_embed x'); auto with algebra.
apply Map_embed_reflects_distinct; auto with algebra.
split.
auto.
apply Trans with (sum (mult_by_scalars a (Map_embed x'))); auto with algebra.
assert (exists i : fin (S n), ~ in_part (Map_embed x' i) s).
apply NNPP.
red in |- *; red in H1.
intro; apply H1.
intro.
red in H2.
apply NNPP.
red in |- *.
intro.
apply H2.
exists i; auto.
elim H2; intros.
generalize x0 H3; clear H3 x0; intros i Hi.
assert (in_part (Map_embed x' i) Sx).
apply Map_embed_prop; auto with algebra.
assert (in_part (Map_embed x' i) (single x)).
apply union_not_in_l with s; auto with algebra.
assert (Map_embed x' i =' x in _).
apply single_prop_rev; auto with algebra.
cut (~ a i =' (zero F) in _).
intro.
assert
(Map_embed x' i ='
field_inverse (a i)
mX (min sum (omit (mult_by_scalars a (Map_embed x'):seq _ _) i)) in _).
apply rewrite_lin_comb_term; auto with algebra.
assert (forall j : fin n, in_part (omit (Map_embed x') i j) s).
intro.
assert (distinct (Map_embed x')).
apply Map_embed_preserves_distinct; auto with algebra.
assert (~ omit (Map_embed x') i j =' Map_embed x' i in _).
apply distinct_omit_removes_all; auto with algebra.
assert (~ omit (Map_embed x') i j =' x in _).
red in |- *; red in H9; intro; apply H9.
apply Trans with x; auto with algebra.
assert (~ in_part (omit (Map_embed x') i j) (single x)).
red in |- *; red in H10; intro; apply H10.
apply single_prop_rev; auto with algebra.
assert (in_part (omit (Map_embed x') i j) Sx).
apply in_part_comp_l with (Map_embed (omit x' i) j); auto with algebra.
apply Map_embed_prop; auto with algebra.
assert (in_part (omit (Map_embed x') i j) (union (single x) s)).
apply in_part_comp_r with Sx; auto with algebra.
simpl in |- *.
red in |- *.
simpl in |- *.
split.
tauto.
tauto.
apply union_not_in_l with (single x); auto with algebra.
assert
(x ='
sum
(mult_by_scalars
(pointwise (uncurry (RING_comp (R:=F)))
(const_seq n (min field_inverse (a i))) (omit a i))
(omit (Map_embed x') i)) in _).
apply Trans with (Map_embed x' i); auto with algebra.
cut
(field_inverse (a i)
mX (min sum (omit (mult_by_scalars a (Map_embed x'):seq (S n) V) i)) ='
sum
(mult_by_scalars
(pointwise (uncurry (RING_comp (R:=F)))
(const_seq n (min field_inverse (a i))) (omit a i))
(omit (Map_embed x') i)) in _).
intro.
apply
Trans
with
(field_inverse (a i)
mX (min sum (omit (mult_by_scalars a (Map_embed x')) i)));
auto with algebra.
apply
Trans
with
(sum
(mult_by_scalars (const_seq n (min field_inverse (a i)))
(mult_by_scalars (omit a i) (omit (Map_embed x') i)))).
2: apply sum_comp; auto with algebra.
apply
Trans
with
((min field_inverse (a i))
mX sum (mult_by_scalars (omit a i) (omit (Map_embed x') i)));
auto with algebra.
apply Sym; auto with algebra.
apply
Trans
with
((min field_inverse (a i))
mX sum (omit (mult_by_scalars a (Map_embed x')) i));
auto with algebra.
assert (exists y : seq n s, Map_embed y =' omit (Map_embed x') i in _).
unfold seq in |- *.
apply seq_castable; auto with algebra.
elim H10; intros.
assert
(x ='
sum
(mult_by_scalars
(pointwise (uncurry (RING_comp (R:=F)))
(const_seq n (min field_inverse (a i))) (omit a i))
(Map_embed x0)) in _).
apply
Trans
with
(sum
(mult_by_scalars
(pointwise (uncurry (RING_comp (R:=F)))
(const_seq n (min field_inverse (a i)))
(omit a i)) (omit (Map_embed x') i)));
auto with algebra.
simpl in |- *.
red in |- *.
exists n.
exists
(pointwise (uncurry (RING_comp (R:=F)))
(const_seq n (min field_inverse (a i))) (omit a i)).
exists x0.
auto.
generalize a x' Hx' Ha Hlc i H5; clear H5 H4 H3 Hi i H2 H1 Hlc Ha Hx' x' a;
case n.
intros.
red in |- *; red in Ha; intro; apply Ha.
assert (head a =' (zero F) in _).
apply Trans with (a i); auto with algebra.
apply Sym; auto with algebra.
intros.
red in |- *; intro.
assert
(sum (mult_by_scalars (omit a i) (omit (Map_embed x') i)) =' (zero V) in _).
apply Trans with (sum (omit (mult_by_scalars a (Map_embed x')) i));
auto with algebra.
apply Trans with (sum (mult_by_scalars a (Map_embed x'))); auto with algebra.
apply Sym.
apply sum_omit_zeros; auto with algebra.
simpl in |- *.
apply Trans with ((zero F) mX subtype_elt (x' i)); auto with algebra.
assert (exists y : seq (S n0) s, Map_embed y =' omit (Map_embed x') i in _).
(* copy'n'paste *)
assert (forall j : fin (S n0), in_part (omit (Map_embed x') i j) s).
intro.
assert (distinct (Map_embed x')).
apply Map_embed_preserves_distinct; auto with algebra.
assert (~ omit (Map_embed x') i j =' Map_embed x' i in _).
apply distinct_omit_removes_all; auto with algebra.
assert (~ omit (Map_embed x') i j =' x in _).
red in |- *; red in H4; intro; apply H4.
apply Trans with x; auto with algebra.
assert (~ in_part (omit (Map_embed x') i j) (single x)).
red in |- *; red in H6; intro; apply H6.
apply single_prop_rev; auto with algebra.
assert (in_part (omit (Map_embed x') i j) Sx).
apply in_part_comp_l with (Map_embed (omit x' i) j); auto with algebra.
apply Map_embed_prop; auto with algebra.
assert (in_part (omit (Map_embed x') i j) (union (single x) s)).
apply in_part_comp_r with Sx; auto with algebra.
simpl in |- *.
red in |- *.
simpl in |- *.
split.
tauto.
tauto.
apply union_not_in_l with (single x); auto with algebra.
unfold seq in |- *.
apply seq_castable; auto with algebra.
elim H3; intros.
assert (sum (mult_by_scalars (omit a i) (Map_embed x0)) =' (zero V) in _).
apply Trans with (sum (mult_by_scalars (omit a i) (omit (Map_embed x') i)));
auto with algebra.
red in H.
red in H.
apply H; auto with algebra.
red in |- *.
exists n0.
exists (omit a i).
exists x0.
split.
apply Map_embed_reflects_distinct; auto with algebra.
apply distinct_comp with (omit (Map_embed x') i); auto with algebra.
split.
red in |- *; red in Ha; intro; apply Ha.
2: auto.
clear H6 H4 x0 H3 H2 H5 Hlc Hx' x' n Sx H0 x H s V.
simpl in |- *; red in |- *.
simpl in |- *.
intro j.
elim (fin_decidable i j).
intro.
apply Trans with (a i); auto with algebra.
change (Map_eq (omit a i) (const_seq (S n0) (zero F))) in H7.
red in H7.
intro.
generalize omit_removes'.
intro p.
case (p _ _ a _ _ H).
intros.
apply Trans with (omit a i x); auto with algebra.
apply Trans with (const_seq (S n0) (zero F) x); auto with algebra.
(* My gods that was painful *)
(* Now the other direction *)
intro.
simpl in H1.
generalize (lin_comb_with_distinct_vectors H1).
clear H1.
intro H1.
elim H1; clear H1; intros.
elim H1; clear H1; intros.
elim H1; clear H1; intros.
elim H1; clear H1; intros.
rename H2 into Dx2.
assert (exists v : seq x0 Sx, Map_embed v =' Map_embed x2 in _).
unfold seq in |- *.
apply subset_seq_castable; auto with algebra.
intro.
assert (in_part (Map_embed x2 i) s).
apply Map_embed_prop; auto with algebra.
unfold Sx in |- *.
apply in_part_union_l; auto with algebra.
elim H2; clear H2; intros.
assert (x =' sum (mult_by_scalars x1 (Map_embed x3)) in _).
apply Trans with (sum (mult_by_scalars x1 (Map_embed x2))); auto with algebra.
assert (exists x' : Sx, Sx x' =' x in _).
simpl in |- *.
assert (in_part x Sx).
simpl in |- *.
right; auto with algebra.
assert (Pred_fun Sx x); auto with algebra.
exists (Build_subtype H5).
simpl in |- *.
auto with algebra.
elim H4; clear H4; intros.
assert
(sum (mult_by_scalars ((min one);; x1) (Map_embed (x4;; x3))) ='
(zero V) in _).
apply
Trans with (sum (mult_by_scalars ((min one);; x1) (Sx x4;; Map_embed x3))).
apply sum_comp; auto with algebra.
unfold mult_by_scalars in |- *.
apply
Trans
with
(sum
(uncurry (MODULE_comp (Mod:=V)) (couple (min one) (Sx x4));;
mult_by_scalars x1 (Map_embed x3))).
unfold mult_by_scalars in |- *.
apply sum_comp; auto with algebra.
apply
Trans
with
(uncurry (MODULE_comp (R:=F) (Mod:=V)) (couple (min one) (Sx x4)) +'
sum (mult_by_scalars x1 (Map_embed x3))); auto with algebra.
simpl in |- *.
apply
Trans with ((min one mX Sx x4) +' sum (mult_by_scalars x1 (Map_embed x3)));
auto with algebra.
apply Trans with ((min one mX Sx x4) +' x); auto with algebra.
apply Trans with ((min Sx x4) +' x); auto with algebra.
apply Trans with ((min x) +' x); auto with algebra.
red in |- *.
exists x0.
exists ((min one);; x1).
exists (x4;; x3).
split.
red in |- *.
assert (distinct x3).
apply Map_embed_reflects_distinct.
apply distinct_comp with (Map_embed x2); auto with algebra.
intros i j; case i; case j.
intros ni Hi nj Hj; generalize Hi Hj; clear Hj Hi; case ni; case nj.
simpl in |- *.
intros; absurd (0 = 0); auto.
3: intros.
3: simpl in |- *.
3: red in H6.
3: simpl in H6.
3: apply H6; auto with algebra.
simpl in |- *.
intros.
change (~ x3 (Build_finiteT (lt_S_n _ _ Hj)) =' x4 in _) in |- *.
red in |- *; intro.
assert (in_part (Sx (x3 (Build_finiteT (lt_S_n _ _ Hj)))) s).
apply in_part_comp_l with (Map_embed x3 (Build_finiteT (lt_S_n _ _ Hj)));
auto with algebra.
apply in_part_comp_l with (Map_embed x2 (Build_finiteT (lt_S_n _ _ Hj)));
auto with algebra.
apply Map_embed_prop; auto with algebra.
assert (~ in_part (Sx x4) s).
red in |- *; intro.
assert (in_part x s).
apply in_part_comp_l with (Sx x4); auto with algebra.
absurd (in_part x s); auto.
red in H10; (apply H10; auto with algebra).
apply in_part_comp_l with (Sx (x3 (Build_finiteT (lt_S_n _ _ Hj))));
auto with algebra.
simpl in |- *.
intros.
change (~ x4 =' x3 (Build_finiteT (lt_S_n _ _ Hi)) in _) in |- *.
red in |- *; intro.
assert (in_part (Sx (x3 (Build_finiteT (lt_S_n _ _ Hi)))) s).
apply in_part_comp_l with (Map_embed x3 (Build_finiteT (lt_S_n _ _ Hi)));
auto with algebra.
apply in_part_comp_l with (Map_embed x2 (Build_finiteT (lt_S_n _ _ Hi)));
auto with algebra.
apply Map_embed_prop; auto with algebra.
assert (~ in_part (Sx x4) s).
red in |- *; intro.
assert (in_part x s).
apply in_part_comp_l with (Sx x4); auto with algebra.
absurd (in_part x s); auto.
red in H10; (apply H10; auto with algebra).
apply in_part_comp_l with (Sx (x3 (Build_finiteT (lt_S_n _ _ Hi))));
auto with algebra.
split.
simpl in |- *.
red in |- *; intro.
red in H6.
generalize (H6 (Build_finiteT (lt_O_Sn x0))).
simpl in |- *.
intro.
absurd (one =' (zero F) in _); auto with algebra.
apply Trans with (min (zero F)); auto with algebra.
apply Trans with ((min (min one)):F); auto with algebra.
auto.
Qed.
(** - Remember how max_lin_dep was defined with respect to arbitrary sets instead of just subspaces. So (max_lin_indep W' W) need not mean span(W')=W *)
intros.
red in H.
elim H; clear H; intros.
elim H0; clear H0; intros.
case (classic (in_part (subtype_elt w) W')).
intro; red in |- *.
exists 1.
exists (const_seq (A:=F) 1 one).
exists (const_seq (A:=W') 1 (Build_subtype H2)).
simpl in |- *.
apply Trans with (one mX subtype_elt w); auto with algebra.
intro.
generalize (lin_dep_vs_span_lemma (F:=F) (V:=V) (s:=W')).
intros.
generalize (H3 H0 (subtype_elt w) H2).
intro.
clear H3; inversion_clear H4.
apply H3; auto with algebra.
Qed.
intros.
simpl in |- *.
red in |- *.
simpl in |- *.
split; intros.
apply lin_comb_casting with W; auto with algebra.
apply max_lin_indep_subset_generates_set; auto with algebra.
red in H.
inversion_clear H.
assert (included (span W') (span W)).
apply span_preserves_inclusion; auto with algebra.
change (in_part x (span W)) in |- *.
change (in_part x (span W')) in H0.
red in H.
apply H; auto with algebra.
Qed.

(** - The seq_set in this lemma is needed to transform seqs into sets: *)
Lemma seq_has_max_lin_indep_subseq :
forall (F : field) (V : vectorspace F) (n : Nat) (v : seq n V),
exists k : Nat,
(exists w : seq k V,
is_subseq w v /\ max_lin_indep (seq_set w) (seq_set v)).