src/HOL/Multivariate_Analysis/Determinants.thy
author wenzelm
Sat, 07 Apr 2012 16:41:59 +0200
changeset 47389 e8552cba702d
parent 47108 2a1953f0d20d
child 50526 899c9c4e4a4c
permissions -rw-r--r--
explicit checks stable_finished_theory/stable_command allow parallel asynchronous command transactions; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41959
b460124855b8 tuned headers;
wenzelm
parents: 40077
diff changeset
     1
(*  Title:      HOL/Multivariate_Analysis/Determinants.thy
b460124855b8 tuned headers;
wenzelm
parents: 40077
diff changeset
     2
    Author:     Amine Chaieb, University of Cambridge
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
     3
*)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
     4
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
     5
header {* Traces, Determinant of square matrices and some properties *}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
     6
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
     7
theory Determinants
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
     8
imports
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
     9
  Cartesian_Euclidean_Space
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
    10
  "~~/src/HOL/Library/Permutations"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    11
begin
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    12
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    13
subsection{* First some facts about products*}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    14
lemma setprod_insert_eq: "finite A \<Longrightarrow> setprod f (insert a A) = (if a \<in> A then setprod f A else f a * setprod f A)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    15
apply clarsimp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    16
by(subgoal_tac "insert a A = A", auto)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    17
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    18
lemma setprod_add_split:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    19
  assumes mn: "(m::nat) <= n + 1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    20
  shows "setprod f {m.. n+p} = setprod f {m .. n} * setprod f {n+1..n+p}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    21
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    22
  let ?A = "{m .. n+p}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    23
  let ?B = "{m .. n}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    24
  let ?C = "{n+1..n+p}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    25
  from mn have un: "?B \<union> ?C = ?A" by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    26
  from mn have dj: "?B \<inter> ?C = {}" by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    27
  have f: "finite ?B" "finite ?C" by simp_all
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    28
  from setprod_Un_disjoint[OF f dj, of f, unfolded un] show ?thesis .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    29
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    30
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    31
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    32
lemma setprod_offset: "setprod f {(m::nat) + p .. n + p} = setprod (\<lambda>i. f (i + p)) {m..n}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    33
apply (rule setprod_reindex_cong[where f="op + p"])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    34
apply (auto simp add: image_iff Bex_def inj_on_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    35
apply arith
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    36
apply (rule ext)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    37
apply (simp add: add_commute)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    38
done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    39
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    40
lemma setprod_singleton: "setprod f {x} = f x" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    41
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    42
lemma setprod_singleton_nat_seg: "setprod f {n..n} = f (n::'a::order)" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    43
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    44
lemma setprod_numseg: "setprod f {m..0} = (if m=0 then f 0 else 1)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    45
  "setprod f {m .. Suc n} = (if m \<le> Suc n then f (Suc n) * setprod f {m..n}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    46
                             else setprod f {m..n})"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    47
  by (auto simp add: atLeastAtMostSuc_conv)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    48
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34291
diff changeset
    49
lemma setprod_le: assumes fS: "finite S" and fg: "\<forall>x\<in>S. f x \<ge> 0 \<and> f x \<le> (g x :: 'a::linordered_idom)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    50
  shows "setprod f S \<le> setprod g S"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    51
using fS fg
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    52
apply(induct S)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    53
apply simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    54
apply auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    55
apply (rule mult_mono)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    56
apply (auto intro: setprod_nonneg)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    57
done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    58
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    59
  (* FIXME: In Finite_Set there is a useless further assumption *)
36409
d323e7773aa8 use new classes (linordered_)field_inverse_zero
haftmann
parents: 36350
diff changeset
    60
lemma setprod_inversef: "finite A ==> setprod (inverse \<circ> f) A = (inverse (setprod f A) :: 'a:: field_inverse_zero)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    61
  apply (erule finite_induct)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    62
  apply (simp)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    63
  apply simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    64
  done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    65
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34291
diff changeset
    66
lemma setprod_le_1: assumes fS: "finite S" and f: "\<forall>x\<in>S. f x \<ge> 0 \<and> f x \<le> (1::'a::linordered_idom)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    67
  shows "setprod f S \<le> 1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    68
using setprod_le[OF fS f] unfolding setprod_1 .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    69
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    70
subsection{* Trace *}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    71
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
    72
definition trace :: "'a::semiring_1^'n^'n \<Rightarrow> 'a" where
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    73
  "trace A = setsum (\<lambda>i. ((A$i)$i)) (UNIV::'n set)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    74
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    75
lemma trace_0: "trace(mat 0) = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    76
  by (simp add: trace_def mat_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    77
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
    78
lemma trace_I: "trace(mat 1 :: 'a::semiring_1^'n^'n) = of_nat(CARD('n))"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    79
  by (simp add: trace_def mat_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    80
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
    81
lemma trace_add: "trace ((A::'a::comm_semiring_1^'n^'n) + B) = trace A + trace B"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    82
  by (simp add: trace_def setsum_addf)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    83
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
    84
lemma trace_sub: "trace ((A::'a::comm_ring_1^'n^'n) - B) = trace A - trace B"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    85
  by (simp add: trace_def setsum_subtractf)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    86
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
    87
lemma trace_mul_sym:"trace ((A::'a::comm_semiring_1^'n^'n) ** B) = trace (B**A)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    88
  apply (simp add: trace_def matrix_matrix_mult_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    89
  apply (subst setsum_commute)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    90
  by (simp add: mult_commute)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    91
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    92
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    93
(* Definition of determinant.                                                *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    94
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    95
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
    96
definition det:: "'a::comm_ring_1^'n^'n \<Rightarrow> 'a" where
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    97
  "det A = setsum (\<lambda>p. of_int (sign p) * setprod (\<lambda>i. A$i$p i) (UNIV :: 'n set)) {p. p permutes (UNIV :: 'n set)}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    98
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    99
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   100
(* A few general lemmas we need below.                                       *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   101
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   102
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   103
lemma setprod_permute:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   104
  assumes p: "p permutes S"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   105
  shows "setprod f S = setprod (f o p) S"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   106
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   107
  {assume "\<not> finite S" hence ?thesis by simp}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   108
  moreover
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   109
  {assume fS: "finite S"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   110
    then have ?thesis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   111
      apply (simp add: setprod_def cong del:strong_setprod_cong)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   112
      apply (rule ab_semigroup_mult.fold_image_permute)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   113
      apply (auto simp add: p)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   114
      apply unfold_locales
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   115
      done}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   116
  ultimately show ?thesis by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   117
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   118
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   119
lemma setproduct_permute_nat_interval: "p permutes {m::nat .. n} ==> setprod f {m..n} = setprod (f o p) {m..n}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   120
  by (blast intro!: setprod_permute)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   121
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   122
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   123
(* Basic determinant properties.                                             *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   124
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   125
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   126
lemma det_transpose: "det (transpose A) = det (A::'a::comm_ring_1 ^'n^'n)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   127
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   128
  let ?di = "\<lambda>A i j. A$i$j"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   129
  let ?U = "(UNIV :: 'n set)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   130
  have fU: "finite ?U" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   131
  {fix p assume p: "p \<in> {p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   132
    from p have pU: "p permutes ?U" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   133
    have sth: "sign (inv p) = sign p"
44260
7784fa3232ce Determinants.thy: avoid using mem_def/Collect_def
huffman
parents: 44228
diff changeset
   134
      by (metis sign_inverse fU p mem_Collect_eq permutation_permutes)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   135
    from permutes_inj[OF pU]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   136
    have pi: "inj_on p ?U" by (blast intro: subset_inj_on)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   137
    from permutes_image[OF pU]
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   138
    have "setprod (\<lambda>i. ?di (transpose A) i (inv p i)) ?U = setprod (\<lambda>i. ?di (transpose A) i (inv p i)) (p ` ?U)" by simp
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   139
    also have "\<dots> = setprod ((\<lambda>i. ?di (transpose A) i (inv p i)) o p) ?U"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   140
      unfolding setprod_reindex[OF pi] ..
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   141
    also have "\<dots> = setprod (\<lambda>i. ?di A i (p i)) ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   142
    proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   143
      {fix i assume i: "i \<in> ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   144
        from i permutes_inv_o[OF pU] permutes_in_image[OF pU]
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   145
        have "((\<lambda>i. ?di (transpose A) i (inv p i)) o p) i = ?di A i (p i)"
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
   146
          unfolding transpose_def by (simp add: fun_eq_iff)}
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   147
      then show "setprod ((\<lambda>i. ?di (transpose A) i (inv p i)) o p) ?U = setprod (\<lambda>i. ?di A i (p i)) ?U" by (auto intro: setprod_cong)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   148
    qed
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   149
    finally have "of_int (sign (inv p)) * (setprod (\<lambda>i. ?di (transpose A) i (inv p i)) ?U) = of_int (sign p) * (setprod (\<lambda>i. ?di A i (p i)) ?U)" using sth
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   150
      by simp}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   151
  then show ?thesis unfolding det_def apply (subst setsum_permutations_inverse)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   152
  apply (rule setsum_cong2) by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   153
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   154
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   155
lemma det_lowerdiagonal:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   156
  fixes A :: "'a::comm_ring_1^('n::{finite,wellorder})^('n::{finite,wellorder})"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   157
  assumes ld: "\<And>i j. i < j \<Longrightarrow> A$i$j = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   158
  shows "det A = setprod (\<lambda>i. A$i$i) (UNIV:: 'n set)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   159
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   160
  let ?U = "UNIV:: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   161
  let ?PU = "{p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   162
  let ?pp = "\<lambda>p. of_int (sign p) * setprod (\<lambda>i. A$i$p i) (UNIV :: 'n set)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   163
  have fU: "finite ?U" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   164
  from finite_permutations[OF fU] have fPU: "finite ?PU" .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   165
  have id0: "{id} \<subseteq> ?PU" by (auto simp add: permutes_id)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   166
  {fix p assume p: "p \<in> ?PU -{id}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   167
    from p have pU: "p permutes ?U" and pid: "p \<noteq> id" by blast+
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   168
    from permutes_natset_le[OF pU] pid obtain i where
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   169
      i: "p i > i" by (metis not_le)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   170
    from ld[OF i] have ex:"\<exists>i \<in> ?U. A$i$p i = 0" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   171
    from setprod_zero[OF fU ex] have "?pp p = 0" by simp}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   172
  then have p0: "\<forall>p \<in> ?PU -{id}. ?pp p = 0"  by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   173
  from setsum_mono_zero_cong_left[OF fPU id0 p0] show ?thesis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   174
    unfolding det_def by (simp add: sign_id)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   175
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   176
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   177
lemma det_upperdiagonal:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   178
  fixes A :: "'a::comm_ring_1^'n::{finite,wellorder}^'n::{finite,wellorder}"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   179
  assumes ld: "\<And>i j. i > j \<Longrightarrow> A$i$j = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   180
  shows "det A = setprod (\<lambda>i. A$i$i) (UNIV:: 'n set)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   181
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   182
  let ?U = "UNIV:: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   183
  let ?PU = "{p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   184
  let ?pp = "(\<lambda>p. of_int (sign p) * setprod (\<lambda>i. A$i$p i) (UNIV :: 'n set))"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   185
  have fU: "finite ?U" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   186
  from finite_permutations[OF fU] have fPU: "finite ?PU" .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   187
  have id0: "{id} \<subseteq> ?PU" by (auto simp add: permutes_id)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   188
  {fix p assume p: "p \<in> ?PU -{id}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   189
    from p have pU: "p permutes ?U" and pid: "p \<noteq> id" by blast+
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   190
    from permutes_natset_ge[OF pU] pid obtain i where
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   191
      i: "p i < i" by (metis not_le)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   192
    from ld[OF i] have ex:"\<exists>i \<in> ?U. A$i$p i = 0" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   193
    from setprod_zero[OF fU ex] have "?pp p = 0" by simp}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   194
  then have p0: "\<forall>p \<in> ?PU -{id}. ?pp p = 0"  by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   195
  from   setsum_mono_zero_cong_left[OF fPU id0 p0] show ?thesis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   196
    unfolding det_def by (simp add: sign_id)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   197
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   198
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   199
lemma det_diagonal:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   200
  fixes A :: "'a::comm_ring_1^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   201
  assumes ld: "\<And>i j. i \<noteq> j \<Longrightarrow> A$i$j = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   202
  shows "det A = setprod (\<lambda>i. A$i$i) (UNIV::'n set)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   203
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   204
  let ?U = "UNIV:: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   205
  let ?PU = "{p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   206
  let ?pp = "\<lambda>p. of_int (sign p) * setprod (\<lambda>i. A$i$p i) (UNIV :: 'n set)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   207
  have fU: "finite ?U" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   208
  from finite_permutations[OF fU] have fPU: "finite ?PU" .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   209
  have id0: "{id} \<subseteq> ?PU" by (auto simp add: permutes_id)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   210
  {fix p assume p: "p \<in> ?PU - {id}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   211
    then have "p \<noteq> id" by simp
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
   212
    then obtain i where i: "p i \<noteq> i" unfolding fun_eq_iff by auto
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   213
    from ld [OF i [symmetric]] have ex:"\<exists>i \<in> ?U. A$i$p i = 0" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   214
    from setprod_zero [OF fU ex] have "?pp p = 0" by simp}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   215
  then have p0: "\<forall>p \<in> ?PU - {id}. ?pp p = 0"  by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   216
  from setsum_mono_zero_cong_left[OF fPU id0 p0] show ?thesis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   217
    unfolding det_def by (simp add: sign_id)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   218
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   219
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   220
lemma det_I: "det (mat 1 :: 'a::comm_ring_1^'n^'n) = 1"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   221
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   222
  let ?A = "mat 1 :: 'a::comm_ring_1^'n^'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   223
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   224
  let ?f = "\<lambda>i j. ?A$i$j"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   225
  {fix i assume i: "i \<in> ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   226
    have "?f i i = 1" using i by (vector mat_def)}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   227
  hence th: "setprod (\<lambda>i. ?f i i) ?U = setprod (\<lambda>x. 1) ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   228
    by (auto intro: setprod_cong)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   229
  {fix i j assume i: "i \<in> ?U" and j: "j \<in> ?U" and ij: "i \<noteq> j"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   230
    have "?f i j = 0" using i j ij by (vector mat_def) }
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   231
  then have "det ?A = setprod (\<lambda>i. ?f i i) ?U" using det_diagonal
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   232
    by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   233
  also have "\<dots> = 1" unfolding th setprod_1 ..
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   234
  finally show ?thesis .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   235
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   236
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   237
lemma det_0: "det (mat 0 :: 'a::comm_ring_1^'n^'n) = 0"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   238
  by (simp add: det_def setprod_zero)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   239
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   240
lemma det_permute_rows:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   241
  fixes A :: "'a::comm_ring_1^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   242
  assumes p: "p permutes (UNIV :: 'n::finite set)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   243
  shows "det(\<chi> i. A$p i :: 'a^'n^'n) = of_int (sign p) * det A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   244
  apply (simp add: det_def setsum_right_distrib mult_assoc[symmetric])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   245
  apply (subst sum_permutations_compose_right[OF p])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   246
proof(rule setsum_cong2)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   247
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   248
  let ?PU = "{p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   249
  fix q assume qPU: "q \<in> ?PU"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   250
  have fU: "finite ?U" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   251
  from qPU have q: "q permutes ?U" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   252
  from p q have pp: "permutation p" and qp: "permutation q"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   253
    by (metis fU permutation_permutes)+
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   254
  from permutes_inv[OF p] have ip: "inv p permutes ?U" .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   255
    have "setprod (\<lambda>i. A$p i$ (q o p) i) ?U = setprod ((\<lambda>i. A$p i$(q o p) i) o inv p) ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   256
      by (simp only: setprod_permute[OF ip, symmetric])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   257
    also have "\<dots> = setprod (\<lambda>i. A $ (p o inv p) i $ (q o (p o inv p)) i) ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   258
      by (simp only: o_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   259
    also have "\<dots> = setprod (\<lambda>i. A$i$q i) ?U" by (simp only: o_def permutes_inverses[OF p])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   260
    finally   have thp: "setprod (\<lambda>i. A$p i$ (q o p) i) ?U = setprod (\<lambda>i. A$i$q i) ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   261
      by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   262
  show "of_int (sign (q o p)) * setprod (\<lambda>i. A$ p i$ (q o p) i) ?U = of_int (sign p) * of_int (sign q) * setprod (\<lambda>i. A$i$q i) ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   263
    by (simp only: thp sign_compose[OF qp pp] mult_commute of_int_mult)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   264
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   265
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   266
lemma det_permute_columns:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   267
  fixes A :: "'a::comm_ring_1^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   268
  assumes p: "p permutes (UNIV :: 'n set)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   269
  shows "det(\<chi> i j. A$i$ p j :: 'a^'n^'n) = of_int (sign p) * det A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   270
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   271
  let ?Ap = "\<chi> i j. A$i$ p j :: 'a^'n^'n"
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   272
  let ?At = "transpose A"
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   273
  have "of_int (sign p) * det A = det (transpose (\<chi> i. transpose A $ p i))"
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   274
    unfolding det_permute_rows[OF p, of ?At] det_transpose ..
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   275
  moreover
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   276
  have "?Ap = transpose (\<chi> i. transpose A $ p i)"
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   277
    by (simp add: transpose_def vec_eq_iff)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   278
  ultimately show ?thesis by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   279
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   280
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   281
lemma det_identical_rows:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34291
diff changeset
   282
  fixes A :: "'a::linordered_idom^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   283
  assumes ij: "i \<noteq> j"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   284
  and r: "row i A = row j A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   285
  shows "det A = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   286
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   287
  have tha: "\<And>(a::'a) b. a = b ==> b = - a ==> a = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   288
    by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 44457
diff changeset
   289
  have th1: "of_int (-1) = - 1" by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   290
  let ?p = "Fun.swap i j id"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   291
  let ?A = "\<chi> i. A $ ?p i"
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   292
  from r have "A = ?A" by (simp add: vec_eq_iff row_def swap_def)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   293
  hence "det A = det ?A" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   294
  moreover have "det A = - det ?A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   295
    by (simp add: det_permute_rows[OF permutes_swap_id] sign_swap_id ij th1)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   296
  ultimately show "det A = 0" by (metis tha)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   297
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   298
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   299
lemma det_identical_columns:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34291
diff changeset
   300
  fixes A :: "'a::linordered_idom^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   301
  assumes ij: "i \<noteq> j"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   302
  and r: "column i A = column j A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   303
  shows "det A = 0"
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   304
apply (subst det_transpose[symmetric])
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   305
apply (rule det_identical_rows[OF ij])
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   306
by (metis row_transpose r)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   307
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   308
lemma det_zero_row:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   309
  fixes A :: "'a::{idom, ring_char_0}^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   310
  assumes r: "row i A = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   311
  shows "det A = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   312
using r
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   313
apply (simp add: row_def det_def vec_eq_iff)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   314
apply (rule setsum_0')
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   315
apply (auto simp: sign_nz)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   316
done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   317
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   318
lemma det_zero_column:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   319
  fixes A :: "'a::{idom,ring_char_0}^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   320
  assumes r: "column i A = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   321
  shows "det A = 0"
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   322
  apply (subst det_transpose[symmetric])
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   323
  apply (rule det_zero_row [of i])
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   324
  by (metis row_transpose r)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   325
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   326
lemma det_row_add:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   327
  fixes a b c :: "'n::finite \<Rightarrow> _ ^ 'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   328
  shows "det((\<chi> i. if i = k then a i + b i else c i)::'a::comm_ring_1^'n^'n) =
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   329
             det((\<chi> i. if i = k then a i else c i)::'a::comm_ring_1^'n^'n) +
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   330
             det((\<chi> i. if i = k then b i else c i)::'a::comm_ring_1^'n^'n)"
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   331
unfolding det_def vec_lambda_beta setsum_addf[symmetric]
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   332
proof (rule setsum_cong2)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   333
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   334
  let ?pU = "{p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   335
  let ?f = "(\<lambda>i. if i = k then a i + b i else c i)::'n \<Rightarrow> 'a::comm_ring_1^'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   336
  let ?g = "(\<lambda> i. if i = k then a i else c i)::'n \<Rightarrow> 'a::comm_ring_1^'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   337
  let ?h = "(\<lambda> i. if i = k then b i else c i)::'n \<Rightarrow> 'a::comm_ring_1^'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   338
  fix p assume p: "p \<in> ?pU"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   339
  let ?Uk = "?U - {k}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   340
  from p have pU: "p permutes ?U" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   341
  have kU: "?U = insert k ?Uk" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   342
  {fix j assume j: "j \<in> ?Uk"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   343
    from j have "?f j $ p j = ?g j $ p j" and "?f j $ p j= ?h j $ p j"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   344
      by simp_all}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   345
  then have th1: "setprod (\<lambda>i. ?f i $ p i) ?Uk = setprod (\<lambda>i. ?g i $ p i) ?Uk"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   346
    and th2: "setprod (\<lambda>i. ?f i $ p i) ?Uk = setprod (\<lambda>i. ?h i $ p i) ?Uk"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   347
    apply -
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   348
    apply (rule setprod_cong, simp_all)+
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   349
    done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   350
  have th3: "finite ?Uk" "k \<notin> ?Uk" by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   351
  have "setprod (\<lambda>i. ?f i $ p i) ?U = setprod (\<lambda>i. ?f i $ p i) (insert k ?Uk)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   352
    unfolding kU[symmetric] ..
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   353
  also have "\<dots> = ?f k $ p k  * setprod (\<lambda>i. ?f i $ p i) ?Uk"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   354
    apply (rule setprod_insert)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   355
    apply simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   356
    by blast
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35542
diff changeset
   357
  also have "\<dots> = (a k $ p k * setprod (\<lambda>i. ?f i $ p i) ?Uk) + (b k$ p k * setprod (\<lambda>i. ?f i $ p i) ?Uk)" by (simp add: field_simps)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   358
  also have "\<dots> = (a k $ p k * setprod (\<lambda>i. ?g i $ p i) ?Uk) + (b k$ p k * setprod (\<lambda>i. ?h i $ p i) ?Uk)" by (metis th1 th2)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   359
  also have "\<dots> = setprod (\<lambda>i. ?g i $ p i) (insert k ?Uk) + setprod (\<lambda>i. ?h i $ p i) (insert k ?Uk)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   360
    unfolding  setprod_insert[OF th3] by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   361
  finally have "setprod (\<lambda>i. ?f i $ p i) ?U = setprod (\<lambda>i. ?g i $ p i) ?U + setprod (\<lambda>i. ?h i $ p i) ?U" unfolding kU[symmetric] .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   362
  then show "of_int (sign p) * setprod (\<lambda>i. ?f i $ p i) ?U = of_int (sign p) * setprod (\<lambda>i. ?g i $ p i) ?U + of_int (sign p) * setprod (\<lambda>i. ?h i $ p i) ?U"
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35542
diff changeset
   363
    by (simp add: field_simps)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   364
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   365
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   366
lemma det_row_mul:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   367
  fixes a b :: "'n::finite \<Rightarrow> _ ^ 'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   368
  shows "det((\<chi> i. if i = k then c *s a i else b i)::'a::comm_ring_1^'n^'n) =
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   369
             c* det((\<chi> i. if i = k then a i else b i)::'a::comm_ring_1^'n^'n)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   370
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   371
unfolding det_def vec_lambda_beta setsum_right_distrib
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   372
proof (rule setsum_cong2)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   373
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   374
  let ?pU = "{p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   375
  let ?f = "(\<lambda>i. if i = k then c*s a i else b i)::'n \<Rightarrow> 'a::comm_ring_1^'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   376
  let ?g = "(\<lambda> i. if i = k then a i else b i)::'n \<Rightarrow> 'a::comm_ring_1^'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   377
  fix p assume p: "p \<in> ?pU"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   378
  let ?Uk = "?U - {k}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   379
  from p have pU: "p permutes ?U" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   380
  have kU: "?U = insert k ?Uk" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   381
  {fix j assume j: "j \<in> ?Uk"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   382
    from j have "?f j $ p j = ?g j $ p j" by simp}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   383
  then have th1: "setprod (\<lambda>i. ?f i $ p i) ?Uk = setprod (\<lambda>i. ?g i $ p i) ?Uk"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   384
    apply -
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   385
    apply (rule setprod_cong, simp_all)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   386
    done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   387
  have th3: "finite ?Uk" "k \<notin> ?Uk" by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   388
  have "setprod (\<lambda>i. ?f i $ p i) ?U = setprod (\<lambda>i. ?f i $ p i) (insert k ?Uk)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   389
    unfolding kU[symmetric] ..
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   390
  also have "\<dots> = ?f k $ p k  * setprod (\<lambda>i. ?f i $ p i) ?Uk"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   391
    apply (rule setprod_insert)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   392
    apply simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   393
    by blast
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35542
diff changeset
   394
  also have "\<dots> = (c*s a k) $ p k * setprod (\<lambda>i. ?f i $ p i) ?Uk" by (simp add: field_simps)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   395
  also have "\<dots> = c* (a k $ p k * setprod (\<lambda>i. ?g i $ p i) ?Uk)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   396
    unfolding th1 by (simp add: mult_ac)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   397
  also have "\<dots> = c* (setprod (\<lambda>i. ?g i $ p i) (insert k ?Uk))"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   398
    unfolding  setprod_insert[OF th3] by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   399
  finally have "setprod (\<lambda>i. ?f i $ p i) ?U = c* (setprod (\<lambda>i. ?g i $ p i) ?U)" unfolding kU[symmetric] .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   400
  then show "of_int (sign p) * setprod (\<lambda>i. ?f i $ p i) ?U = c * (of_int (sign p) * setprod (\<lambda>i. ?g i $ p i) ?U)"
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35542
diff changeset
   401
    by (simp add: field_simps)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   402
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   403
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   404
lemma det_row_0:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   405
  fixes b :: "'n::finite \<Rightarrow> _ ^ 'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   406
  shows "det((\<chi> i. if i = k then 0 else b i)::'a::comm_ring_1^'n^'n) = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   407
using det_row_mul[of k 0 "\<lambda>i. 1" b]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   408
apply (simp)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   409
  unfolding vector_smult_lzero .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   410
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   411
lemma det_row_operation:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34291
diff changeset
   412
  fixes A :: "'a::linordered_idom^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   413
  assumes ij: "i \<noteq> j"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   414
  shows "det (\<chi> k. if k = i then row i A + c *s row j A else row k A) = det A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   415
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   416
  let ?Z = "(\<chi> k. if k = i then row j A else row k A) :: 'a ^'n^'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   417
  have th: "row i ?Z = row j ?Z" by (vector row_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   418
  have th2: "((\<chi> k. if k = i then row i A else row k A) :: 'a^'n^'n) = A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   419
    by (vector row_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   420
  show ?thesis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   421
    unfolding det_row_add [of i] det_row_mul[of i] det_identical_rows[OF ij th] th2
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   422
    by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   423
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   424
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   425
lemma det_row_span:
36593
fb69c8cd27bd define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents: 36585
diff changeset
   426
  fixes A :: "real^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   427
  assumes x: "x \<in> span {row j A |j. j \<noteq> i}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   428
  shows "det (\<chi> k. if k = i then row i A + x else row k A) = det A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   429
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   430
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   431
  let ?S = "{row j A |j. j \<noteq> i}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   432
  let ?d = "\<lambda>x. det (\<chi> k. if k = i then x else row k A)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   433
  let ?P = "\<lambda>x. ?d (row i A + x) = det A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   434
  {fix k
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   435
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   436
    have "(if k = i then row i A + 0 else row k A) = row k A" by simp}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   437
  then have P0: "?P 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   438
    apply -
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   439
    apply (rule cong[of det, OF refl])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   440
    by (vector row_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   441
  moreover
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   442
  {fix c z y assume zS: "z \<in> ?S" and Py: "?P y"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   443
    from zS obtain j where j: "z = row j A" "i \<noteq> j" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   444
    let ?w = "row i A + y"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   445
    have th0: "row i A + (c*s z + y) = ?w + c*s z" by vector
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   446
    have thz: "?d z = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   447
      apply (rule det_identical_rows[OF j(2)])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   448
      using j by (vector row_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   449
    have "?d (row i A + (c*s z + y)) = ?d (?w + c*s z)" unfolding th0 ..
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   450
    then have "?P (c*s z + y)" unfolding thz Py det_row_mul[of i] det_row_add[of i]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   451
      by simp }
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   452
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   453
  ultimately show ?thesis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   454
    apply -
36593
fb69c8cd27bd define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents: 36585
diff changeset
   455
    apply (rule span_induct_alt[of ?P ?S, OF P0, folded smult_conv_scaleR])
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   456
    apply blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   457
    apply (rule x)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   458
    done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   459
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   460
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   461
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   462
(* May as well do this, though it's a bit unsatisfactory since it ignores    *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   463
(* exact duplicates by considering the rows/columns as a set.                *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   464
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   465
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   466
lemma det_dependent_rows:
36593
fb69c8cd27bd define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents: 36585
diff changeset
   467
  fixes A:: "real^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   468
  assumes d: "dependent (rows A)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   469
  shows "det A = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   470
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   471
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   472
  from d obtain i where i: "row i A \<in> span (rows A - {row i A})"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   473
    unfolding dependent_def rows_def by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   474
  {fix j k assume jk: "j \<noteq> k"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   475
    and c: "row j A = row k A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   476
    from det_identical_rows[OF jk c] have ?thesis .}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   477
  moreover
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   478
  {assume H: "\<And> i j. i \<noteq> j \<Longrightarrow> row i A \<noteq> row j A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   479
    have th0: "- row i A \<in> span {row j A|j. j \<noteq> i}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   480
      apply (rule span_neg)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   481
      apply (rule set_rev_mp)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   482
      apply (rule i)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   483
      apply (rule span_mono)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   484
      using H i by (auto simp add: rows_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   485
    from det_row_span[OF th0]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   486
    have "det A = det (\<chi> k. if k = i then 0 *s 1 else row k A)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   487
      unfolding right_minus vector_smult_lzero ..
36593
fb69c8cd27bd define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents: 36585
diff changeset
   488
    with det_row_mul[of i "0::real" "\<lambda>i. 1"]
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   489
    have "det A = 0" by simp}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   490
  ultimately show ?thesis by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   491
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   492
36593
fb69c8cd27bd define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents: 36585
diff changeset
   493
lemma det_dependent_columns: assumes d: "dependent(columns (A::real^'n^'n))" shows "det A = 0"
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   494
by (metis d det_dependent_rows rows_transpose det_transpose)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   495
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   496
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   497
(* Multilinearity and the multiplication formula.                            *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   498
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   499
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   500
lemma Cart_lambda_cong: "(\<And>x. f x = g x) \<Longrightarrow> (vec_lambda f::'a^'n) = (vec_lambda g :: 'a^'n)"
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   501
  apply (rule iffD1[OF vec_lambda_unique]) by vector
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   502
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   503
lemma det_linear_row_setsum:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   504
  assumes fS: "finite S"
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   505
  shows "det ((\<chi> i. if i = k then setsum (a i) S else c i)::'a::comm_ring_1^'n^'n) = setsum (\<lambda>j. det ((\<chi> i. if i = k then a  i j else c i)::'a^'n^'n)) S"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   506
proof(induct rule: finite_induct[OF fS])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   507
  case 1 thus ?case apply simp  unfolding setsum_empty det_row_0[of k] ..
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   508
next
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   509
  case (2 x F)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   510
  then  show ?case by (simp add: det_row_add cong del: if_weak_cong)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   511
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   512
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   513
lemma finite_bounded_functions:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   514
  assumes fS: "finite S"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   515
  shows "finite {f. (\<forall>i \<in> {1.. (k::nat)}. f i \<in> S) \<and> (\<forall>i. i \<notin> {1 .. k} \<longrightarrow> f i = i)}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   516
proof(induct k)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   517
  case 0
44457
d366fa5551ef declare euclidean_simps [simp] at the point they are proved;
huffman
parents: 44260
diff changeset
   518
  have th: "{f. \<forall>i. f i = i} = {id}" by auto
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   519
  show ?case by (auto simp add: th)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   520
next
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   521
  case (Suc k)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   522
  let ?f = "\<lambda>(y::nat,g) i. if i = Suc k then y else g i"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   523
  let ?S = "?f ` (S \<times> {f. (\<forall>i\<in>{1..k}. f i \<in> S) \<and> (\<forall>i. i \<notin> {1..k} \<longrightarrow> f i = i)})"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   524
  have "?S = {f. (\<forall>i\<in>{1.. Suc k}. f i \<in> S) \<and> (\<forall>i. i \<notin> {1.. Suc k} \<longrightarrow> f i = i)}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   525
    apply (auto simp add: image_iff)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   526
    apply (rule_tac x="x (Suc k)" in bexI)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   527
    apply (rule_tac x = "\<lambda>i. if i = Suc k then i else x i" in exI)
44457
d366fa5551ef declare euclidean_simps [simp] at the point they are proved;
huffman
parents: 44260
diff changeset
   528
    apply auto
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   529
    done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   530
  with finite_imageI[OF finite_cartesian_product[OF fS Suc.hyps(1)], of ?f]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   531
  show ?case by metis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   532
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   533
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   534
44457
d366fa5551ef declare euclidean_simps [simp] at the point they are proved;
huffman
parents: 44260
diff changeset
   535
lemma eq_id_iff[simp]: "(\<forall>x. f x = x) = (f = id)" by auto
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   536
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   537
lemma det_linear_rows_setsum_lemma:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   538
  assumes fS: "finite S" and fT: "finite T"
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   539
  shows "det((\<chi> i. if i \<in> T then setsum (a i) S else c i):: 'a::comm_ring_1^'n^'n) =
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   540
             setsum (\<lambda>f. det((\<chi> i. if i \<in> T then a i (f i) else c i)::'a^'n^'n))
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   541
                 {f. (\<forall>i \<in> T. f i \<in> S) \<and> (\<forall>i. i \<notin> T \<longrightarrow> f i = i)}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   542
using fT
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   543
proof(induct T arbitrary: a c set: finite)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   544
  case empty
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   545
  have th0: "\<And>x y. (\<chi> i. if i \<in> {} then x i else y i) = (\<chi> i. y i)" by vector
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   546
  from "empty.prems"  show ?case unfolding th0 by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   547
next
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   548
  case (insert z T a c)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   549
  let ?F = "\<lambda>T. {f. (\<forall>i \<in> T. f i \<in> S) \<and> (\<forall>i. i \<notin> T \<longrightarrow> f i = i)}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   550
  let ?h = "\<lambda>(y,g) i. if i = z then y else g i"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   551
  let ?k = "\<lambda>h. (h(z),(\<lambda>i. if i = z then i else h i))"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   552
  let ?s = "\<lambda> k a c f. det((\<chi> i. if i \<in> T then a i (f i) else c i)::'a^'n^'n)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   553
  let ?c = "\<lambda>i. if i = z then a i j else c i"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   554
  have thif: "\<And>a b c d. (if a \<or> b then c else d) = (if a then c else if b then c else d)" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   555
  have thif2: "\<And>a b c d e. (if a then b else if c then d else e) =
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   556
     (if c then (if a then b else d) else (if a then b else e))" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   557
  from `z \<notin> T` have nz: "\<And>i. i \<in> T \<Longrightarrow> i = z \<longleftrightarrow> False" by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   558
  have "det (\<chi> i. if i \<in> insert z T then setsum (a i) S else c i) =
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   559
        det (\<chi> i. if i = z then setsum (a i) S
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   560
                 else if i \<in> T then setsum (a i) S else c i)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   561
    unfolding insert_iff thif ..
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   562
  also have "\<dots> = (\<Sum>j\<in>S. det (\<chi> i. if i \<in> T then setsum (a i) S
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   563
                    else if i = z then a i j else c i))"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   564
    unfolding det_linear_row_setsum[OF fS]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   565
    apply (subst thif2)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   566
    using nz by (simp cong del: if_weak_cong cong add: if_cong)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   567
  finally have tha:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   568
    "det (\<chi> i. if i \<in> insert z T then setsum (a i) S else c i) =
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   569
     (\<Sum>(j, f)\<in>S \<times> ?F T. det (\<chi> i. if i \<in> T then a i (f i)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   570
                                else if i = z then a i j
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   571
                                else c i))"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   572
    unfolding  insert.hyps unfolding setsum_cartesian_product by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   573
  show ?case unfolding tha
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   574
    apply(rule setsum_eq_general_reverses[where h= "?h" and k= "?k"],
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   575
      blast intro: finite_cartesian_product fS finite,
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   576
      blast intro: finite_cartesian_product fS finite)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   577
    using `z \<notin> T`
44457
d366fa5551ef declare euclidean_simps [simp] at the point they are proved;
huffman
parents: 44260
diff changeset
   578
    apply auto
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   579
    apply (rule cong[OF refl[of det]])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   580
    by vector
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   581
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   582
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   583
lemma det_linear_rows_setsum:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   584
  assumes fS: "finite (S::'n::finite set)"
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   585
  shows "det (\<chi> i. setsum (a i) S) = setsum (\<lambda>f. det (\<chi> i. a i (f i) :: 'a::comm_ring_1 ^ 'n^'n)) {f. \<forall>i. f i \<in> S}"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   586
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   587
  have th0: "\<And>x y. ((\<chi> i. if i \<in> (UNIV:: 'n set) then x i else y i) :: 'a^'n^'n) = (\<chi> i. x i)" by vector
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   588
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   589
  from det_linear_rows_setsum_lemma[OF fS, of "UNIV :: 'n set" a, unfolded th0, OF finite] show ?thesis by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   590
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   591
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   592
lemma matrix_mul_setsum_alt:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   593
  fixes A B :: "'a::comm_ring_1^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   594
  shows "A ** B = (\<chi> i. setsum (\<lambda>k. A$i$k *s B $ k) (UNIV :: 'n set))"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   595
  by (vector matrix_matrix_mult_def setsum_component)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   596
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   597
lemma det_rows_mul:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   598
  "det((\<chi> i. c i *s a i)::'a::comm_ring_1^'n^'n) =
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   599
  setprod (\<lambda>i. c i) (UNIV:: 'n set) * det((\<chi> i. a i)::'a^'n^'n)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   600
proof (simp add: det_def setsum_right_distrib cong add: setprod_cong, rule setsum_cong2)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   601
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   602
  let ?PU = "{p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   603
  fix p assume pU: "p \<in> ?PU"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   604
  let ?s = "of_int (sign p)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   605
  from pU have p: "p permutes ?U" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   606
  have "setprod (\<lambda>i. c i * a i $ p i) ?U = setprod c ?U * setprod (\<lambda>i. a i $ p i) ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   607
    unfolding setprod_timesf ..
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   608
  then show "?s * (\<Prod>xa\<in>?U. c xa * a xa $ p xa) =
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35542
diff changeset
   609
        setprod c ?U * (?s* (\<Prod>xa\<in>?U. a xa $ p xa))" by (simp add: field_simps)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   610
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   611
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   612
lemma det_mul:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34291
diff changeset
   613
  fixes A B :: "'a::linordered_idom^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   614
  shows "det (A ** B) = det A * det B"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   615
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   616
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   617
  let ?F = "{f. (\<forall>i\<in> ?U. f i \<in> ?U) \<and> (\<forall>i. i \<notin> ?U \<longrightarrow> f i = i)}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   618
  let ?PU = "{p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   619
  have fU: "finite ?U" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   620
  have fF: "finite ?F" by (rule finite)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   621
  {fix p assume p: "p permutes ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   622
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   623
    have "p \<in> ?F" unfolding mem_Collect_eq permutes_in_image[OF p]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   624
      using p[unfolded permutes_def] by simp}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   625
  then have PUF: "?PU \<subseteq> ?F"  by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   626
  {fix f assume fPU: "f \<in> ?F - ?PU"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   627
    have fUU: "f ` ?U \<subseteq> ?U" using fPU by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   628
    from fPU have f: "\<forall>i \<in> ?U. f i \<in> ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   629
      "\<forall>i. i \<notin> ?U \<longrightarrow> f i = i" "\<not>(\<forall>y. \<exists>!x. f x = y)" unfolding permutes_def
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   630
      by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   631
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   632
    let ?A = "(\<chi> i. A$i$f i *s B$f i) :: 'a^'n^'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   633
    let ?B = "(\<chi> i. B$f i) :: 'a^'n^'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   634
    {assume fni: "\<not> inj_on f ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   635
      then obtain i j where ij: "f i = f j" "i \<noteq> j"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   636
        unfolding inj_on_def by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   637
      from ij
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   638
      have rth: "row i ?B = row j ?B" by (vector row_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   639
      from det_identical_rows[OF ij(2) rth]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   640
      have "det (\<chi> i. A$i$f i *s B$f i) = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   641
        unfolding det_rows_mul by simp}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   642
    moreover
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   643
    {assume fi: "inj_on f ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   644
      from f fi have fith: "\<And>i j. f i = f j \<Longrightarrow> i = j"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   645
        unfolding inj_on_def by metis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   646
      note fs = fi[unfolded surjective_iff_injective_gen[OF fU fU refl fUU, symmetric]]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   647
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   648
      {fix y
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   649
        from fs f have "\<exists>x. f x = y" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   650
        then obtain x where x: "f x = y" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   651
        {fix z assume z: "f z = y" from fith x z have "z = x" by metis}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   652
        with x have "\<exists>!x. f x = y" by blast}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   653
      with f(3) have "det (\<chi> i. A$i$f i *s B$f i) = 0" by blast}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   654
    ultimately have "det (\<chi> i. A$i$f i *s B$f i) = 0" by blast}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   655
  hence zth: "\<forall> f\<in> ?F - ?PU. det (\<chi> i. A$i$f i *s B$f i) = 0" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   656
  {fix p assume pU: "p \<in> ?PU"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   657
    from pU have p: "p permutes ?U" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   658
    let ?s = "\<lambda>p. of_int (sign p)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   659
    let ?f = "\<lambda>q. ?s p * (\<Prod>i\<in> ?U. A $ i $ p i) *
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   660
               (?s q * (\<Prod>i\<in> ?U. B $ i $ q i))"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   661
    have "(setsum (\<lambda>q. ?s q *
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   662
            (\<Prod>i\<in> ?U. (\<chi> i. A $ i $ p i *s B $ p i :: 'a^'n^'n) $ i $ q i)) ?PU) =
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   663
        (setsum (\<lambda>q. ?s p * (\<Prod>i\<in> ?U. A $ i $ p i) *
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   664
               (?s q * (\<Prod>i\<in> ?U. B $ i $ q i))) ?PU)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   665
      unfolding sum_permutations_compose_right[OF permutes_inv[OF p], of ?f]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   666
    proof(rule setsum_cong2)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   667
      fix q assume qU: "q \<in> ?PU"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   668
      hence q: "q permutes ?U" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   669
      from p q have pp: "permutation p" and pq: "permutation q"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   670
        unfolding permutation_permutes by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   671
      have th00: "of_int (sign p) * of_int (sign p) = (1::'a)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   672
        "\<And>a. of_int (sign p) * (of_int (sign p) * a) = a"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   673
        unfolding mult_assoc[symmetric] unfolding of_int_mult[symmetric]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   674
        by (simp_all add: sign_idempotent)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   675
      have ths: "?s q = ?s p * ?s (q o inv p)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   676
        using pp pq permutation_inverse[OF pp] sign_inverse[OF pp]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   677
        by (simp add:  th00 mult_ac sign_idempotent sign_compose)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   678
      have th001: "setprod (\<lambda>i. B$i$ q (inv p i)) ?U = setprod ((\<lambda>i. B$i$ q (inv p i)) o p) ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   679
        by (rule setprod_permute[OF p])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   680
      have thp: "setprod (\<lambda>i. (\<chi> i. A$i$p i *s B$p i :: 'a^'n^'n) $i $ q i) ?U = setprod (\<lambda>i. A$i$p i) ?U * setprod (\<lambda>i. B$i$ q (inv p i)) ?U"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   681
        unfolding th001 setprod_timesf[symmetric] o_def permutes_inverses[OF p]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   682
        apply (rule setprod_cong[OF refl])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   683
        using permutes_in_image[OF q] by vector
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   684
      show "?s q * setprod (\<lambda>i. (((\<chi> i. A$i$p i *s B$p i) :: 'a^'n^'n)$i$q i)) ?U = ?s p * (setprod (\<lambda>i. A$i$p i) ?U) * (?s (q o inv p) * setprod (\<lambda>i. B$i$(q o inv p) i) ?U)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   685
        using ths thp pp pq permutation_inverse[OF pp] sign_inverse[OF pp]
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35542
diff changeset
   686
        by (simp add: sign_nz th00 field_simps sign_idempotent sign_compose)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   687
    qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   688
  }
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   689
  then have th2: "setsum (\<lambda>f. det (\<chi> i. A$i$f i *s B$f i)) ?PU = det A * det B"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   690
    unfolding det_def setsum_product
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   691
    by (rule setsum_cong2)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   692
  have "det (A**B) = setsum (\<lambda>f.  det (\<chi> i. A $ i $ f i *s B $ f i)) ?F"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   693
    unfolding matrix_mul_setsum_alt det_linear_rows_setsum[OF fU] by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   694
  also have "\<dots> = setsum (\<lambda>f. det (\<chi> i. A$i$f i *s B$f i)) ?PU"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   695
    using setsum_mono_zero_cong_left[OF fF PUF zth, symmetric]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   696
    unfolding det_rows_mul by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   697
  finally show ?thesis unfolding th2 .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   698
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   699
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   700
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   701
(* Relation to invertibility.                                                *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   702
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   703
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   704
lemma invertible_left_inverse:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   705
  fixes A :: "real^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   706
  shows "invertible A \<longleftrightarrow> (\<exists>(B::real^'n^'n). B** A = mat 1)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   707
  by (metis invertible_def matrix_left_right_inverse)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   708
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   709
lemma invertible_righ_inverse:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   710
  fixes A :: "real^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   711
  shows "invertible A \<longleftrightarrow> (\<exists>(B::real^'n^'n). A** B = mat 1)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   712
  by (metis invertible_def matrix_left_right_inverse)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   713
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   714
lemma invertible_det_nz:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   715
  fixes A::"real ^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   716
  shows "invertible A \<longleftrightarrow> det A \<noteq> 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   717
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   718
  {assume "invertible A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   719
    then obtain B :: "real ^'n^'n" where B: "A ** B = mat 1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   720
      unfolding invertible_righ_inverse by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   721
    hence "det (A ** B) = det (mat 1 :: real ^'n^'n)" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   722
    hence "det A \<noteq> 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   723
      apply (simp add: det_mul det_I) by algebra }
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   724
  moreover
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   725
  {assume H: "\<not> invertible A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   726
    let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   727
    have fU: "finite ?U" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   728
    from H obtain c i where c: "setsum (\<lambda>i. c i *s row i A) ?U = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   729
      and iU: "i \<in> ?U" and ci: "c i \<noteq> 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   730
      unfolding invertible_righ_inverse
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   731
      unfolding matrix_right_invertible_independent_rows by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   732
    have stupid: "\<And>(a::real^'n) b. a + b = 0 \<Longrightarrow> -a = b"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   733
      apply (drule_tac f="op + (- a)" in cong[OF refl])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   734
      apply (simp only: ab_left_minus add_assoc[symmetric])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   735
      apply simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   736
      done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   737
    from c ci
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   738
    have thr0: "- row i A = setsum (\<lambda>j. (1/ c i) *s (c j *s row j A)) (?U - {i})"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   739
      unfolding setsum_diff1'[OF fU iU] setsum_cmul
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   740
      apply -
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   741
      apply (rule vector_mul_lcancel_imp[OF ci])
44457
d366fa5551ef declare euclidean_simps [simp] at the point they are proved;
huffman
parents: 44260
diff changeset
   742
      apply (auto simp add: field_simps)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   743
      unfolding stupid ..
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   744
    have thr: "- row i A \<in> span {row j A| j. j \<noteq> i}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   745
      unfolding thr0
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   746
      apply (rule span_setsum)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   747
      apply simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   748
      apply (rule ballI)
36593
fb69c8cd27bd define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents: 36585
diff changeset
   749
      apply (rule span_mul [where 'a="real^'n", folded smult_conv_scaleR])+
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   750
      apply (rule span_superset)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   751
      apply auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   752
      done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   753
    let ?B = "(\<chi> k. if k = i then 0 else row k A) :: real ^'n^'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   754
    have thrb: "row i ?B = 0" using iU by (vector row_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   755
    have "det A = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   756
      unfolding det_row_span[OF thr, symmetric] right_minus
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   757
      unfolding  det_zero_row[OF thrb]  ..}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   758
  ultimately show ?thesis by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   759
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   760
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   761
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   762
(* Cramer's rule.                                                            *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   763
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   764
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   765
lemma cramer_lemma_transpose:
36593
fb69c8cd27bd define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents: 36585
diff changeset
   766
  fixes A:: "real^'n^'n" and x :: "real^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   767
  shows "det ((\<chi> i. if i = k then setsum (\<lambda>i. x$i *s row i A) (UNIV::'n set)
36593
fb69c8cd27bd define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents: 36585
diff changeset
   768
                           else row i A)::real^'n^'n) = x$k * det A"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   769
  (is "?lhs = ?rhs")
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   770
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   771
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   772
  let ?Uk = "?U - {k}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   773
  have U: "?U = insert k ?Uk" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   774
  have fUk: "finite ?Uk" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   775
  have kUk: "k \<notin> ?Uk" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   776
  have th00: "\<And>k s. x$k *s row k A + s = (x$k - 1) *s row k A + row k A + s"
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35542
diff changeset
   777
    by (vector field_simps)
44457
d366fa5551ef declare euclidean_simps [simp] at the point they are proved;
huffman
parents: 44260
diff changeset
   778
  have th001: "\<And>f k . (\<lambda>x. if x = k then f k else f x) = f" by auto
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   779
  have "(\<chi> i. row i A) = A" by (vector row_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   780
  then have thd1: "det (\<chi> i. row i A) = det A"  by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   781
  have thd0: "det (\<chi> i. if i = k then row k A + (\<Sum>i \<in> ?Uk. x $ i *s row i A) else row i A) = det A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   782
    apply (rule det_row_span)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   783
    apply (rule span_setsum[OF fUk])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   784
    apply (rule ballI)
36593
fb69c8cd27bd define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents: 36585
diff changeset
   785
    apply (rule span_mul [where 'a="real^'n", folded smult_conv_scaleR])+
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   786
    apply (rule span_superset)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   787
    apply auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   788
    done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   789
  show "?lhs = x$k * det A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   790
    apply (subst U)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   791
    unfolding setsum_insert[OF fUk kUk]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   792
    apply (subst th00)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   793
    unfolding add_assoc
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   794
    apply (subst det_row_add)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   795
    unfolding thd0
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   796
    unfolding det_row_mul
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   797
    unfolding th001[of k "\<lambda>i. row i A"]
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35542
diff changeset
   798
    unfolding thd1  by (simp add: field_simps)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   799
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   800
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   801
lemma cramer_lemma:
36593
fb69c8cd27bd define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents: 36585
diff changeset
   802
  fixes A :: "real^'n^'n"
fb69c8cd27bd define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents: 36585
diff changeset
   803
  shows "det((\<chi> i j. if j = k then (A *v x)$i else A$i$j):: real^'n^'n) = x$k * det A"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   804
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   805
  let ?U = "UNIV :: 'n set"
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   806
  have stupid: "\<And>c. setsum (\<lambda>i. c i *s row i (transpose A)) ?U = setsum (\<lambda>i. c i *s column i A) ?U"
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   807
    by (auto simp add: row_transpose intro: setsum_cong2)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   808
  show ?thesis  unfolding matrix_mult_vsum
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   809
  unfolding cramer_lemma_transpose[of k x "transpose A", unfolded det_transpose, symmetric]
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   810
  unfolding stupid[of "\<lambda>i. x$i"]
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   811
  apply (subst det_transpose[symmetric])
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   812
  apply (rule cong[OF refl[of det]]) by (vector transpose_def column_def row_def)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   813
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   814
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   815
lemma cramer:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   816
  fixes A ::"real^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   817
  assumes d0: "det A \<noteq> 0"
36362
06475a1547cb fix lots of looping simp calls and other warnings
huffman
parents: 35542
diff changeset
   818
  shows "A *v x = b \<longleftrightarrow> x = (\<chi> k. det(\<chi> i j. if j=k then b$i else A$i$j) / det A)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   819
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   820
  from d0 obtain B where B: "A ** B = mat 1" "B ** A = mat 1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   821
    unfolding invertible_det_nz[symmetric] invertible_def by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   822
  have "(A ** B) *v b = b" by (simp add: B matrix_vector_mul_lid)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   823
  hence "A *v (B *v b) = b" by (simp add: matrix_vector_mul_assoc)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   824
  then have xe: "\<exists>x. A*v x = b" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   825
  {fix x assume x: "A *v x = b"
36362
06475a1547cb fix lots of looping simp calls and other warnings
huffman
parents: 35542
diff changeset
   826
  have "x = (\<chi> k. det(\<chi> i j. if j=k then b$i else A$i$j) / det A)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   827
    unfolding x[symmetric]
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   828
    using d0 by (simp add: vec_eq_iff cramer_lemma field_simps)}
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   829
  with xe show ?thesis by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   830
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   831
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   832
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   833
(* Orthogonality of a transformation and matrix.                             *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   834
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   835
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   836
definition "orthogonal_transformation f \<longleftrightarrow> linear f \<and> (\<forall>v w. f v \<bullet> f w = v \<bullet> w)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   837
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   838
lemma orthogonal_transformation: "orthogonal_transformation f \<longleftrightarrow> linear f \<and> (\<forall>(v::real ^_). norm (f v) = norm v)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   839
  unfolding orthogonal_transformation_def
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   840
  apply auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   841
  apply (erule_tac x=v in allE)+
35542
8f97d8caabfd replaced \<bullet> with inner
himmelma
parents: 35150
diff changeset
   842
  apply (simp add: norm_eq_sqrt_inner)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   843
  by (simp add: dot_norm  linear_add[symmetric])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   844
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   845
definition "orthogonal_matrix (Q::'a::semiring_1^'n^'n) \<longleftrightarrow> transpose Q ** Q = mat 1 \<and> Q ** transpose Q = mat 1"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   846
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   847
lemma orthogonal_matrix: "orthogonal_matrix (Q:: real ^'n^'n)  \<longleftrightarrow> transpose Q ** Q = mat 1"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   848
  by (metis matrix_left_right_inverse orthogonal_matrix_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   849
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   850
lemma orthogonal_matrix_id: "orthogonal_matrix (mat 1 :: _^'n^'n)"
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   851
  by (simp add: orthogonal_matrix_def transpose_mat matrix_mul_lid)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   852
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   853
lemma orthogonal_matrix_mul:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   854
  fixes A :: "real ^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   855
  assumes oA : "orthogonal_matrix A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   856
  and oB: "orthogonal_matrix B"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   857
  shows "orthogonal_matrix(A ** B)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   858
  using oA oB
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   859
  unfolding orthogonal_matrix matrix_transpose_mul
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   860
  apply (subst matrix_mul_assoc)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   861
  apply (subst matrix_mul_assoc[symmetric])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   862
  by (simp add: matrix_mul_rid)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   863
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   864
lemma orthogonal_transformation_matrix:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   865
  fixes f:: "real^'n \<Rightarrow> real^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   866
  shows "orthogonal_transformation f \<longleftrightarrow> linear f \<and> orthogonal_matrix(matrix f)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   867
  (is "?lhs \<longleftrightarrow> ?rhs")
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   868
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   869
  let ?mf = "matrix f"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   870
  let ?ot = "orthogonal_transformation f"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   871
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   872
  have fU: "finite ?U" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   873
  let ?m1 = "mat 1 :: real ^'n^'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   874
  {assume ot: ?ot
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   875
    from ot have lf: "linear f" and fd: "\<forall>v w. f v \<bullet> f w = v \<bullet> w"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   876
      unfolding  orthogonal_transformation_def orthogonal_matrix by blast+
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   877
    {fix i j
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   878
      let ?A = "transpose ?mf ** ?mf"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   879
      have th0: "\<And>b (x::'a::comm_ring_1). (if b then 1 else 0)*x = (if b then x else 0)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   880
        "\<And>b (x::'a::comm_ring_1). x*(if b then 1 else 0) = (if b then x else 0)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   881
        by simp_all
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   882
      from fd[rule_format, of "cart_basis i" "cart_basis j", unfolded matrix_works[OF lf, symmetric] dot_matrix_vector_mul]
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   883
      have "?A$i$j = ?m1 $ i $ j"
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   884
        by (simp add: inner_vec_def matrix_matrix_mult_def columnvector_def rowvector_def cart_basis_def th0 setsum_delta[OF fU] mat_def)}
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   885
    hence "orthogonal_matrix ?mf" unfolding orthogonal_matrix by vector
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   886
    with lf have ?rhs by blast}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   887
  moreover
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   888
  {assume lf: "linear f" and om: "orthogonal_matrix ?mf"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   889
    from lf om have ?lhs
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   890
      unfolding orthogonal_matrix_def norm_eq orthogonal_transformation
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   891
      unfolding matrix_works[OF lf, symmetric]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   892
      apply (subst dot_matrix_vector_mul)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   893
      by (simp add: dot_matrix_product matrix_mul_lid)}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   894
  ultimately show ?thesis by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   895
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   896
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   897
lemma det_orthogonal_matrix:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34291
diff changeset
   898
  fixes Q:: "'a::linordered_idom^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   899
  assumes oQ: "orthogonal_matrix Q"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   900
  shows "det Q = 1 \<or> det Q = - 1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   901
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   902
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   903
  have th: "\<And>x::'a. x = 1 \<or> x = - 1 \<longleftrightarrow> x*x = 1" (is "\<And>x::'a. ?ths x")
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   904
  proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   905
    fix x:: 'a
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35542
diff changeset
   906
    have th0: "x*x - 1 = (x - 1)*(x + 1)" by (simp add: field_simps)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   907
    have th1: "\<And>(x::'a) y. x = - y \<longleftrightarrow> x + y = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   908
      apply (subst eq_iff_diff_eq_0) by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   909
    have "x*x = 1 \<longleftrightarrow> x*x - 1 = 0" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   910
    also have "\<dots> \<longleftrightarrow> x = 1 \<or> x = - 1" unfolding th0 th1 by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   911
    finally show "?ths x" ..
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   912
  qed
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   913
  from oQ have "Q ** transpose Q = mat 1" by (metis orthogonal_matrix_def)
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   914
  hence "det (Q ** transpose Q) = det (mat 1:: 'a^'n^'n)" by simp
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   915
  hence "det Q * det Q = 1" by (simp add: det_mul det_I det_transpose)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   916
  then show ?thesis unfolding th .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   917
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   918
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   919
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   920
(* Linearity of scaling, and hence isometry, that preserves origin.          *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   921
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   922
lemma scaling_linear:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   923
  fixes f :: "real ^'n \<Rightarrow> real ^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   924
  assumes f0: "f 0 = 0" and fd: "\<forall>x y. dist (f x) (f y) = c * dist x y"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   925
  shows "linear f"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   926
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   927
  {fix v w
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   928
    {fix x note fd[rule_format, of x 0, unfolded dist_norm f0 diff_0_right] }
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   929
    note th0 = this
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   930
    have "f v \<bullet> f w = c^2 * (v \<bullet> w)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   931
      unfolding dot_norm_neg dist_norm[symmetric]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   932
      unfolding th0 fd[rule_format] by (simp add: power2_eq_square field_simps)}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   933
  note fc = this
44457
d366fa5551ef declare euclidean_simps [simp] at the point they are proved;
huffman
parents: 44260
diff changeset
   934
  show ?thesis unfolding linear_def vector_eq[where 'a="real^'n"] smult_conv_scaleR by (simp add: inner_add fc field_simps)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   935
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   936
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   937
lemma isometry_linear:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   938
  "f (0:: real^'n) = (0:: real^'n) \<Longrightarrow> \<forall>x y. dist(f x) (f y) = dist x y
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   939
        \<Longrightarrow> linear f"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   940
by (rule scaling_linear[where c=1]) simp_all
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   941
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   942
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   943
(* Hence another formulation of orthogonal transformation.                   *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   944
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   945
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   946
lemma orthogonal_transformation_isometry:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   947
  "orthogonal_transformation f \<longleftrightarrow> f(0::real^'n) = (0::real^'n) \<and> (\<forall>x y. dist(f x) (f y) = dist x y)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   948
  unfolding orthogonal_transformation
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   949
  apply (rule iffI)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   950
  apply clarify
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   951
  apply (clarsimp simp add: linear_0 linear_sub[symmetric] dist_norm)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   952
  apply (rule conjI)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   953
  apply (rule isometry_linear)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   954
  apply simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   955
  apply simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   956
  apply clarify
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   957
  apply (erule_tac x=v in allE)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   958
  apply (erule_tac x=0 in allE)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   959
  by (simp add: dist_norm)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   960
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   961
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   962
(* Can extend an isometry from unit sphere.                                  *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   963
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   964
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   965
lemma isometry_sphere_extend:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   966
  fixes f:: "real ^'n \<Rightarrow> real ^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   967
  assumes f1: "\<forall>x. norm x = 1 \<longrightarrow> norm (f x) = 1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   968
  and fd1: "\<forall> x y. norm x = 1 \<longrightarrow> norm y = 1 \<longrightarrow> dist (f x) (f y) = dist x y"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   969
  shows "\<exists>g. orthogonal_transformation g \<and> (\<forall>x. norm x = 1 \<longrightarrow> g x = f x)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   970
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   971
  {fix x y x' y' x0 y0 x0' y0' :: "real ^'n"
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   972
    assume H: "x = norm x *\<^sub>R x0" "y = norm y *\<^sub>R y0"
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   973
    "x' = norm x *\<^sub>R x0'" "y' = norm y *\<^sub>R y0'"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   974
    "norm x0 = 1" "norm x0' = 1" "norm y0 = 1" "norm y0' = 1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   975
    "norm(x0' - y0') = norm(x0 - y0)"
44457
d366fa5551ef declare euclidean_simps [simp] at the point they are proved;
huffman
parents: 44260
diff changeset
   976
    hence *:"x0 \<bullet> y0 = x0' \<bullet> y0' + y0' \<bullet> x0' - y0 \<bullet> x0 " by(simp add: norm_eq norm_eq_1 inner_add inner_diff)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   977
    have "norm(x' - y') = norm(x - y)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   978
      apply (subst H(1))
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   979
      apply (subst H(2))
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   980
      apply (subst H(3))
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   981
      apply (subst H(4))
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   982
      using H(5-9)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   983
      apply (simp add: norm_eq norm_eq_1)
44457
d366fa5551ef declare euclidean_simps [simp] at the point they are proved;
huffman
parents: 44260
diff changeset
   984
      apply (simp add: inner_diff smult_conv_scaleR) unfolding *
36350
bc7982c54e37 dropped group_simps, ring_simps, field_eq_simps
haftmann
parents: 35542
diff changeset
   985
      by (simp add: field_simps) }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   986
  note th0 = this
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   987
  let ?g = "\<lambda>x. if x = 0 then 0 else norm x *\<^sub>R f (inverse (norm x) *\<^sub>R x)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   988
  {fix x:: "real ^'n" assume nx: "norm x = 1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   989
    have "?g x = f x" using nx by auto}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   990
  hence thfg: "\<forall>x. norm x = 1 \<longrightarrow> ?g x = f x" by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   991
  have g0: "?g 0 = 0" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   992
  {fix x y :: "real ^'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   993
    {assume "x = 0" "y = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   994
      then have "dist (?g x) (?g y) = dist x y" by simp }
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   995
    moreover
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   996
    {assume "x = 0" "y \<noteq> 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   997
      then have "dist (?g x) (?g y) = dist x y"
36362
06475a1547cb fix lots of looping simp calls and other warnings
huffman
parents: 35542
diff changeset
   998
        apply (simp add: dist_norm)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   999
        apply (rule f1[rule_format])
36362
06475a1547cb fix lots of looping simp calls and other warnings
huffman
parents: 35542
diff changeset
  1000
        by(simp add: field_simps)}
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1001
    moreover
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1002
    {assume "x \<noteq> 0" "y = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1003
      then have "dist (?g x) (?g y) = dist x y"
36362
06475a1547cb fix lots of looping simp calls and other warnings
huffman
parents: 35542
diff changeset
  1004
        apply (simp add: dist_norm)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1005
        apply (rule f1[rule_format])
36362
06475a1547cb fix lots of looping simp calls and other warnings
huffman
parents: 35542
diff changeset
  1006
        by(simp add: field_simps)}
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1007
    moreover
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1008
    {assume z: "x \<noteq> 0" "y \<noteq> 0"
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1009
      have th00: "x = norm x *\<^sub>R (inverse (norm x) *\<^sub>R x)" "y = norm y *\<^sub>R (inverse (norm y) *\<^sub>R y)" "norm x *\<^sub>R f ((inverse (norm x) *\<^sub>R x)) = norm x *\<^sub>R f (inverse (norm x) *\<^sub>R x)"
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1010
        "norm y *\<^sub>R f (inverse (norm y) *\<^sub>R y) = norm y *\<^sub>R f (inverse (norm y) *\<^sub>R y)"
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1011
        "norm (inverse (norm x) *\<^sub>R x) = 1"
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1012
        "norm (f (inverse (norm x) *\<^sub>R x)) = 1"
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1013
        "norm (inverse (norm y) *\<^sub>R y) = 1"
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1014
        "norm (f (inverse (norm y) *\<^sub>R y)) = 1"
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1015
        "norm (f (inverse (norm x) *\<^sub>R x) - f (inverse (norm y) *\<^sub>R y)) =
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1016
        norm (inverse (norm x) *\<^sub>R x - inverse (norm y) *\<^sub>R y)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1017
        using z
44457
d366fa5551ef declare euclidean_simps [simp] at the point they are proved;
huffman
parents: 44260
diff changeset
  1018
        by (auto simp add: field_simps intro: f1[rule_format] fd1[rule_format, unfolded dist_norm])
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1019
      from z th0[OF th00] have "dist (?g x) (?g y) = dist x y"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1020
        by (simp add: dist_norm)}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1021
    ultimately have "dist (?g x) (?g y) = dist x y" by blast}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1022
  note thd = this
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1023
    show ?thesis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1024
    apply (rule exI[where x= ?g])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1025
    unfolding orthogonal_transformation_isometry
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1026
      using  g0 thfg thd by metis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1027
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1028
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1029
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1030
(* Rotation, reflection, rotoinversion.                                      *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1031
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1032
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1033
definition "rotation_matrix Q \<longleftrightarrow> orthogonal_matrix Q \<and> det Q = 1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1034
definition "rotoinversion_matrix Q \<longleftrightarrow> orthogonal_matrix Q \<and> det Q = - 1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1035
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1036
lemma orthogonal_rotation_or_rotoinversion:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34291
diff changeset
  1037
  fixes Q :: "'a::linordered_idom^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1038
  shows " orthogonal_matrix Q \<longleftrightarrow> rotation_matrix Q \<or> rotoinversion_matrix Q"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1039
  by (metis rotoinversion_matrix_def rotation_matrix_def det_orthogonal_matrix)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1040
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1041
(* Explicit formulas for low dimensions.                                     *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1042
(* ------------------------------------------------------------------------- *)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1043
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1044
lemma setprod_1: "setprod f {(1::nat)..1} = f 1" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1045
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1046
lemma setprod_2: "setprod f {(1::nat)..2} = f 1 * f 2"
40077
c8a9eaaa2f59 nat_number -> eval_nat_numeral
nipkow
parents: 39302
diff changeset
  1047
  by (simp add: eval_nat_numeral setprod_numseg mult_commute)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1048
lemma setprod_3: "setprod f {(1::nat)..3} = f 1 * f 2 * f 3"
40077
c8a9eaaa2f59 nat_number -> eval_nat_numeral
nipkow
parents: 39302
diff changeset
  1049
  by (simp add: eval_nat_numeral setprod_numseg mult_commute)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1050
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1051
lemma det_1: "det (A::'a::comm_ring_1^1^1) = A$1$1"
44457
d366fa5551ef declare euclidean_simps [simp] at the point they are proved;
huffman
parents: 44260
diff changeset
  1052
  by (simp add: det_def sign_id)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1053
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1054
lemma det_2: "det (A::'a::comm_ring_1^2^2) = A$1$1 * A$2$2 - A$1$2 * A$2$1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1055
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1056
  have f12: "finite {2::2}" "1 \<notin> {2::2}" by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1057
  show ?thesis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1058
  unfolding det_def UNIV_2
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1059
  unfolding setsum_over_permutations_insert[OF f12]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1060
  unfolding permutes_sing
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 44457
diff changeset
  1061
  by (simp add: sign_swap_id sign_id swap_id_eq)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1062
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1063
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1064
lemma det_3: "det (A::'a::comm_ring_1^3^3) =
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1065
  A$1$1 * A$2$2 * A$3$3 +
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1066
  A$1$2 * A$2$3 * A$3$1 +
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1067
  A$1$3 * A$2$1 * A$3$2 -
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1068
  A$1$1 * A$2$3 * A$3$2 -
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1069
  A$1$2 * A$2$1 * A$3$3 -
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1070
  A$1$3 * A$2$2 * A$3$1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1071
proof-
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1072
  have f123: "finite {2::3, 3}" "1 \<notin> {2::3, 3}" by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1073
  have f23: "finite {3::3}" "2 \<notin> {3::3}" by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1074
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1075
  show ?thesis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1076
  unfolding det_def UNIV_3
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1077
  unfolding setsum_over_permutations_insert[OF f123]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1078
  unfolding setsum_over_permutations_insert[OF f23]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1079
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1080
  unfolding permutes_sing
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 44457
diff changeset
  1081
  by (simp add: sign_swap_id permutation_swap_id sign_compose sign_id swap_id_eq)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1082
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1083
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1084
end