src/HOL/Multivariate_Analysis/Determinants.thy
author paulson <lp15@cam.ac.uk>
Wed, 30 Sep 2015 17:09:12 +0100
changeset 61286 dcf7be51bf5d
parent 60420 884f54e01427
child 62408 86f27b264d3d
permissions -rw-r--r--
Dead wood removal
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
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
     5
section \<open>Traces, Determinant of square matrices and some properties\<close>
33175
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
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
    13
subsection \<open>Trace\<close>
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    14
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    15
definition trace :: "'a::semiring_1^'n^'n \<Rightarrow> 'a"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    16
  where "trace A = setsum (\<lambda>i. ((A$i)$i)) (UNIV::'n set)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    17
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    18
lemma trace_0: "trace (mat 0) = 0"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    19
  by (simp add: trace_def mat_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    20
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    21
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
    22
  by (simp add: trace_def mat_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    23
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
    24
lemma trace_add: "trace ((A::'a::comm_semiring_1^'n^'n) + B) = trace A + trace B"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
    25
  by (simp add: trace_def setsum.distrib)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    26
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
    27
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
    28
  by (simp add: trace_def setsum_subtractf)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    29
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    30
lemma trace_mul_sym: "trace ((A::'a::comm_semiring_1^'n^'m) ** B) = trace (B**A)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    31
  apply (simp add: trace_def matrix_matrix_mult_def)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
    32
  apply (subst setsum.commute)
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57418
diff changeset
    33
  apply (simp add: mult.commute)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    34
  done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    35
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
    36
text \<open>Definition of determinant.\<close>
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    37
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
    38
definition det:: "'a::comm_ring_1^'n^'n \<Rightarrow> 'a" where
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    39
  "det A =
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    40
    setsum (\<lambda>p. of_int (sign p) * setprod (\<lambda>i. A$i$p i) (UNIV :: 'n set))
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    41
      {p. p permutes (UNIV :: 'n set)}"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    42
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
    43
text \<open>A few general lemmas we need below.\<close>
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    44
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    45
lemma setprod_permute:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    46
  assumes p: "p permutes S"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    47
  shows "setprod f S = setprod (f \<circ> p) S"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 50526
diff changeset
    48
  using assms by (fact setprod.permute)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    49
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    50
lemma setproduct_permute_nat_interval:
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    51
  fixes m n :: nat
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    52
  shows "p permutes {m..n} \<Longrightarrow> setprod f {m..n} = setprod (f \<circ> p) {m..n}"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    53
  by (blast intro!: setprod_permute)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    54
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
    55
text \<open>Basic determinant properties.\<close>
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    56
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
    57
lemma det_transpose: "det (transpose A) = det (A::'a::comm_ring_1 ^'n^'n)"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    58
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    59
  let ?di = "\<lambda>A i j. A$i$j"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    60
  let ?U = "(UNIV :: 'n set)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    61
  have fU: "finite ?U" by simp
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    62
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    63
    fix p
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    64
    assume p: "p \<in> {p. p permutes ?U}"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    65
    from p have pU: "p permutes ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    66
      by blast
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    67
    have sth: "sign (inv p) = sign p"
44260
7784fa3232ce Determinants.thy: avoid using mem_def/Collect_def
huffman
parents: 44228
diff changeset
    68
      by (metis sign_inverse fU p mem_Collect_eq permutation_permutes)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    69
    from permutes_inj[OF pU]
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    70
    have pi: "inj_on p ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    71
      by (blast intro: subset_inj_on)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    72
    from permutes_image[OF pU]
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    73
    have "setprod (\<lambda>i. ?di (transpose A) i (inv p i)) ?U =
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    74
      setprod (\<lambda>i. ?di (transpose A) i (inv p i)) (p ` ?U)"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    75
      by simp
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    76
    also have "\<dots> = setprod ((\<lambda>i. ?di (transpose A) i (inv p i)) \<circ> p) ?U"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
    77
      unfolding setprod.reindex[OF pi] ..
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    78
    also have "\<dots> = setprod (\<lambda>i. ?di A i (p i)) ?U"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    79
    proof -
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    80
      {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    81
        fix i
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    82
        assume i: "i \<in> ?U"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    83
        from i permutes_inv_o[OF pU] permutes_in_image[OF pU]
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    84
        have "((\<lambda>i. ?di (transpose A) i (inv p i)) \<circ> p) i = ?di A i (p i)"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    85
          unfolding transpose_def by (simp add: fun_eq_iff)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    86
      }
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    87
      then show "setprod ((\<lambda>i. ?di (transpose A) i (inv p i)) \<circ> p) ?U =
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    88
        setprod (\<lambda>i. ?di A i (p i)) ?U"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
    89
        by (auto intro: setprod.cong)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
    90
    qed
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    91
    finally have "of_int (sign (inv p)) * (setprod (\<lambda>i. ?di (transpose A) i (inv p i)) ?U) =
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    92
      of_int (sign p) * (setprod (\<lambda>i. ?di A i (p i)) ?U)"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
    93
      using sth by simp
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    94
  }
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    95
  then show ?thesis
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    96
    unfolding det_def
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
    97
    apply (subst setsum_permutations_inverse)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
    98
    apply (rule setsum.cong)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
    99
    apply (rule refl)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   100
    apply blast
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   101
    done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   102
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   103
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   104
lemma det_lowerdiagonal:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   105
  fixes A :: "'a::comm_ring_1^('n::{finite,wellorder})^('n::{finite,wellorder})"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   106
  assumes ld: "\<And>i j. i < j \<Longrightarrow> A$i$j = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   107
  shows "det A = setprod (\<lambda>i. A$i$i) (UNIV:: 'n set)"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   108
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   109
  let ?U = "UNIV:: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   110
  let ?PU = "{p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   111
  let ?pp = "\<lambda>p. of_int (sign p) * setprod (\<lambda>i. A$i$p i) (UNIV :: 'n set)"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   112
  have fU: "finite ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   113
    by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   114
  from finite_permutations[OF fU] have fPU: "finite ?PU" .
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   115
  have id0: "{id} \<subseteq> ?PU"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   116
    by (auto simp add: permutes_id)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   117
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   118
    fix p
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   119
    assume p: "p \<in> ?PU - {id}"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   120
    from p have pU: "p permutes ?U" and pid: "p \<noteq> id"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   121
      by blast+
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   122
    from permutes_natset_le[OF pU] pid obtain i where i: "p i > i"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   123
      by (metis not_le)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   124
    from ld[OF i] have ex:"\<exists>i \<in> ?U. A$i$p i = 0"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   125
      by blast
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   126
    from setprod_zero[OF fU ex] have "?pp p = 0"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   127
      by simp
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   128
  }
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   129
  then have p0: "\<forall>p \<in> ?PU - {id}. ?pp p = 0"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   130
    by blast
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   131
  from setsum.mono_neutral_cong_left[OF fPU id0 p0] show ?thesis
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   132
    unfolding det_def by (simp add: sign_id)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   133
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   134
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   135
lemma det_upperdiagonal:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   136
  fixes A :: "'a::comm_ring_1^'n::{finite,wellorder}^'n::{finite,wellorder}"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   137
  assumes ld: "\<And>i j. i > j \<Longrightarrow> A$i$j = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   138
  shows "det A = setprod (\<lambda>i. A$i$i) (UNIV:: 'n set)"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   139
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   140
  let ?U = "UNIV:: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   141
  let ?PU = "{p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   142
  let ?pp = "(\<lambda>p. of_int (sign p) * setprod (\<lambda>i. A$i$p i) (UNIV :: 'n set))"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   143
  have fU: "finite ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   144
    by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   145
  from finite_permutations[OF fU] have fPU: "finite ?PU" .
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   146
  have id0: "{id} \<subseteq> ?PU"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   147
    by (auto simp add: permutes_id)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   148
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   149
    fix p
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   150
    assume p: "p \<in> ?PU - {id}"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   151
    from p have pU: "p permutes ?U" and pid: "p \<noteq> id"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   152
      by blast+
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   153
    from permutes_natset_ge[OF pU] pid obtain i where i: "p i < i"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   154
      by (metis not_le)
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   155
    from ld[OF i] have ex:"\<exists>i \<in> ?U. A$i$p i = 0"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   156
      by blast
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   157
    from setprod_zero[OF fU ex] have "?pp p = 0"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   158
      by simp
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   159
  }
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   160
  then have p0: "\<forall>p \<in> ?PU -{id}. ?pp p = 0"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   161
    by blast
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   162
  from setsum.mono_neutral_cong_left[OF fPU id0 p0] show ?thesis
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   163
    unfolding det_def by (simp add: sign_id)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   164
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   165
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   166
lemma det_diagonal:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   167
  fixes A :: "'a::comm_ring_1^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   168
  assumes ld: "\<And>i j. i \<noteq> j \<Longrightarrow> A$i$j = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   169
  shows "det A = setprod (\<lambda>i. A$i$i) (UNIV::'n set)"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   170
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   171
  let ?U = "UNIV:: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   172
  let ?PU = "{p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   173
  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
   174
  have fU: "finite ?U" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   175
  from finite_permutations[OF fU] have fPU: "finite ?PU" .
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   176
  have id0: "{id} \<subseteq> ?PU"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   177
    by (auto simp add: permutes_id)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   178
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   179
    fix p
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   180
    assume p: "p \<in> ?PU - {id}"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   181
    then have "p \<noteq> id"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   182
      by simp
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   183
    then obtain i where i: "p i \<noteq> i"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   184
      unfolding fun_eq_iff by auto
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   185
    from ld [OF i [symmetric]] have ex:"\<exists>i \<in> ?U. A$i$p i = 0"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   186
      by blast
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   187
    from setprod_zero [OF fU ex] have "?pp p = 0"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   188
      by simp
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   189
  }
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   190
  then have p0: "\<forall>p \<in> ?PU - {id}. ?pp p = 0"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   191
    by blast
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   192
  from setsum.mono_neutral_cong_left[OF fPU id0 p0] show ?thesis
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   193
    unfolding det_def by (simp add: sign_id)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   194
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   195
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   196
lemma det_I: "det (mat 1 :: 'a::comm_ring_1^'n^'n) = 1"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   197
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   198
  let ?A = "mat 1 :: 'a::comm_ring_1^'n^'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   199
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   200
  let ?f = "\<lambda>i j. ?A$i$j"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   201
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   202
    fix i
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   203
    assume i: "i \<in> ?U"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   204
    have "?f i i = 1"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   205
      using i by (vector mat_def)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   206
  }
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   207
  then have th: "setprod (\<lambda>i. ?f i i) ?U = setprod (\<lambda>x. 1) ?U"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   208
    by (auto intro: setprod.cong)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   209
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   210
    fix i j
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   211
    assume i: "i \<in> ?U" and j: "j \<in> ?U" and ij: "i \<noteq> j"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   212
    have "?f i j = 0" using i j ij
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   213
      by (vector mat_def)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   214
  }
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   215
  then have "det ?A = setprod (\<lambda>i. ?f i i) ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   216
    using det_diagonal by blast
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   217
  also have "\<dots> = 1"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   218
    unfolding th setprod.neutral_const ..
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   219
  finally show ?thesis .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   220
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   221
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   222
lemma det_0: "det (mat 0 :: 'a::comm_ring_1^'n^'n) = 0"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   223
  by (simp add: det_def setprod_zero)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   224
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   225
lemma det_permute_rows:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   226
  fixes A :: "'a::comm_ring_1^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   227
  assumes p: "p permutes (UNIV :: 'n::finite set)"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   228
  shows "det (\<chi> i. A$p i :: 'a^'n^'n) = of_int (sign p) * det A"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57418
diff changeset
   229
  apply (simp add: det_def setsum_right_distrib mult.assoc[symmetric])
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   230
  apply (subst sum_permutations_compose_right[OF p])
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   231
proof (rule setsum.cong)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   232
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   233
  let ?PU = "{p. p permutes ?U}"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   234
  fix q
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   235
  assume qPU: "q \<in> ?PU"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   236
  have fU: "finite ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   237
    by simp
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   238
  from qPU have q: "q permutes ?U"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   239
    by blast
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   240
  from p q have pp: "permutation p" and qp: "permutation q"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   241
    by (metis fU permutation_permutes)+
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   242
  from permutes_inv[OF p] have ip: "inv p permutes ?U" .
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   243
  have "setprod (\<lambda>i. A$p i$ (q \<circ> p) i) ?U = setprod ((\<lambda>i. A$p i$(q \<circ> p) i) \<circ> inv p) ?U"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   244
    by (simp only: setprod_permute[OF ip, symmetric])
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   245
  also have "\<dots> = setprod (\<lambda>i. A $ (p \<circ> inv p) i $ (q \<circ> (p \<circ> inv p)) i) ?U"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   246
    by (simp only: o_def)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   247
  also have "\<dots> = setprod (\<lambda>i. A$i$q i) ?U"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   248
    by (simp only: o_def permutes_inverses[OF p])
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   249
  finally have thp: "setprod (\<lambda>i. A$p i$ (q \<circ> p) i) ?U = setprod (\<lambda>i. A$i$q i) ?U"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   250
    by blast
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   251
  show "of_int (sign (q \<circ> p)) * setprod (\<lambda>i. A$ p i$ (q \<circ> p) i) ?U =
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   252
    of_int (sign p) * of_int (sign q) * setprod (\<lambda>i. A$i$q i) ?U"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57418
diff changeset
   253
    by (simp only: thp sign_compose[OF qp pp] mult.commute of_int_mult)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   254
qed rule
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   255
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   256
lemma det_permute_columns:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   257
  fixes A :: "'a::comm_ring_1^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   258
  assumes p: "p permutes (UNIV :: 'n set)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   259
  shows "det(\<chi> i j. A$i$ p j :: 'a^'n^'n) = of_int (sign p) * det A"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   260
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   261
  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
   262
  let ?At = "transpose A"
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   263
  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
   264
    unfolding det_permute_rows[OF p, of ?At] det_transpose ..
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   265
  moreover
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   266
  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
   267
    by (simp add: transpose_def vec_eq_iff)
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   268
  ultimately show ?thesis
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   269
    by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   270
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   271
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   272
lemma det_identical_rows:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34291
diff changeset
   273
  fixes A :: "'a::linordered_idom^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   274
  assumes ij: "i \<noteq> j"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   275
    and r: "row i A = row j A"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   276
  shows "det A = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   277
proof-
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   278
  have tha: "\<And>(a::'a) b. a = b \<Longrightarrow> b = - a \<Longrightarrow> a = 0"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   279
    by simp
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 44457
diff changeset
   280
  have th1: "of_int (-1) = - 1" by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   281
  let ?p = "Fun.swap i j id"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   282
  let ?A = "\<chi> i. A $ ?p i"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56196
diff changeset
   283
  from r have "A = ?A" by (simp add: vec_eq_iff row_def Fun.swap_def)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   284
  then have "det A = det ?A" by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   285
  moreover have "det A = - det ?A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   286
    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
   287
  ultimately show "det A = 0" by (metis tha)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   288
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   289
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   290
lemma det_identical_columns:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34291
diff changeset
   291
  fixes A :: "'a::linordered_idom^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   292
  assumes ij: "i \<noteq> j"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   293
    and r: "column i A = column j A"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   294
  shows "det A = 0"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   295
  apply (subst det_transpose[symmetric])
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   296
  apply (rule det_identical_rows[OF ij])
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   297
  apply (metis row_transpose r)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   298
  done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   299
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   300
lemma det_zero_row:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   301
  fixes A :: "'a::{idom, ring_char_0}^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   302
  assumes r: "row i A = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   303
  shows "det A = 0"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   304
  using r
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   305
  apply (simp add: row_def det_def vec_eq_iff)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   306
  apply (rule setsum.neutral)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   307
  apply (auto simp: sign_nz)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   308
  done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   309
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   310
lemma det_zero_column:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   311
  fixes A :: "'a::{idom,ring_char_0}^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   312
  assumes r: "column i A = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   313
  shows "det A = 0"
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   314
  apply (subst det_transpose[symmetric])
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   315
  apply (rule det_zero_row [of i])
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   316
  apply (metis row_transpose r)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   317
  done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   318
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   319
lemma det_row_add:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   320
  fixes a b c :: "'n::finite \<Rightarrow> _ ^ 'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   321
  shows "det((\<chi> i. if i = k then a i + b i else c i)::'a::comm_ring_1^'n^'n) =
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   322
    det((\<chi> i. if i = k then a i else c i)::'a::comm_ring_1^'n^'n) +
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   323
    det((\<chi> i. if i = k then b i else c i)::'a::comm_ring_1^'n^'n)"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   324
  unfolding det_def vec_lambda_beta setsum.distrib[symmetric]
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   325
proof (rule setsum.cong)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   326
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   327
  let ?pU = "{p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   328
  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
   329
  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
   330
  let ?h = "(\<lambda> i. if i = k then b i else c i)::'n \<Rightarrow> 'a::comm_ring_1^'n"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   331
  fix p
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   332
  assume p: "p \<in> ?pU"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   333
  let ?Uk = "?U - {k}"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   334
  from p have pU: "p permutes ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   335
    by blast
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   336
  have kU: "?U = insert k ?Uk"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   337
    by blast
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   338
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   339
    fix j
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   340
    assume j: "j \<in> ?Uk"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   341
    from j have "?f j $ p j = ?g j $ p j" and "?f j $ p j= ?h j $ p j"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   342
      by simp_all
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   343
  }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   344
  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
   345
    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
   346
    apply -
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   347
    apply (rule setprod.cong, simp_all)+
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   348
    done
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   349
  have th3: "finite ?Uk" "k \<notin> ?Uk"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   350
    by auto
33175
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] ..
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   353
  also have "\<dots> = ?f k $ p k * setprod (\<lambda>i. ?f i $ p i) ?Uk"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   354
    apply (rule setprod.insert)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   355
    apply simp
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   356
    apply blast
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   357
    done
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   358
  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)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   359
    by (simp add: field_simps)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   360
  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)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   361
    by (metis th1 th2)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   362
  also have "\<dots> = setprod (\<lambda>i. ?g i $ p i) (insert k ?Uk) + setprod (\<lambda>i. ?h i $ p i) (insert k ?Uk)"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   363
    unfolding  setprod.insert[OF th3] by simp
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   364
  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"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   365
    unfolding kU[symmetric] .
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   366
  then show "of_int (sign p) * setprod (\<lambda>i. ?f i $ p i) ?U =
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   367
    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
   368
    by (simp add: field_simps)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   369
qed rule
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   370
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   371
lemma det_row_mul:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   372
  fixes a b :: "'n::finite \<Rightarrow> _ ^ 'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   373
  shows "det((\<chi> i. if i = k then c *s a i else b i)::'a::comm_ring_1^'n^'n) =
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   374
    c * det((\<chi> i. if i = k then a i else b i)::'a::comm_ring_1^'n^'n)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   375
  unfolding det_def vec_lambda_beta setsum_right_distrib
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   376
proof (rule setsum.cong)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   377
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   378
  let ?pU = "{p. p permutes ?U}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   379
  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
   380
  let ?g = "(\<lambda> i. if i = k then a i else b i)::'n \<Rightarrow> 'a::comm_ring_1^'n"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   381
  fix p
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   382
  assume p: "p \<in> ?pU"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   383
  let ?Uk = "?U - {k}"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   384
  from p have pU: "p permutes ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   385
    by blast
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   386
  have kU: "?U = insert k ?Uk"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   387
    by blast
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   388
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   389
    fix j
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   390
    assume j: "j \<in> ?Uk"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   391
    from j have "?f j $ p j = ?g j $ p j"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   392
      by simp
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   393
  }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   394
  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
   395
    apply -
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   396
    apply (rule setprod.cong)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   397
    apply simp_all
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   398
    done
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   399
  have th3: "finite ?Uk" "k \<notin> ?Uk"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   400
    by auto
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   401
  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
   402
    unfolding kU[symmetric] ..
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   403
  also have "\<dots> = ?f k $ p k  * setprod (\<lambda>i. ?f i $ p i) ?Uk"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   404
    apply (rule setprod.insert)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   405
    apply simp
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   406
    apply blast
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   407
    done
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   408
  also have "\<dots> = (c*s a k) $ p k * setprod (\<lambda>i. ?f i $ p i) ?Uk"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   409
    by (simp add: field_simps)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   410
  also have "\<dots> = c* (a k $ p k * setprod (\<lambda>i. ?g i $ p i) ?Uk)"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   411
    unfolding th1 by (simp add: ac_simps)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   412
  also have "\<dots> = c* (setprod (\<lambda>i. ?g i $ p i) (insert k ?Uk))"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   413
    unfolding setprod.insert[OF th3] by simp
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   414
  finally have "setprod (\<lambda>i. ?f i $ p i) ?U = c* (setprod (\<lambda>i. ?g i $ p i) ?U)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   415
    unfolding kU[symmetric] .
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   416
  then show "of_int (sign p) * setprod (\<lambda>i. ?f i $ p i) ?U =
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   417
    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
   418
    by (simp add: field_simps)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   419
qed rule
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   420
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   421
lemma det_row_0:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   422
  fixes b :: "'n::finite \<Rightarrow> _ ^ 'n"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   423
  shows "det((\<chi> i. if i = k then 0 else b i)::'a::comm_ring_1^'n^'n) = 0"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   424
  using det_row_mul[of k 0 "\<lambda>i. 1" b]
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   425
  apply simp
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   426
  apply (simp only: vector_smult_lzero)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   427
  done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   428
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   429
lemma det_row_operation:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34291
diff changeset
   430
  fixes A :: "'a::linordered_idom^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   431
  assumes ij: "i \<noteq> j"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   432
  shows "det (\<chi> k. if k = i then row i A + c *s row j A else row k A) = det A"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   433
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   434
  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
   435
  have th: "row i ?Z = row j ?Z" by (vector row_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   436
  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
   437
    by (vector row_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   438
  show ?thesis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   439
    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
   440
    by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   441
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   442
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   443
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
   444
  fixes A :: "real^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   445
  assumes x: "x \<in> span {row j A |j. j \<noteq> i}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   446
  shows "det (\<chi> k. if k = i then row i A + x else row k A) = det A"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   447
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   448
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   449
  let ?S = "{row j A |j. j \<noteq> i}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   450
  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
   451
  let ?P = "\<lambda>x. ?d (row i A + x) = det A"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   452
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   453
    fix k
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   454
    have "(if k = i then row i A + 0 else row k A) = row k A"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   455
      by simp
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   456
  }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   457
  then have P0: "?P 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   458
    apply -
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   459
    apply (rule cong[of det, OF refl])
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   460
    apply (vector row_def)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   461
    done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   462
  moreover
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   463
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   464
    fix c z y
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   465
    assume zS: "z \<in> ?S" and Py: "?P y"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   466
    from zS obtain j where j: "z = row j A" "i \<noteq> j"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   467
      by blast
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   468
    let ?w = "row i A + y"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   469
    have th0: "row i A + (c*s z + y) = ?w + c*s z"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   470
      by vector
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   471
    have thz: "?d z = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   472
      apply (rule det_identical_rows[OF j(2)])
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   473
      using j
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   474
      apply (vector row_def)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   475
      done
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   476
    have "?d (row i A + (c*s z + y)) = ?d (?w + c*s z)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   477
      unfolding th0 ..
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   478
    then have "?P (c*s z + y)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   479
      unfolding thz Py det_row_mul[of i] det_row_add[of i]
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   480
      by simp
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   481
  }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   482
  ultimately show ?thesis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   483
    apply -
50526
899c9c4e4a4c Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents: 47108
diff changeset
   484
    apply (rule span_induct_alt[of ?P ?S, OF P0, folded scalar_mult_eq_scaleR])
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   485
    apply blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   486
    apply (rule x)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   487
    done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   488
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   489
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
   490
text \<open>
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   491
  May as well do this, though it's a bit unsatisfactory since it ignores
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   492
  exact duplicates by considering the rows/columns as a set.
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
   493
\<close>
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   494
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   495
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
   496
  fixes A:: "real^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   497
  assumes d: "dependent (rows A)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   498
  shows "det A = 0"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   499
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   500
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   501
  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
   502
    unfolding dependent_def rows_def by blast
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   503
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   504
    fix j k
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   505
    assume jk: "j \<noteq> k" and c: "row j A = row k A"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   506
    from det_identical_rows[OF jk c] have ?thesis .
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   507
  }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   508
  moreover
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   509
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   510
    assume H: "\<And> i j. i \<noteq> j \<Longrightarrow> row i A \<noteq> row j A"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   511
    have th0: "- row i A \<in> span {row j A|j. j \<noteq> i}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   512
      apply (rule span_neg)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   513
      apply (rule set_rev_mp)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   514
      apply (rule i)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   515
      apply (rule span_mono)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   516
      using H i
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   517
      apply (auto simp add: rows_def)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   518
      done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   519
    from det_row_span[OF th0]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   520
    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
   521
      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
   522
    with det_row_mul[of i "0::real" "\<lambda>i. 1"]
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   523
    have "det A = 0" by simp
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   524
  }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   525
  ultimately show ?thesis by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   526
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   527
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   528
lemma det_dependent_columns:
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   529
  assumes d: "dependent (columns (A::real^'n^'n))"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   530
  shows "det A = 0"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   531
  by (metis d det_dependent_rows rows_transpose det_transpose)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   532
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
   533
text \<open>Multilinearity and the multiplication formula.\<close>
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   534
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
   535
lemma Cart_lambda_cong: "(\<And>x. f x = g x) \<Longrightarrow> (vec_lambda f::'a^'n) = (vec_lambda g :: 'a^'n)"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   536
  by (rule iffD1[OF vec_lambda_unique]) vector
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   537
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   538
lemma det_linear_row_setsum:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   539
  assumes fS: "finite S"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   540
  shows "det ((\<chi> i. if i = k then setsum (a i) S else c i)::'a::comm_ring_1^'n^'n) =
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   541
    setsum (\<lambda>j. det ((\<chi> i. if i = k then a  i j else c i)::'a^'n^'n)) S"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   542
proof (induct rule: finite_induct[OF fS])
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   543
  case 1
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   544
  then show ?case
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   545
    apply simp
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   546
    unfolding setsum.empty det_row_0[of k]
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   547
    apply rule
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   548
    done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   549
next
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   550
  case (2 x F)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   551
  then show ?case
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   552
    by (simp add: det_row_add cong del: if_weak_cong)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   553
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   554
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   555
lemma finite_bounded_functions:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   556
  assumes fS: "finite S"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   557
  shows "finite {f. (\<forall>i \<in> {1.. (k::nat)}. f i \<in> S) \<and> (\<forall>i. i \<notin> {1 .. k} \<longrightarrow> f i = i)}"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   558
proof (induct k)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   559
  case 0
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   560
  have th: "{f. \<forall>i. f i = i} = {id}"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   561
    by auto
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   562
  show ?case
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   563
    by (auto simp add: th)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   564
next
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   565
  case (Suc k)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   566
  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
   567
  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
   568
  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
   569
    apply (auto simp add: image_iff)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   570
    apply (rule_tac x="x (Suc k)" in bexI)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   571
    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
   572
    apply auto
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   573
    done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   574
  with finite_imageI[OF finite_cartesian_product[OF fS Suc.hyps(1)], of ?f]
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   575
  show ?case
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   576
    by metis
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   577
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   578
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   579
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   580
lemma eq_id_iff[simp]: "(\<forall>x. f x = x) \<longleftrightarrow> f = id"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   581
  by auto
33175
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_lemma:
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   584
  assumes fS: "finite S"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   585
    and fT: "finite T"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   586
  shows "det ((\<chi> i. if i \<in> T then setsum (a i) S else c i):: 'a::comm_ring_1^'n^'n) =
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   587
    setsum (\<lambda>f. det((\<chi> i. if i \<in> T then a i (f i) else c i)::'a^'n^'n))
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   588
      {f. (\<forall>i \<in> T. f i \<in> S) \<and> (\<forall>i. i \<notin> T \<longrightarrow> f i = i)}"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   589
  using fT
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   590
proof (induct T arbitrary: a c set: finite)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   591
  case empty
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   592
  have th0: "\<And>x y. (\<chi> i. if i \<in> {} then x i else y i) = (\<chi> i. y i)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   593
    by vector
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   594
  from empty.prems show ?case
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   595
    unfolding th0 by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   596
next
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   597
  case (insert z T a c)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   598
  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
   599
  let ?h = "\<lambda>(y,g) i. if i = z then y else g i"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   600
  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
   601
  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)"
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   602
  let ?c = "\<lambda>j i. if i = z then a i j else c i"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   603
  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)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   604
    by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   605
  have thif2: "\<And>a b c d e. (if a then b else if c then d else e) =
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   606
     (if c then (if a then b else d) else (if a then b else e))"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   607
    by simp
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
   608
  from \<open>z \<notin> T\<close> have nz: "\<And>i. i \<in> T \<Longrightarrow> i = z \<longleftrightarrow> False"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   609
    by auto
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   610
  have "det (\<chi> i. if i \<in> insert z T then setsum (a i) S else c i) =
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   611
    det (\<chi> i. if i = z then setsum (a i) S else if i \<in> T then setsum (a i) S else c i)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   612
    unfolding insert_iff thif ..
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   613
  also have "\<dots> = (\<Sum>j\<in>S. det (\<chi> i. if i \<in> T then setsum (a i) S else if i = z then a i j else c i))"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   614
    unfolding det_linear_row_setsum[OF fS]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   615
    apply (subst thif2)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   616
    using nz
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   617
    apply (simp cong del: if_weak_cong cong add: if_cong)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   618
    done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   619
  finally have tha:
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   620
    "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
   621
     (\<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
   622
                                else if i = z then a i j
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   623
                                else c i))"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   624
    unfolding insert.hyps unfolding setsum.cartesian_product by blast
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   625
  show ?case unfolding tha
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
   626
    using \<open>z \<notin> T\<close>
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   627
    by (intro setsum.reindex_bij_witness[where i="?k" and j="?h"])
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   628
       (auto intro!: cong[OF refl[of det]] simp: vec_eq_iff)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   629
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   630
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   631
lemma det_linear_rows_setsum:
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   632
  fixes S :: "'n::finite set"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   633
  assumes fS: "finite S"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   634
  shows "det (\<chi> i. setsum (a i) S) =
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   635
    setsum (\<lambda>f. det (\<chi> i. a i (f i) :: 'a::comm_ring_1 ^ 'n^'n)) {f. \<forall>i. f i \<in> S}"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   636
proof -
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   637
  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)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   638
    by vector
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   639
  from det_linear_rows_setsum_lemma[OF fS, of "UNIV :: 'n set" a, unfolded th0, OF finite]
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   640
  show ?thesis by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   641
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   642
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   643
lemma matrix_mul_setsum_alt:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   644
  fixes A B :: "'a::comm_ring_1^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   645
  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
   646
  by (vector matrix_matrix_mult_def setsum_component)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   647
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   648
lemma det_rows_mul:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   649
  "det((\<chi> i. c i *s a i)::'a::comm_ring_1^'n^'n) =
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   650
    setprod (\<lambda>i. c i) (UNIV:: 'n set) * det((\<chi> i. a i)::'a^'n^'n)"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   651
proof (simp add: det_def setsum_right_distrib cong add: setprod.cong, rule setsum.cong)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   652
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   653
  let ?PU = "{p. p permutes ?U}"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   654
  fix p
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   655
  assume pU: "p \<in> ?PU"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   656
  let ?s = "of_int (sign p)"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   657
  from pU have p: "p permutes ?U"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   658
    by blast
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   659
  have "setprod (\<lambda>i. c i * a i $ p i) ?U = setprod c ?U * setprod (\<lambda>i. a i $ p i) ?U"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   660
    unfolding setprod.distrib ..
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   661
  then show "?s * (\<Prod>xa\<in>?U. c xa * a xa $ p xa) =
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   662
    setprod c ?U * (?s* (\<Prod>xa\<in>?U. a xa $ p xa))"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   663
    by (simp add: field_simps)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   664
qed rule
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   665
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   666
lemma det_mul:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34291
diff changeset
   667
  fixes A B :: "'a::linordered_idom^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   668
  shows "det (A ** B) = det A * det B"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   669
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   670
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   671
  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
   672
  let ?PU = "{p. p permutes ?U}"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   673
  have fU: "finite ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   674
    by simp
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   675
  have fF: "finite ?F"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   676
    by (rule finite)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   677
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   678
    fix p
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   679
    assume p: "p permutes ?U"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   680
    have "p \<in> ?F" unfolding mem_Collect_eq permutes_in_image[OF p]
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   681
      using p[unfolded permutes_def] by simp
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   682
  }
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   683
  then have PUF: "?PU \<subseteq> ?F" by blast
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   684
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   685
    fix f
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   686
    assume fPU: "f \<in> ?F - ?PU"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   687
    have fUU: "f ` ?U \<subseteq> ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   688
      using fPU by auto
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   689
    from fPU have f: "\<forall>i \<in> ?U. f i \<in> ?U" "\<forall>i. i \<notin> ?U \<longrightarrow> f i = i" "\<not>(\<forall>y. \<exists>!x. f x = y)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   690
      unfolding permutes_def by auto
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   691
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   692
    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
   693
    let ?B = "(\<chi> i. B$f i) :: 'a^'n^'n"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   694
    {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   695
      assume fni: "\<not> inj_on f ?U"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   696
      then obtain i j where ij: "f i = f j" "i \<noteq> j"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   697
        unfolding inj_on_def by blast
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   698
      from ij
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   699
      have rth: "row i ?B = row j ?B"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   700
        by (vector row_def)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   701
      from det_identical_rows[OF ij(2) rth]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   702
      have "det (\<chi> i. A$i$f i *s B$f i) = 0"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   703
        unfolding det_rows_mul by simp
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   704
    }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   705
    moreover
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   706
    {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   707
      assume fi: "inj_on f ?U"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   708
      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
   709
        unfolding inj_on_def by metis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   710
      note fs = fi[unfolded surjective_iff_injective_gen[OF fU fU refl fUU, symmetric]]
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   711
      {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   712
        fix y
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   713
        from fs f have "\<exists>x. f x = y"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   714
          by blast
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   715
        then obtain x where x: "f x = y"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   716
          by blast
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   717
        {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   718
          fix z
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   719
          assume z: "f z = y"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   720
          from fith x z have "z = x"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   721
            by metis
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   722
        }
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   723
        with x have "\<exists>!x. f x = y"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   724
          by blast
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   725
      }
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   726
      with f(3) have "det (\<chi> i. A$i$f i *s B$f i) = 0"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   727
        by blast
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   728
    }
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   729
    ultimately have "det (\<chi> i. A$i$f i *s B$f i) = 0"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   730
      by blast
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   731
  }
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   732
  then have zth: "\<forall> f\<in> ?F - ?PU. det (\<chi> i. A$i$f i *s B$f i) = 0"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   733
    by simp
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   734
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   735
    fix p
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   736
    assume pU: "p \<in> ?PU"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   737
    from pU have p: "p permutes ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   738
      by blast
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   739
    let ?s = "\<lambda>p. of_int (sign p)"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   740
    let ?f = "\<lambda>q. ?s p * (\<Prod>i\<in> ?U. A $ i $ p i) * (?s q * (\<Prod>i\<in> ?U. B $ i $ q i))"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   741
    have "(setsum (\<lambda>q. ?s q *
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   742
        (\<Prod>i\<in> ?U. (\<chi> i. A $ i $ p i *s B $ p i :: 'a^'n^'n) $ i $ q i)) ?PU) =
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   743
      (setsum (\<lambda>q. ?s p * (\<Prod>i\<in> ?U. A $ i $ p i) * (?s q * (\<Prod>i\<in> ?U. B $ i $ q i))) ?PU)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   744
      unfolding sum_permutations_compose_right[OF permutes_inv[OF p], of ?f]
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   745
    proof (rule setsum.cong)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   746
      fix q
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   747
      assume qU: "q \<in> ?PU"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   748
      then have q: "q permutes ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   749
        by blast
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   750
      from p q have pp: "permutation p" and pq: "permutation q"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   751
        unfolding permutation_permutes by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   752
      have th00: "of_int (sign p) * of_int (sign p) = (1::'a)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   753
        "\<And>a. of_int (sign p) * (of_int (sign p) * a) = a"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57418
diff changeset
   754
        unfolding mult.assoc[symmetric]
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   755
        unfolding of_int_mult[symmetric]
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   756
        by (simp_all add: sign_idempotent)
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   757
      have ths: "?s q = ?s p * ?s (q \<circ> inv p)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   758
        using pp pq permutation_inverse[OF pp] sign_inverse[OF pp]
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   759
        by (simp add:  th00 ac_simps sign_idempotent sign_compose)
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   760
      have th001: "setprod (\<lambda>i. B$i$ q (inv p i)) ?U = setprod ((\<lambda>i. B$i$ q (inv p i)) \<circ> p) ?U"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   761
        by (rule setprod_permute[OF p])
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   762
      have thp: "setprod (\<lambda>i. (\<chi> i. A$i$p i *s B$p i :: 'a^'n^'n) $i $ q i) ?U =
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   763
        setprod (\<lambda>i. A$i$p i) ?U * setprod (\<lambda>i. B$i$ q (inv p i)) ?U"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   764
        unfolding th001 setprod.distrib[symmetric] o_def permutes_inverses[OF p]
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   765
        apply (rule setprod.cong[OF refl])
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   766
        using permutes_in_image[OF q]
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   767
        apply vector
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   768
        done
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   769
      show "?s q * setprod (\<lambda>i. (((\<chi> i. A$i$p i *s B$p i) :: 'a^'n^'n)$i$q i)) ?U =
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   770
        ?s p * (setprod (\<lambda>i. A$i$p i) ?U) * (?s (q \<circ> inv p) * setprod (\<lambda>i. B$i$(q \<circ> inv p) i) ?U)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   771
        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
   772
        by (simp add: sign_nz th00 field_simps sign_idempotent sign_compose)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   773
    qed rule
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   774
  }
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   775
  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
   776
    unfolding det_def setsum_product
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   777
    by (rule setsum.cong [OF refl])
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   778
  have "det (A**B) = setsum (\<lambda>f.  det (\<chi> i. A $ i $ f i *s B $ f i)) ?F"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   779
    unfolding matrix_mul_setsum_alt det_linear_rows_setsum[OF fU]
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   780
    by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   781
  also have "\<dots> = setsum (\<lambda>f. det (\<chi> i. A$i$f i *s B$f i)) ?PU"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   782
    using setsum.mono_neutral_cong_left[OF fF PUF zth, symmetric]
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   783
    unfolding det_rows_mul by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   784
  finally show ?thesis unfolding th2 .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   785
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   786
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
   787
text \<open>Relation to invertibility.\<close>
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   788
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   789
lemma invertible_left_inverse:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   790
  fixes A :: "real^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   791
  shows "invertible A \<longleftrightarrow> (\<exists>(B::real^'n^'n). B** A = mat 1)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   792
  by (metis invertible_def matrix_left_right_inverse)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   793
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   794
lemma invertible_righ_inverse:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   795
  fixes A :: "real^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   796
  shows "invertible A \<longleftrightarrow> (\<exists>(B::real^'n^'n). A** B = mat 1)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   797
  by (metis invertible_def matrix_left_right_inverse)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   798
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   799
lemma invertible_det_nz:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   800
  fixes A::"real ^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   801
  shows "invertible A \<longleftrightarrow> det A \<noteq> 0"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   802
proof -
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   803
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   804
    assume "invertible A"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   805
    then obtain B :: "real ^'n^'n" where B: "A ** B = mat 1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   806
      unfolding invertible_righ_inverse by blast
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   807
    then have "det (A ** B) = det (mat 1 :: real ^'n^'n)"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   808
      by simp
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   809
    then have "det A \<noteq> 0"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   810
      by (simp add: det_mul det_I) algebra
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   811
  }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   812
  moreover
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   813
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   814
    assume H: "\<not> invertible A"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   815
    let ?U = "UNIV :: 'n set"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   816
    have fU: "finite ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   817
      by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   818
    from H obtain c i where c: "setsum (\<lambda>i. c i *s row i A) ?U = 0"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   819
      and iU: "i \<in> ?U"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   820
      and ci: "c i \<noteq> 0"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   821
      unfolding invertible_righ_inverse
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   822
      unfolding matrix_right_invertible_independent_rows
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   823
      by blast
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   824
    have *: "\<And>(a::real^'n) b. a + b = 0 \<Longrightarrow> -a = b"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   825
      apply (drule_tac f="op + (- a)" in cong[OF refl])
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57418
diff changeset
   826
      apply (simp only: ab_left_minus add.assoc[symmetric])
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   827
      apply simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   828
      done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   829
    from c ci
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   830
    have thr0: "- row i A = setsum (\<lambda>j. (1/ c i) *s (c j *s row j A)) (?U - {i})"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   831
      unfolding setsum.remove[OF fU iU] setsum_cmul
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   832
      apply -
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   833
      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
   834
      apply (auto simp add: field_simps)
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   835
      unfolding *
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   836
      apply rule
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   837
      done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   838
    have thr: "- row i A \<in> span {row j A| j. j \<noteq> i}"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   839
      unfolding thr0
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   840
      apply (rule span_setsum)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   841
      apply simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   842
      apply (rule ballI)
50526
899c9c4e4a4c Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents: 47108
diff changeset
   843
      apply (rule span_mul [where 'a="real^'n", folded scalar_mult_eq_scaleR])+
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   844
      apply (rule span_superset)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   845
      apply auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   846
      done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   847
    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
   848
    have thrb: "row i ?B = 0" using iU by (vector row_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   849
    have "det A = 0"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   850
      unfolding det_row_span[OF thr, symmetric] right_minus
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   851
      unfolding det_zero_row[OF thrb] ..
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   852
  }
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   853
  ultimately show ?thesis
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   854
    by blast
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   855
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   856
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
   857
text \<open>Cramer's rule.\<close>
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   858
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   859
lemma cramer_lemma_transpose:
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   860
  fixes A:: "real^'n^'n"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   861
    and x :: "real^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   862
  shows "det ((\<chi> i. if i = k then setsum (\<lambda>i. x$i *s row i A) (UNIV::'n set)
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   863
                             else row i A)::real^'n^'n) = x$k * det A"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   864
  (is "?lhs = ?rhs")
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   865
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   866
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   867
  let ?Uk = "?U - {k}"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   868
  have U: "?U = insert k ?Uk"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   869
    by blast
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   870
  have fUk: "finite ?Uk"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   871
    by simp
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   872
  have kUk: "k \<notin> ?Uk"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   873
    by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   874
  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
   875
    by (vector field_simps)
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   876
  have th001: "\<And>f k . (\<lambda>x. if x = k then f k else f x) = f"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   877
    by auto
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   878
  have "(\<chi> i. row i A) = A" by (vector row_def)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   879
  then have thd1: "det (\<chi> i. row i A) = det A"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   880
    by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   881
  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
   882
    apply (rule det_row_span)
56196
32b7eafc5a52 remove unnecessary finiteness assumptions from lemmas about setsum
huffman
parents: 53854
diff changeset
   883
    apply (rule span_setsum)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   884
    apply (rule ballI)
50526
899c9c4e4a4c Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents: 47108
diff changeset
   885
    apply (rule span_mul [where 'a="real^'n", folded scalar_mult_eq_scaleR])+
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   886
    apply (rule span_superset)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   887
    apply auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   888
    done
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   889
  show "?lhs = x$k * det A"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   890
    apply (subst U)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   891
    unfolding setsum.insert[OF fUk kUk]
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   892
    apply (subst th00)
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57418
diff changeset
   893
    unfolding add.assoc
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   894
    apply (subst det_row_add)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   895
    unfolding thd0
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   896
    unfolding det_row_mul
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   897
    unfolding th001[of k "\<lambda>i. row i A"]
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   898
    unfolding thd1
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   899
    apply (simp add: field_simps)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   900
    done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   901
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   902
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   903
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
   904
  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
   905
  shows "det((\<chi> i j. if j = k then (A *v x)$i else A$i$j):: real^'n^'n) = x$k * det A"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   906
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   907
  let ?U = "UNIV :: 'n set"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   908
  have *: "\<And>c. setsum (\<lambda>i. c i *s row i (transpose A)) ?U = setsum (\<lambda>i. c i *s column i A) ?U"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
   909
    by (auto simp add: row_transpose intro: setsum.cong)
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   910
  show ?thesis
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   911
    unfolding matrix_mult_vsum
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   912
    unfolding cramer_lemma_transpose[of k x "transpose A", unfolded det_transpose, symmetric]
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   913
    unfolding *[of "\<lambda>i. x$i"]
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   914
    apply (subst det_transpose[symmetric])
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   915
    apply (rule cong[OF refl[of det]])
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   916
    apply (vector transpose_def column_def row_def)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   917
    done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   918
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   919
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   920
lemma cramer:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   921
  fixes A ::"real^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   922
  assumes d0: "det A \<noteq> 0"
36362
06475a1547cb fix lots of looping simp calls and other warnings
huffman
parents: 35542
diff changeset
   923
  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)"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   924
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   925
  from d0 obtain B where B: "A ** B = mat 1" "B ** A = mat 1"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   926
    unfolding invertible_det_nz[symmetric] invertible_def
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   927
    by blast
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   928
  have "(A ** B) *v b = b"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   929
    by (simp add: B matrix_vector_mul_lid)
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   930
  then have "A *v (B *v b) = b"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   931
    by (simp add: matrix_vector_mul_assoc)
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   932
  then have xe: "\<exists>x. A *v x = b"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   933
    by blast
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   934
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   935
    fix x
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   936
    assume x: "A *v x = b"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   937
    have "x = (\<chi> k. det(\<chi> i j. if j=k then b$i else A$i$j) / det A)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   938
      unfolding x[symmetric]
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   939
      using d0 by (simp add: vec_eq_iff cramer_lemma field_simps)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   940
  }
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   941
  with xe show ?thesis
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
   942
    by auto
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   943
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   944
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
   945
text \<open>Orthogonality of a transformation and matrix.\<close>
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   946
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   947
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
   948
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   949
lemma orthogonal_transformation:
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   950
  "orthogonal_transformation f \<longleftrightarrow> linear f \<and> (\<forall>(v::real ^_). norm (f v) = norm v)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   951
  unfolding orthogonal_transformation_def
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   952
  apply auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   953
  apply (erule_tac x=v in allE)+
35542
8f97d8caabfd replaced \<bullet> with inner
himmelma
parents: 35150
diff changeset
   954
  apply (simp add: norm_eq_sqrt_inner)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   955
  apply (simp add: dot_norm  linear_add[symmetric])
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   956
  done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   957
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   958
definition "orthogonal_matrix (Q::'a::semiring_1^'n^'n) \<longleftrightarrow>
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   959
  transpose Q ** Q = mat 1 \<and> Q ** transpose Q = mat 1"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   960
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   961
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
   962
  by (metis matrix_left_right_inverse orthogonal_matrix_def)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   963
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   964
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
   965
  by (simp add: orthogonal_matrix_def transpose_mat matrix_mul_lid)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   966
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   967
lemma orthogonal_matrix_mul:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   968
  fixes A :: "real ^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   969
  assumes oA : "orthogonal_matrix A"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   970
    and oB: "orthogonal_matrix B"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   971
  shows "orthogonal_matrix(A ** B)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   972
  using oA oB
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   973
  unfolding orthogonal_matrix matrix_transpose_mul
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   974
  apply (subst matrix_mul_assoc)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   975
  apply (subst matrix_mul_assoc[symmetric])
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   976
  apply (simp add: matrix_mul_rid)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   977
  done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   978
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   979
lemma orthogonal_transformation_matrix:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
   980
  fixes f:: "real^'n \<Rightarrow> real^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   981
  shows "orthogonal_transformation f \<longleftrightarrow> linear f \<and> orthogonal_matrix(matrix f)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   982
  (is "?lhs \<longleftrightarrow> ?rhs")
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   983
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   984
  let ?mf = "matrix f"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   985
  let ?ot = "orthogonal_transformation f"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   986
  let ?U = "UNIV :: 'n set"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   987
  have fU: "finite ?U" by simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   988
  let ?m1 = "mat 1 :: real ^'n^'n"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   989
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   990
    assume ot: ?ot
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   991
    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
   992
      unfolding  orthogonal_transformation_def orthogonal_matrix by blast+
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   993
    {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
   994
      fix i j
35150
082fa4bd403d Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents: 35028
diff changeset
   995
      let ?A = "transpose ?mf ** ?mf"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
   996
      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
   997
        "\<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
   998
        by simp_all
50526
899c9c4e4a4c Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents: 47108
diff changeset
   999
      from fd[rule_format, of "axis i 1" "axis j 1", unfolded matrix_works[OF lf, symmetric] dot_matrix_vector_mul]
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1000
      have "?A$i$j = ?m1 $ i $ j"
50526
899c9c4e4a4c Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents: 47108
diff changeset
  1001
        by (simp add: inner_vec_def matrix_matrix_mult_def columnvector_def rowvector_def
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
  1002
            th0 setsum.delta[OF fU] mat_def axis_def)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1003
    }
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1004
    then have "orthogonal_matrix ?mf"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1005
      unfolding orthogonal_matrix
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1006
      by vector
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1007
    with lf have ?rhs
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1008
      by blast
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1009
  }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1010
  moreover
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1011
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1012
    assume lf: "linear f" and om: "orthogonal_matrix ?mf"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1013
    from lf om have ?lhs
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1014
      unfolding orthogonal_matrix_def norm_eq orthogonal_transformation
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1015
      unfolding matrix_works[OF lf, symmetric]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1016
      apply (subst dot_matrix_vector_mul)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1017
      apply (simp add: dot_matrix_product matrix_mul_lid)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1018
      done
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1019
  }
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1020
  ultimately show ?thesis
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1021
    by blast
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1022
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1023
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1024
lemma det_orthogonal_matrix:
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34291
diff changeset
  1025
  fixes Q:: "'a::linordered_idom^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1026
  assumes oQ: "orthogonal_matrix Q"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1027
  shows "det Q = 1 \<or> det Q = - 1"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1028
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1029
  have th: "\<And>x::'a. x = 1 \<or> x = - 1 \<longleftrightarrow> x*x = 1" (is "\<And>x::'a. ?ths x")
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1030
  proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1031
    fix x:: 'a
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1032
    have th0: "x * x - 1 = (x - 1) * (x + 1)"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1033
      by (simp add: field_simps)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1034
    have th1: "\<And>(x::'a) y. x = - y \<longleftrightarrow> x + y = 0"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1035
      apply (subst eq_iff_diff_eq_0)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1036
      apply simp
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1037
      done
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1038
    have "x * x = 1 \<longleftrightarrow> x * x - 1 = 0"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1039
      by simp
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1040
    also have "\<dots> \<longleftrightarrow> x = 1 \<or> x = - 1"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1041
      unfolding th0 th1 by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1042
    finally show "?ths x" ..
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1043
  qed
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1044
  from oQ have "Q ** transpose Q = mat 1"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1045
    by (metis orthogonal_matrix_def)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1046
  then have "det (Q ** transpose Q) = det (mat 1:: 'a^'n^'n)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1047
    by simp
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1048
  then have "det Q * det Q = 1"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1049
    by (simp add: det_mul det_I det_transpose)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1050
  then show ?thesis unfolding th .
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1051
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1052
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
  1053
text \<open>Linearity of scaling, and hence isometry, that preserves origin.\<close>
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1054
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1055
lemma scaling_linear:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
  1056
  fixes f :: "real ^'n \<Rightarrow> real ^'n"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1057
  assumes f0: "f 0 = 0"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1058
    and fd: "\<forall>x y. dist (f x) (f y) = c * dist x y"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1059
  shows "linear f"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1060
proof -
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1061
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1062
    fix v w
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1063
    {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1064
      fix x
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1065
      note fd[rule_format, of x 0, unfolded dist_norm f0 diff_0_right]
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1066
    }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1067
    note th0 = this
53077
a1b3784f8129 more symbols;
wenzelm
parents: 52451
diff changeset
  1068
    have "f v \<bullet> f w = c\<^sup>2 * (v \<bullet> w)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1069
      unfolding dot_norm_neg dist_norm[symmetric]
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1070
      unfolding th0 fd[rule_format] by (simp add: power2_eq_square field_simps)}
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1071
  note fc = this
50526
899c9c4e4a4c Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents: 47108
diff changeset
  1072
  show ?thesis
53600
8fda7ad57466 make 'linear' into a sublocale of 'bounded_linear';
huffman
parents: 53253
diff changeset
  1073
    unfolding linear_iff vector_eq[where 'a="real^'n"] scalar_mult_eq_scaleR
50526
899c9c4e4a4c Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents: 47108
diff changeset
  1074
    by (simp add: inner_add fc field_simps)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1075
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1076
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1077
lemma isometry_linear:
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1078
  "f (0:: real^'n) = (0:: real^'n) \<Longrightarrow> \<forall>x y. dist(f x) (f y) = dist x y \<Longrightarrow> linear f"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1079
  by (rule scaling_linear[where c=1]) simp_all
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1080
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
  1081
text \<open>Hence another formulation of orthogonal transformation.\<close>
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1082
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1083
lemma orthogonal_transformation_isometry:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
  1084
  "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
  1085
  unfolding orthogonal_transformation
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1086
  apply (rule iffI)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1087
  apply clarify
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1088
  apply (clarsimp simp add: linear_0 linear_sub[symmetric] dist_norm)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1089
  apply (rule conjI)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1090
  apply (rule isometry_linear)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1091
  apply simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1092
  apply simp
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1093
  apply clarify
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1094
  apply (erule_tac x=v in allE)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1095
  apply (erule_tac x=0 in allE)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1096
  apply (simp add: dist_norm)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1097
  done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1098
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
  1099
text \<open>Can extend an isometry from unit sphere.\<close>
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1100
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1101
lemma isometry_sphere_extend:
34291
4e896680897e finite annotation on cartesian product is now implicit.
hoelzl
parents: 34289
diff changeset
  1102
  fixes f:: "real ^'n \<Rightarrow> real ^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1103
  assumes f1: "\<forall>x. norm x = 1 \<longrightarrow> norm (f x) = 1"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1104
    and fd1: "\<forall> x y. norm x = 1 \<longrightarrow> norm y = 1 \<longrightarrow> dist (f x) (f y) = dist x y"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1105
  shows "\<exists>g. orthogonal_transformation g \<and> (\<forall>x. norm x = 1 \<longrightarrow> g x = f x)"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1106
proof -
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1107
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1108
    fix x y x' y' x0 y0 x0' y0' :: "real ^'n"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1109
    assume H:
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1110
      "x = norm x *\<^sub>R x0"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1111
      "y = norm y *\<^sub>R y0"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1112
      "x' = norm x *\<^sub>R x0'" "y' = norm y *\<^sub>R y0'"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1113
      "norm x0 = 1" "norm x0' = 1" "norm y0 = 1" "norm y0' = 1"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1114
      "norm(x0' - y0') = norm(x0 - y0)"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1115
    then have *: "x0 \<bullet> y0 = x0' \<bullet> y0' + y0' \<bullet> x0' - y0 \<bullet> x0 "
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1116
      by (simp add: norm_eq norm_eq_1 inner_add inner_diff)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1117
    have "norm(x' - y') = norm(x - y)"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1118
      apply (subst H(1))
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1119
      apply (subst H(2))
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1120
      apply (subst H(3))
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1121
      apply (subst H(4))
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1122
      using H(5-9)
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1123
      apply (simp add: norm_eq norm_eq_1)
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1124
      apply (simp add: inner_diff scalar_mult_eq_scaleR)
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1125
      unfolding *
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1126
      apply (simp add: field_simps)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1127
      done
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1128
  }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1129
  note th0 = this
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1130
  let ?g = "\<lambda>x. if x = 0 then 0 else norm x *\<^sub>R f (inverse (norm x) *\<^sub>R x)"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1131
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1132
    fix x:: "real ^'n"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1133
    assume nx: "norm x = 1"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1134
    have "?g x = f x"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1135
      using nx by auto
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1136
  }
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1137
  then have thfg: "\<forall>x. norm x = 1 \<longrightarrow> ?g x = f x"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1138
    by blast
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1139
  have g0: "?g 0 = 0"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1140
    by simp
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1141
  {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1142
    fix x y :: "real ^'n"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1143
    {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1144
      assume "x = 0" "y = 0"
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1145
      then have "dist (?g x) (?g y) = dist x y"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1146
        by simp
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1147
    }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1148
    moreover
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1149
    {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1150
      assume "x = 0" "y \<noteq> 0"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1151
      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
  1152
        apply (simp add: dist_norm)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1153
        apply (rule f1[rule_format])
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1154
        apply (simp add: field_simps)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1155
        done
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1156
    }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1157
    moreover
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1158
    {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1159
      assume "x \<noteq> 0" "y = 0"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1160
      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
  1161
        apply (simp add: dist_norm)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1162
        apply (rule f1[rule_format])
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1163
        apply (simp add: field_simps)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1164
        done
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1165
    }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1166
    moreover
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1167
    {
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1168
      assume z: "x \<noteq> 0" "y \<noteq> 0"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1169
      have th00:
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1170
        "x = norm x *\<^sub>R (inverse (norm x) *\<^sub>R x)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1171
        "y = norm y *\<^sub>R (inverse (norm y) *\<^sub>R y)"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1172
        "norm x *\<^sub>R f ((inverse (norm x) *\<^sub>R x)) = norm x *\<^sub>R f (inverse (norm x) *\<^sub>R x)"
44228
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1173
        "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
  1174
        "norm (inverse (norm x) *\<^sub>R x) = 1"
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1175
        "norm (f (inverse (norm x) *\<^sub>R x)) = 1"
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1176
        "norm (inverse (norm y) *\<^sub>R y) = 1"
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1177
        "norm (f (inverse (norm y) *\<^sub>R y)) = 1"
5f974bead436 get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents: 41959
diff changeset
  1178
        "norm (f (inverse (norm x) *\<^sub>R x) - f (inverse (norm y) *\<^sub>R y)) =
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1179
          norm (inverse (norm x) *\<^sub>R x - inverse (norm y) *\<^sub>R y)"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1180
        using z
44457
d366fa5551ef declare euclidean_simps [simp] at the point they are proved;
huffman
parents: 44260
diff changeset
  1181
        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
  1182
      from z th0[OF th00] have "dist (?g x) (?g y) = dist x y"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1183
        by (simp add: dist_norm)
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1184
    }
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1185
    ultimately have "dist (?g x) (?g y) = dist x y"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1186
      by blast
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1187
  }
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1188
  note thd = this
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1189
    show ?thesis
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1190
    apply (rule exI[where x= ?g])
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1191
    unfolding orthogonal_transformation_isometry
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1192
    using g0 thfg thd
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1193
    apply metis
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1194
    done
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1195
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1196
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
  1197
text \<open>Rotation, reflection, rotoinversion.\<close>
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1198
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1199
definition "rotation_matrix Q \<longleftrightarrow> orthogonal_matrix Q \<and> det Q = 1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1200
definition "rotoinversion_matrix Q \<longleftrightarrow> orthogonal_matrix Q \<and> det Q = - 1"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1201
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1202
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
  1203
  fixes Q :: "'a::linordered_idom^'n^'n"
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1204
  shows " orthogonal_matrix Q \<longleftrightarrow> rotation_matrix Q \<or> rotoinversion_matrix Q"
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1205
  by (metis rotoinversion_matrix_def rotation_matrix_def det_orthogonal_matrix)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1206
60420
884f54e01427 isabelle update_cartouches;
wenzelm
parents: 59867
diff changeset
  1207
text \<open>Explicit formulas for low dimensions.\<close>
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1208
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57129
diff changeset
  1209
lemma setprod_neutral_const: "setprod f {(1::nat)..1} = f 1"
61286
dcf7be51bf5d Dead wood removal
paulson <lp15@cam.ac.uk>
parents: 60420
diff changeset
  1210
  by simp
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1211
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1212
lemma setprod_2: "setprod f {(1::nat)..2} = f 1 * f 2"
61286
dcf7be51bf5d Dead wood removal
paulson <lp15@cam.ac.uk>
parents: 60420
diff changeset
  1213
  by (simp add: eval_nat_numeral atLeastAtMostSuc_conv mult.commute)
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1214
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1215
lemma setprod_3: "setprod f {(1::nat)..3} = f 1 * f 2 * f 3"
61286
dcf7be51bf5d Dead wood removal
paulson <lp15@cam.ac.uk>
parents: 60420
diff changeset
  1216
  by (simp add: eval_nat_numeral atLeastAtMostSuc_conv mult.commute)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1217
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1218
lemma det_1: "det (A::'a::comm_ring_1^1^1) = A$1$1"
61286
dcf7be51bf5d Dead wood removal
paulson <lp15@cam.ac.uk>
parents: 60420
diff changeset
  1219
  by (simp add: det_def of_nat_Suc sign_id)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1220
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1221
lemma det_2: "det (A::'a::comm_ring_1^2^2) = A$1$1 * A$2$2 - A$1$2 * A$2$1"
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1222
proof -
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1223
  have f12: "finite {2::2}" "1 \<notin> {2::2}" by auto
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1224
  show ?thesis
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1225
    unfolding det_def UNIV_2
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1226
    unfolding setsum_over_permutations_insert[OF f12]
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1227
    unfolding permutes_sing
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1228
    by (simp add: sign_swap_id sign_id swap_id_eq)
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1229
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1230
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1231
lemma det_3:
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1232
  "det (A::'a::comm_ring_1^3^3) =
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1233
    A$1$1 * A$2$2 * A$3$3 +
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1234
    A$1$2 * A$2$3 * A$3$1 +
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1235
    A$1$3 * A$2$1 * A$3$2 -
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1236
    A$1$1 * A$2$3 * A$3$2 -
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1237
    A$1$2 * A$2$1 * A$3$3 -
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1238
    A$1$3 * A$2$2 * A$3$1"
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1239
proof -
53854
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1240
  have f123: "finite {2::3, 3}" "1 \<notin> {2::3, 3}"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1241
    by auto
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1242
  have f23: "finite {3::3}" "2 \<notin> {3::3}"
78afb4c4e683 tuned proofs;
wenzelm
parents: 53600
diff changeset
  1243
    by auto
33175
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1244
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1245
  show ?thesis
53253
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1246
    unfolding det_def UNIV_3
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1247
    unfolding setsum_over_permutations_insert[OF f123]
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1248
    unfolding setsum_over_permutations_insert[OF f23]
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1249
    unfolding permutes_sing
220f306f5c4e tuned proofs;
wenzelm
parents: 53077
diff changeset
  1250
    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
  1251
qed
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1252
2083bde13ce1 distinguished session for multivariate analysis
himmelma
parents:
diff changeset
  1253
end