src/HOL/Matrix/MatrixGeneral.thy
author haftmann
Thu, 29 Nov 2007 17:08:26 +0100
changeset 25502 9200b36280c0
parent 23373 ead82c82da9e
child 25764 878c37886eed
permissions -rw-r--r--
instance command as rudimentary class target
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
     1
(*  Title:      HOL/Matrix/MatrixGeneral.thy
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
     2
    ID:         $Id$
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
     3
    Author:     Steven Obua
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
     4
*)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
     5
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 15795
diff changeset
     6
theory MatrixGeneral imports Main begin
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
     7
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
     8
types 'a infmatrix = "[nat, nat] \<Rightarrow> 'a"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
     9
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    10
constdefs
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    11
  nonzero_positions :: "('a::zero) infmatrix \<Rightarrow> (nat*nat) set"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    12
  "nonzero_positions A == {pos. A (fst pos) (snd pos) ~= 0}"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    13
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    14
typedef 'a matrix = "{(f::(('a::zero) infmatrix)). finite (nonzero_positions f)}"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    15
apply (rule_tac x="(% j i. 0)" in exI)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    16
by (simp add: nonzero_positions_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    17
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    18
declare Rep_matrix_inverse[simp]
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    19
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    20
lemma finite_nonzero_positions : "finite (nonzero_positions (Rep_matrix A))"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    21
apply (rule Abs_matrix_induct)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    22
by (simp add: Abs_matrix_inverse matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    23
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    24
constdefs
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    25
  nrows :: "('a::zero) matrix \<Rightarrow> nat"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    26
  "nrows A == if nonzero_positions(Rep_matrix A) = {} then 0 else Suc(Max ((image fst) (nonzero_positions (Rep_matrix A))))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    27
  ncols :: "('a::zero) matrix \<Rightarrow> nat"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    28
  "ncols A == if nonzero_positions(Rep_matrix A) = {} then 0 else Suc(Max ((image snd) (nonzero_positions (Rep_matrix A))))"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    29
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    30
lemma nrows:
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    31
  assumes hyp: "nrows A \<le> m"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    32
  shows "(Rep_matrix A m n) = 0" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    33
proof cases
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    34
  assume "nonzero_positions(Rep_matrix A) = {}"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    35
  then show "(Rep_matrix A m n) = 0" by (simp add: nonzero_positions_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    36
next
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    37
  assume a: "nonzero_positions(Rep_matrix A) \<noteq> {}"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    38
  let ?S = "fst`(nonzero_positions(Rep_matrix A))"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    39
  from a have b: "?S \<noteq> {}" by (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    40
  have c: "finite (?S)" by (simp add: finite_nonzero_positions)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    41
  from hyp have d: "Max (?S) < m" by (simp add: a nrows_def)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    42
  have "m \<notin> ?S"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    43
    proof -
15580
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
    44
      have "m \<in> ?S \<Longrightarrow> m <= Max(?S)" by (simp add: Max_ge[OF c b])
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    45
      moreover from d have "~(m <= Max ?S)" by (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    46
      ultimately show "m \<notin> ?S" by (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    47
    qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    48
  thus "Rep_matrix A m n = 0" by (simp add: nonzero_positions_def image_Collect)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    49
qed
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    50
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    51
constdefs
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    52
  transpose_infmatrix :: "'a infmatrix \<Rightarrow> 'a infmatrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    53
  "transpose_infmatrix A j i == A i j"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    54
  transpose_matrix :: "('a::zero) matrix \<Rightarrow> 'a matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    55
  "transpose_matrix == Abs_matrix o transpose_infmatrix o Rep_matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    56
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    57
declare transpose_infmatrix_def[simp]
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    58
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    59
lemma transpose_infmatrix_twice[simp]: "transpose_infmatrix (transpose_infmatrix A) = A"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    60
by ((rule ext)+, simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    61
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    62
lemma transpose_infmatrix: "transpose_infmatrix (% j i. P j i) = (% j i. P i j)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    63
  apply (rule ext)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    64
  by (simp add: transpose_infmatrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    65
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    66
lemma transpose_infmatrix_closed[simp]: "Rep_matrix (Abs_matrix (transpose_infmatrix (Rep_matrix x))) = transpose_infmatrix (Rep_matrix x)"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    67
apply (rule Abs_matrix_inverse)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    68
apply (simp add: matrix_def nonzero_positions_def image_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    69
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    70
  let ?A = "{pos. Rep_matrix x (snd pos) (fst pos) \<noteq> 0}"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    71
  let ?swap = "% pos. (snd pos, fst pos)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    72
  let ?B = "{pos. Rep_matrix x (fst pos) (snd pos) \<noteq> 0}"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    73
  have swap_image: "?swap`?A = ?B"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    74
    apply (simp add: image_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    75
    apply (rule set_ext)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    76
    apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    77
    proof
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    78
      fix y
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    79
      assume hyp: "\<exists>a b. Rep_matrix x b a \<noteq> 0 \<and> y = (b, a)"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    80
      thus "Rep_matrix x (fst y) (snd y) \<noteq> 0"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    81
        proof -
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    82
          from hyp obtain a b where "(Rep_matrix x b a \<noteq> 0 & y = (b,a))" by blast
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    83
          then show "Rep_matrix x (fst y) (snd y) \<noteq> 0" by (simp)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    84
        qed
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    85
    next
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    86
      fix y
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    87
      assume hyp: "Rep_matrix x (fst y) (snd y) \<noteq> 0"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 23315
diff changeset
    88
      show "\<exists> a b. (Rep_matrix x b a \<noteq> 0 & y = (b,a))"
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 23315
diff changeset
    89
	by (rule exI[of _ "snd y"], rule exI[of _ "fst y"]) (simp add: hyp)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    90
    qed
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    91
  then have "finite (?swap`?A)"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    92
    proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    93
      have "finite (nonzero_positions (Rep_matrix x))" by (simp add: finite_nonzero_positions)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    94
      then have "finite ?B" by (simp add: nonzero_positions_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    95
      with swap_image show "finite (?swap`?A)" by (simp)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    96
    qed
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    97
  moreover
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
    98
  have "inj_on ?swap ?A" by (simp add: inj_on_def)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
    99
  ultimately show "finite ?A"by (rule finite_imageD[of ?swap ?A])
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   100
qed
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   101
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   102
lemma infmatrixforward: "(x::'a infmatrix) = y \<Longrightarrow> \<forall> a b. x a b = y a b" by auto
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   103
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   104
lemma transpose_infmatrix_inject: "(transpose_infmatrix A = transpose_infmatrix B) = (A = B)"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   105
apply (auto)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   106
apply (rule ext)+
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   107
apply (simp add: transpose_infmatrix)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   108
apply (drule infmatrixforward)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   109
apply (simp)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   110
done
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   111
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   112
lemma transpose_matrix_inject: "(transpose_matrix A = transpose_matrix B) = (A = B)"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   113
apply (simp add: transpose_matrix_def)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   114
apply (subst Rep_matrix_inject[THEN sym])+
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   115
apply (simp only: transpose_infmatrix_closed transpose_infmatrix_inject)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   116
done
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   117
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   118
lemma transpose_matrix[simp]: "Rep_matrix(transpose_matrix A) j i = Rep_matrix A i j"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   119
by (simp add: transpose_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   120
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   121
lemma transpose_transpose_id[simp]: "transpose_matrix (transpose_matrix A) = A"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   122
by (simp add: transpose_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   123
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   124
lemma nrows_transpose[simp]: "nrows (transpose_matrix A) = ncols A"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   125
by (simp add: nrows_def ncols_def nonzero_positions_def transpose_matrix_def image_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   126
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   127
lemma ncols_transpose[simp]: "ncols (transpose_matrix A) = nrows A"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   128
by (simp add: nrows_def ncols_def nonzero_positions_def transpose_matrix_def image_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   129
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   130
lemma ncols: "ncols A <= n \<Longrightarrow> Rep_matrix A m n = 0"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   131
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   132
  assume "ncols A <= n"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   133
  then have "nrows (transpose_matrix A) <= n" by (simp)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   134
  then have "Rep_matrix (transpose_matrix A) n m = 0" by (rule nrows)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   135
  thus "Rep_matrix A m n = 0" by (simp add: transpose_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   136
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   137
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   138
lemma ncols_le: "(ncols A <= n) = (! j i. n <= i \<longrightarrow> (Rep_matrix A j i) = 0)" (is "_ = ?st")
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   139
apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   140
apply (simp add: ncols)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   141
proof (simp add: ncols_def, auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   142
  let ?P = "nonzero_positions (Rep_matrix A)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   143
  let ?p = "snd`?P"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   144
  have a:"finite ?p" by (simp add: finite_nonzero_positions)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   145
  let ?m = "Max ?p"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   146
  assume "~(Suc (?m) <= n)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   147
  then have b:"n <= ?m" by (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   148
  fix a b
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   149
  assume "(a,b) \<in> ?P"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   150
  then have "?p \<noteq> {}" by (auto)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   151
  with a have "?m \<in>  ?p" by (simp)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   152
  moreover have "!x. (x \<in> ?p \<longrightarrow> (? y. (Rep_matrix A y x) \<noteq> 0))" by (simp add: nonzero_positions_def image_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   153
  ultimately have "? y. (Rep_matrix A y ?m) \<noteq> 0" by (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   154
  moreover assume ?st
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   155
  ultimately show "False" using b by (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   156
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   157
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   158
lemma less_ncols: "(n < ncols A) = (? j i. n <= i & (Rep_matrix A j i) \<noteq> 0)" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   159
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   160
  have a: "!! (a::nat) b. (a < b) = (~(b <= a))" by arith
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   161
  show ?concl by (simp add: a ncols_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   162
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   163
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   164
lemma le_ncols: "(n <= ncols A) = (\<forall> m. (\<forall> j i. m <= i \<longrightarrow> (Rep_matrix A j i) = 0) \<longrightarrow> n <= m)" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   165
apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   166
apply (subgoal_tac "ncols A <= m")
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   167
apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   168
apply (simp add: ncols_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   169
apply (drule_tac x="ncols A" in spec)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   170
by (simp add: ncols)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   171
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   172
lemma nrows_le: "(nrows A <= n) = (! j i. n <= j \<longrightarrow> (Rep_matrix A j i) = 0)" (is ?s)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   173
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   174
  have "(nrows A <= n) = (ncols (transpose_matrix A) <= n)" by (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   175
  also have "\<dots> = (! j i. n <= i \<longrightarrow> (Rep_matrix (transpose_matrix A) j i = 0))" by (rule ncols_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   176
  also have "\<dots> = (! j i. n <= i \<longrightarrow> (Rep_matrix A i j) = 0)" by (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   177
  finally show "(nrows A <= n) = (! j i. n <= j \<longrightarrow> (Rep_matrix A j i) = 0)" by (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   178
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   179
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   180
lemma less_nrows: "(m < nrows A) = (? j i. m <= j & (Rep_matrix A j i) \<noteq> 0)" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   181
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   182
  have a: "!! (a::nat) b. (a < b) = (~(b <= a))" by arith
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   183
  show ?concl by (simp add: a nrows_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   184
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   185
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   186
lemma le_nrows: "(n <= nrows A) = (\<forall> m. (\<forall> j i. m <= j \<longrightarrow> (Rep_matrix A j i) = 0) \<longrightarrow> n <= m)" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   187
apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   188
apply (subgoal_tac "nrows A <= m")
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   189
apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   190
apply (simp add: nrows_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   191
apply (drule_tac x="nrows A" in spec)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   192
by (simp add: nrows)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   193
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   194
lemma nrows_notzero: "Rep_matrix A m n \<noteq> 0 \<Longrightarrow> m < nrows A"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   195
apply (case_tac "nrows A <= m")
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   196
apply (simp_all add: nrows)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   197
done
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   198
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   199
lemma ncols_notzero: "Rep_matrix A m n \<noteq> 0 \<Longrightarrow> n < ncols A"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   200
apply (case_tac "ncols A <= n")
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   201
apply (simp_all add: ncols)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   202
done
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   203
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   204
lemma finite_natarray1: "finite {x. x < (n::nat)}"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   205
apply (induct n)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   206
apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   207
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   208
  fix n
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   209
  have "{x. x < Suc n} = insert n {x. x < n}"  by (rule set_ext, simp, arith)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   210
  moreover assume "finite {x. x < n}"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   211
  ultimately show "finite {x. x < Suc n}" by (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   212
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   213
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   214
lemma finite_natarray2: "finite {pos. (fst pos) < (m::nat) & (snd pos) < (n::nat)}"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   215
  apply (induct m)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   216
  apply (simp+)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   217
  proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   218
    fix m::nat
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   219
    let ?s0 = "{pos. fst pos < m & snd pos < n}"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   220
    let ?s1 = "{pos. fst pos < (Suc m) & snd pos < n}"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   221
    let ?sd = "{pos. fst pos = m & snd pos < n}"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   222
    assume f0: "finite ?s0"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   223
    have f1: "finite ?sd"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   224
    proof -
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   225
      let ?f = "% x. (m, x)"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   226
      have "{pos. fst pos = m & snd pos < n} = ?f ` {x. x < n}" by (rule set_ext, simp add: image_def, auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   227
      moreover have "finite {x. x < n}" by (simp add: finite_natarray1)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   228
      ultimately show "finite {pos. fst pos = m & snd pos < n}" by (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   229
    qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   230
    have su: "?s0 \<union> ?sd = ?s1" by (rule set_ext, simp, arith)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   231
    from f0 f1 have "finite (?s0 \<union> ?sd)" by (rule finite_UnI)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   232
    with su show "finite ?s1" by (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   233
qed
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   234
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   235
lemma RepAbs_matrix:
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   236
  assumes aem: "? m. ! j i. m <= j \<longrightarrow> x j i = 0" (is ?em) and aen:"? n. ! j i. (n <= i \<longrightarrow> x j i = 0)" (is ?en)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   237
  shows "(Rep_matrix (Abs_matrix x)) = x"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   238
apply (rule Abs_matrix_inverse)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   239
apply (simp add: matrix_def nonzero_positions_def)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   240
proof -
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   241
  from aem obtain m where a: "! j i. m <= j \<longrightarrow> x j i = 0" by (blast)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   242
  from aen obtain n where b: "! j i. n <= i \<longrightarrow> x j i = 0" by (blast)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   243
  let ?u = "{pos. x (fst pos) (snd pos) \<noteq> 0}"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   244
  let ?v = "{pos. fst pos < m & snd pos < n}"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   245
  have c: "!! (m::nat) a. ~(m <= a) \<Longrightarrow> a < m" by (arith)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   246
  from a b have "(?u \<inter> (-?v)) = {}"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   247
    apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   248
    apply (rule set_ext)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   249
    apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   250
    apply auto
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   251
    by (rule c, auto)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   252
  then have d: "?u \<subseteq> ?v" by blast
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   253
  moreover have "finite ?v" by (simp add: finite_natarray2)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   254
  ultimately show "finite ?u" by (rule finite_subset)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   255
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   256
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   257
constdefs
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   258
  apply_infmatrix :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a infmatrix \<Rightarrow> 'b infmatrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   259
  "apply_infmatrix f == % A. (% j i. f (A j i))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   260
  apply_matrix :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a::zero) matrix \<Rightarrow> ('b::zero) matrix"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   261
  "apply_matrix f == % A. Abs_matrix (apply_infmatrix f (Rep_matrix A))"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   262
  combine_infmatrix :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'a infmatrix \<Rightarrow> 'b infmatrix \<Rightarrow> 'c infmatrix"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   263
  "combine_infmatrix f == % A B. (% j i. f (A j i) (B j i))"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   264
  combine_matrix :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> ('a::zero) matrix \<Rightarrow> ('b::zero) matrix \<Rightarrow> ('c::zero) matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   265
  "combine_matrix f == % A B. Abs_matrix (combine_infmatrix f (Rep_matrix A) (Rep_matrix B))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   266
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   267
lemma expand_apply_infmatrix[simp]: "apply_infmatrix f A j i = f (A j i)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   268
by (simp add: apply_infmatrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   269
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   270
lemma expand_combine_infmatrix[simp]: "combine_infmatrix f A B j i = f (A j i) (B j i)"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   271
by (simp add: combine_infmatrix_def)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   272
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   273
constdefs
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   274
commutative :: "('a \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> bool"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   275
"commutative f == ! x y. f x y = f y x"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   276
associative :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> bool"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   277
"associative f == ! x y z. f (f x y) z = f x (f y z)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   278
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   279
text{*
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   280
To reason about associativity and commutativity of operations on matrices,
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   281
let's take a step back and look at the general situtation: Assume that we have
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   282
sets $A$ and $B$ with $B \subset A$ and an abstraction $u: A \rightarrow B$. This abstraction has to fulfill $u(b) = b$ for all $b \in B$, but is arbitrary otherwise.
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   283
Each function $f: A \times A \rightarrow A$ now induces a function $f': B \times B \rightarrow B$ by $f' = u \circ f$.
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   284
It is obvious that commutativity of $f$ implies commutativity of $f'$: $f' x y = u (f x y) = u (f y x) = f' y x.$
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   285
*}
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   286
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   287
lemma combine_infmatrix_commute:
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   288
  "commutative f \<Longrightarrow> commutative (combine_infmatrix f)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   289
by (simp add: commutative_def combine_infmatrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   290
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   291
lemma combine_matrix_commute:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   292
"commutative f \<Longrightarrow> commutative (combine_matrix f)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   293
by (simp add: combine_matrix_def commutative_def combine_infmatrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   294
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   295
text{*
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   296
On the contrary, given an associative function $f$ we cannot expect $f'$ to be associative. A counterexample is given by $A=\ganz$, $B=\{-1, 0, 1\}$,
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   297
as $f$ we take addition on $\ganz$, which is clearly associative. The abstraction is given by  $u(a) = 0$ for $a \notin B$. Then we have
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   298
\[ f' (f' 1 1) -1 = u(f (u (f 1 1)) -1) = u(f (u 2) -1) = u (f 0 -1) = -1, \]
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   299
but on the other hand we have
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   300
\[ f' 1 (f' 1 -1) = u (f 1 (u (f 1 -1))) = u (f 1 0) = 1.\]
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   301
A way out of this problem is to assume that $f(A\times A)\subset A$ holds, and this is what we are going to do:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   302
*}
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   303
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   304
lemma nonzero_positions_combine_infmatrix[simp]: "f 0 0 = 0 \<Longrightarrow> nonzero_positions (combine_infmatrix f A B) \<subseteq> (nonzero_positions A) \<union> (nonzero_positions B)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   305
by (rule subsetI, simp add: nonzero_positions_def combine_infmatrix_def, auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   306
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   307
lemma finite_nonzero_positions_Rep[simp]: "finite (nonzero_positions (Rep_matrix A))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   308
by (insert Rep_matrix [of A], simp add: matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   309
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   310
lemma combine_infmatrix_closed [simp]:
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   311
  "f 0 0 = 0 \<Longrightarrow> Rep_matrix (Abs_matrix (combine_infmatrix f (Rep_matrix A) (Rep_matrix B))) = combine_infmatrix f (Rep_matrix A) (Rep_matrix B)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   312
apply (rule Abs_matrix_inverse)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   313
apply (simp add: matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   314
apply (rule finite_subset[of _ "(nonzero_positions (Rep_matrix A)) \<union> (nonzero_positions (Rep_matrix B))"])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   315
by (simp_all)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   316
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   317
text {* We need the next two lemmas only later, but it is analog to the above one, so we prove them now: *}
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   318
lemma nonzero_positions_apply_infmatrix[simp]: "f 0 = 0 \<Longrightarrow> nonzero_positions (apply_infmatrix f A) \<subseteq> nonzero_positions A"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   319
by (rule subsetI, simp add: nonzero_positions_def apply_infmatrix_def, auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   320
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   321
lemma apply_infmatrix_closed [simp]:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   322
  "f 0 = 0 \<Longrightarrow> Rep_matrix (Abs_matrix (apply_infmatrix f (Rep_matrix A))) = apply_infmatrix f (Rep_matrix A)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   323
apply (rule Abs_matrix_inverse)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   324
apply (simp add: matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   325
apply (rule finite_subset[of _ "nonzero_positions (Rep_matrix A)"])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   326
by (simp_all)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   327
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   328
lemma combine_infmatrix_assoc[simp]: "f 0 0 = 0 \<Longrightarrow> associative f \<Longrightarrow> associative (combine_infmatrix f)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   329
by (simp add: associative_def combine_infmatrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   330
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   331
lemma comb: "f = g \<Longrightarrow> x = y \<Longrightarrow> f x = g y"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   332
by (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   333
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   334
lemma combine_matrix_assoc: "f 0 0 = 0 \<Longrightarrow> associative f \<Longrightarrow> associative (combine_matrix f)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   335
apply (simp(no_asm) add: associative_def combine_matrix_def, auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   336
apply (rule comb [of Abs_matrix Abs_matrix])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   337
by (auto, insert combine_infmatrix_assoc[of f], simp add: associative_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   338
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   339
lemma Rep_apply_matrix[simp]: "f 0 = 0 \<Longrightarrow> Rep_matrix (apply_matrix f A) j i = f (Rep_matrix A j i)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   340
by (simp add: apply_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   341
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   342
lemma Rep_combine_matrix[simp]: "f 0 0 = 0 \<Longrightarrow> Rep_matrix (combine_matrix f A B) j i = f (Rep_matrix A j i) (Rep_matrix B j i)"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   343
  by(simp add: combine_matrix_def)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   344
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   345
lemma combine_nrows: "f 0 0 = 0  \<Longrightarrow> nrows (combine_matrix f A B) <= max (nrows A) (nrows B)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   346
by (simp add: nrows_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   347
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   348
lemma combine_ncols: "f 0 0 = 0 \<Longrightarrow> ncols (combine_matrix f A B) <= max (ncols A) (ncols B)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   349
by (simp add: ncols_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   350
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   351
lemma combine_nrows: "f 0 0 = 0 \<Longrightarrow> nrows A <= q \<Longrightarrow> nrows B <= q \<Longrightarrow> nrows(combine_matrix f A B) <= q"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   352
  by (simp add: nrows_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   353
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   354
lemma combine_ncols: "f 0 0 = 0 \<Longrightarrow> ncols A <= q \<Longrightarrow> ncols B <= q \<Longrightarrow> ncols(combine_matrix f A B) <= q"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   355
  by (simp add: ncols_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   356
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   357
constdefs
14654
aad262a36014 fixed constdefs typing;
wenzelm
parents: 14593
diff changeset
   358
  zero_r_neutral :: "('a \<Rightarrow> 'b::zero \<Rightarrow> 'a) \<Rightarrow> bool"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   359
  "zero_r_neutral f == ! a. f a 0 = a"
14654
aad262a36014 fixed constdefs typing;
wenzelm
parents: 14593
diff changeset
   360
  zero_l_neutral :: "('a::zero \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> bool"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   361
  "zero_l_neutral f == ! a. f 0 a = a"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   362
  zero_closed :: "(('a::zero) \<Rightarrow> ('b::zero) \<Rightarrow> ('c::zero)) \<Rightarrow> bool"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   363
  "zero_closed f == (!x. f x 0 = 0) & (!y. f 0 y = 0)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   364
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   365
consts foldseq :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> (nat \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   366
primrec
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   367
  "foldseq f s 0 = s 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   368
  "foldseq f s (Suc n) = f (s 0) (foldseq f (% k. s(Suc k)) n)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   369
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   370
consts foldseq_transposed ::  "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> (nat \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   371
primrec
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   372
  "foldseq_transposed f s 0 = s 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   373
  "foldseq_transposed f s (Suc n) = f (foldseq_transposed f s n) (s (Suc n))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   374
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   375
lemma foldseq_assoc : "associative f \<Longrightarrow> foldseq f = foldseq_transposed f"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   376
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   377
  assume a:"associative f"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   378
  then have sublemma: "!! n. ! N s. N <= n \<longrightarrow> foldseq f s N = foldseq_transposed f s N"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   379
  proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   380
    fix n
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   381
    show "!N s. N <= n \<longrightarrow> foldseq f s N = foldseq_transposed f s N"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   382
    proof (induct n)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   383
      show "!N s. N <= 0 \<longrightarrow> foldseq f s N = foldseq_transposed f s N" by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   384
    next
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   385
      fix n
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   386
      assume b:"! N s. N <= n \<longrightarrow> foldseq f s N = foldseq_transposed f s N"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   387
      have c:"!!N s. N <= n \<Longrightarrow> foldseq f s N = foldseq_transposed f s N" by (simp add: b)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   388
      show "! N t. N <= Suc n \<longrightarrow> foldseq f t N = foldseq_transposed f t N"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   389
      proof (auto)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   390
        fix N t
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   391
        assume Nsuc: "N <= Suc n"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   392
        show "foldseq f t N = foldseq_transposed f t N"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   393
        proof cases
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   394
          assume "N <= n"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   395
          then show "foldseq f t N = foldseq_transposed f t N" by (simp add: b)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   396
        next
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   397
          assume "~(N <= n)"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   398
          with Nsuc have Nsuceq: "N = Suc n" by simp
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   399
          have neqz: "n \<noteq> 0 \<Longrightarrow> ? m. n = Suc m & Suc m <= n" by arith
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   400
          have assocf: "!! x y z. f x (f y z) = f (f x y) z" by (insert a, simp add: associative_def)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   401
          show "foldseq f t N = foldseq_transposed f t N"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   402
            apply (simp add: Nsuceq)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   403
            apply (subst c)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   404
            apply (simp)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   405
            apply (case_tac "n = 0")
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   406
            apply (simp)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   407
            apply (drule neqz)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   408
            apply (erule exE)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   409
            apply (simp)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   410
            apply (subst assocf)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   411
            proof -
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   412
              fix m
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   413
              assume "n = Suc m & Suc m <= n"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   414
              then have mless: "Suc m <= n" by arith
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   415
              then have step1: "foldseq_transposed f (% k. t (Suc k)) m = foldseq f (% k. t (Suc k)) m" (is "?T1 = ?T2")
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   416
                apply (subst c)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   417
                by simp+
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   418
              have step2: "f (t 0) ?T2 = foldseq f t (Suc m)" (is "_ = ?T3") by simp
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   419
              have step3: "?T3 = foldseq_transposed f t (Suc m)" (is "_ = ?T4")
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   420
                apply (subst c)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   421
                by (simp add: mless)+
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   422
              have step4: "?T4 = f (foldseq_transposed f t m) (t (Suc m))" (is "_=?T5") by simp
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   423
              from step1 step2 step3 step4 show sowhat: "f (f (t 0) ?T1) (t (Suc (Suc m))) = f ?T5 (t (Suc (Suc m)))" by simp
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   424
            qed
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   425
          qed
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   426
        qed
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   427
      qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   428
    qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   429
    show "foldseq f = foldseq_transposed f" by ((rule ext)+, insert sublemma, auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   430
  qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   431
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   432
lemma foldseq_distr: "\<lbrakk>associative f; commutative f\<rbrakk> \<Longrightarrow> foldseq f (% k. f (u k) (v k)) n = f (foldseq f u n) (foldseq f v n)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   433
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   434
  assume assoc: "associative f"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   435
  assume comm: "commutative f"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   436
  from assoc have a:"!! x y z. f (f x y) z = f x (f y z)" by (simp add: associative_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   437
  from comm have b: "!! x y. f x y = f y x" by (simp add: commutative_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   438
  from assoc comm have c: "!! x y z. f x (f y z) = f y (f x z)" by (simp add: commutative_def associative_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   439
  have "!! n. (! u v. foldseq f (%k. f (u k) (v k)) n = f (foldseq f u n) (foldseq f v n))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   440
    apply (induct_tac n)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   441
    apply (simp+, auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   442
    by (simp add: a b c)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   443
  then show "foldseq f (% k. f (u k) (v k)) n = f (foldseq f u n) (foldseq f v n)" by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   444
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   445
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   446
theorem "\<lbrakk>associative f; associative g; \<forall>a b c d. g (f a b) (f c d) = f (g a c) (g b d); ? x y. (f x) \<noteq> (f y); ? x y. (g x) \<noteq> (g y); f x x = x; g x x = x\<rbrakk> \<Longrightarrow> f=g | (! y. f y x = y) | (! y. g y x = y)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   447
oops
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   448
(* Model found
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   449
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   450
Trying to find a model that refutes: \<lbrakk>associative f; associative g;
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   451
 \<forall>a b c d. g (f a b) (f c d) = f (g a c) (g b d); \<exists>x y. f x \<noteq> f y;
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   452
 \<exists>x y. g x \<noteq> g y; f x x = x; g x x = x\<rbrakk>
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   453
\<Longrightarrow> f = g \<or> (\<forall>y. f y x = y) \<or> (\<forall>y. g y x = y)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   454
Searching for a model of size 1, translating term... invoking SAT solver... no model found.
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   455
Searching for a model of size 2, translating term... invoking SAT solver... no model found.
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   456
Searching for a model of size 3, translating term... invoking SAT solver...
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   457
Model found:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   458
Size of types: 'a: 3
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   459
x: a1
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   460
g: (a0\<mapsto>(a0\<mapsto>a1, a1\<mapsto>a0, a2\<mapsto>a1), a1\<mapsto>(a0\<mapsto>a0, a1\<mapsto>a1, a2\<mapsto>a0), a2\<mapsto>(a0\<mapsto>a1, a1\<mapsto>a0, a2\<mapsto>a1))
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   461
f: (a0\<mapsto>(a0\<mapsto>a0, a1\<mapsto>a0, a2\<mapsto>a0), a1\<mapsto>(a0\<mapsto>a1, a1\<mapsto>a1, a2\<mapsto>a1), a2\<mapsto>(a0\<mapsto>a0, a1\<mapsto>a0, a2\<mapsto>a0))
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   462
*)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   463
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   464
lemma foldseq_zero:
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   465
assumes fz: "f 0 0 = 0" and sz: "! i. i <= n \<longrightarrow> s i = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   466
shows "foldseq f s n = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   467
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   468
  have "!! n. ! s. (! i. i <= n \<longrightarrow> s i = 0) \<longrightarrow> foldseq f s n = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   469
    apply (induct_tac n)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   470
    apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   471
    by (simp add: fz)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   472
  then show "foldseq f s n = 0" by (simp add: sz)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   473
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   474
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   475
lemma foldseq_significant_positions:
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   476
  assumes p: "! i. i <= N \<longrightarrow> S i = T i"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   477
  shows "foldseq f S N = foldseq f T N" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   478
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   479
  have "!! m . ! s t. (! i. i<=m \<longrightarrow> s i = t i) \<longrightarrow> foldseq f s m = foldseq f t m"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   480
    apply (induct_tac m)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   481
    apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   482
    apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   483
    apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   484
    proof -
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   485
      fix n
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   486
      fix s::"nat\<Rightarrow>'a"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   487
      fix t::"nat\<Rightarrow>'a"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   488
      assume a: "\<forall>s t. (\<forall>i\<le>n. s i = t i) \<longrightarrow> foldseq f s n = foldseq f t n"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   489
      assume b: "\<forall>i\<le>Suc n. s i = t i"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   490
      have c:"!! a b. a = b \<Longrightarrow> f (t 0) a = f (t 0) b" by blast
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   491
      have d:"!! s t. (\<forall>i\<le>n. s i = t i) \<Longrightarrow> foldseq f s n = foldseq f t n" by (simp add: a)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   492
      show "f (t 0) (foldseq f (\<lambda>k. s (Suc k)) n) = f (t 0) (foldseq f (\<lambda>k. t (Suc k)) n)" by (rule c, simp add: d b)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   493
    qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   494
  with p show ?concl by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   495
qed
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   496
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   497
lemma foldseq_tail: "M <= N \<Longrightarrow> foldseq f S N = foldseq f (% k. (if k < M then (S k) else (foldseq f (% k. S(k+M)) (N-M)))) M" (is "?p \<Longrightarrow> ?concl")
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   498
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   499
  have suc: "!! a b. \<lbrakk>a <= Suc b; a \<noteq> Suc b\<rbrakk> \<Longrightarrow> a <= b" by arith
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   500
  have a:"!! a b c . a = b \<Longrightarrow> f c a = f c b" by blast
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   501
  have "!! n. ! m s. m <= n \<longrightarrow> foldseq f s n = foldseq f (% k. (if k < m then (s k) else (foldseq f (% k. s(k+m)) (n-m)))) m"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   502
    apply (induct_tac n)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   503
    apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   504
    apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   505
    apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   506
    apply (case_tac "m = Suc na")
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   507
    apply (simp)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   508
    apply (rule a)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   509
    apply (rule foldseq_significant_positions)
15197
19e735596e51 Added antisymmetry simproc
nipkow
parents: 15178
diff changeset
   510
    apply (auto)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   511
    apply (drule suc, simp+)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   512
    proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   513
      fix na m s
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   514
      assume suba:"\<forall>m\<le>na. \<forall>s. foldseq f s na = foldseq f (\<lambda>k. if k < m then s k else foldseq f (\<lambda>k. s (k + m)) (na - m))m"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   515
      assume subb:"m <= na"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   516
      from suba have subc:"!! m s. m <= na \<Longrightarrow>foldseq f s na = foldseq f (\<lambda>k. if k < m then s k else foldseq f (\<lambda>k. s (k + m)) (na - m))m" by simp
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   517
      have subd: "foldseq f (\<lambda>k. if k < m then s (Suc k) else foldseq f (\<lambda>k. s (Suc (k + m))) (na - m)) m =
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   518
        foldseq f (% k. s(Suc k)) na"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   519
        by (rule subc[of m "% k. s(Suc k)", THEN sym], simp add: subb)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   520
      from subb have sube: "m \<noteq> 0 \<Longrightarrow> ? mm. m = Suc mm & mm <= na" by arith
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   521
      show "f (s 0) (foldseq f (\<lambda>k. if k < m then s (Suc k) else foldseq f (\<lambda>k. s (Suc (k + m))) (na - m)) m) =
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   522
        foldseq f (\<lambda>k. if k < m then s k else foldseq f (\<lambda>k. s (k + m)) (Suc na - m)) m"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   523
        apply (simp add: subd)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   524
        apply (case_tac "m=0")
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   525
        apply (simp)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   526
        apply (drule sube)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   527
        apply (auto)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   528
        apply (rule a)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   529
        by (simp add: subc if_def)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   530
    qed
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   531
  then show "?p \<Longrightarrow> ?concl" by simp
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   532
qed
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   533
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   534
lemma foldseq_zerotail:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   535
  assumes
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   536
  fz: "f 0 0 = 0"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   537
  and sz: "! i.  n <= i \<longrightarrow> s i = 0"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   538
  and nm: "n <= m"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   539
  shows
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   540
  "foldseq f s n = foldseq f s m"
15580
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
   541
proof -
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
   542
  show "foldseq f s n = foldseq f s m"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   543
    apply (simp add: foldseq_tail[OF nm, of f s])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   544
    apply (rule foldseq_significant_positions)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   545
    apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   546
    apply (subst foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   547
    by (simp add: fz sz)+
15580
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
   548
qed
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   549
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   550
lemma foldseq_zerotail2:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   551
  assumes "! x. f x 0 = x"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   552
  and "! i. n < i \<longrightarrow> s i = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   553
  and nm: "n <= m"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   554
  shows
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   555
  "foldseq f s n = foldseq f s m" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   556
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   557
  have "f 0 0 = 0" by (simp add: prems)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   558
  have b:"!! m n. n <= m \<Longrightarrow> m \<noteq> n \<Longrightarrow> ? k. m-n = Suc k" by arith
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   559
  have c: "0 <= m" by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   560
  have d: "!! k. k \<noteq> 0 \<Longrightarrow> ? l. k = Suc l" by arith
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   561
  show ?concl
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   562
    apply (subst foldseq_tail[OF nm])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   563
    apply (rule foldseq_significant_positions)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   564
    apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   565
    apply (case_tac "m=n")
15197
19e735596e51 Added antisymmetry simproc
nipkow
parents: 15178
diff changeset
   566
    apply (simp+)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   567
    apply (drule b[OF nm])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   568
    apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   569
    apply (case_tac "k=0")
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   570
    apply (simp add: prems)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   571
    apply (drule d)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   572
    apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   573
    by (simp add: prems foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   574
qed
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   575
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   576
lemma foldseq_zerostart:
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   577
  "! x. f 0 (f 0 x) = f 0 x \<Longrightarrow>  ! i. i <= n \<longrightarrow> s i = 0 \<Longrightarrow> foldseq f s (Suc n) = f 0 (s (Suc n))"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   578
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   579
  assume f00x: "! x. f 0 (f 0 x) = f 0 x"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   580
  have "! s. (! i. i<=n \<longrightarrow> s i = 0) \<longrightarrow> foldseq f s (Suc n) = f 0 (s (Suc n))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   581
    apply (induct n)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   582
    apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   583
    apply (rule allI, rule impI)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   584
    proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   585
      fix n
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   586
      fix s
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   587
      have a:"foldseq f s (Suc (Suc n)) = f (s 0) (foldseq f (% k. s(Suc k)) (Suc n))" by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   588
      assume b: "! s. ((\<forall>i\<le>n. s i = 0) \<longrightarrow> foldseq f s (Suc n) = f 0 (s (Suc n)))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   589
      from b have c:"!! s. (\<forall>i\<le>n. s i = 0) \<Longrightarrow> foldseq f s (Suc n) = f 0 (s (Suc n))" by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   590
      assume d: "! i. i <= Suc n \<longrightarrow> s i = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   591
      show "foldseq f s (Suc (Suc n)) = f 0 (s (Suc (Suc n)))"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   592
        apply (subst a)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   593
        apply (subst c)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   594
        by (simp add: d f00x)+
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   595
    qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   596
  then show "! i. i <= n \<longrightarrow> s i = 0 \<Longrightarrow> foldseq f s (Suc n) = f 0 (s (Suc n))" by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   597
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   598
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   599
lemma foldseq_zerostart2:
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   600
  "! x. f 0 x = x \<Longrightarrow>  ! i. i < n \<longrightarrow> s i = 0 \<Longrightarrow> foldseq f s n = s n"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   601
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   602
  assume a:"! i. i<n \<longrightarrow> s i = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   603
  assume x:"! x. f 0 x = x"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   604
  from x have f00x: "! x. f 0 (f 0 x) = f 0 x" by blast
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   605
  have b: "!! i l. i < Suc l = (i <= l)" by arith
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   606
  have d: "!! k. k \<noteq> 0 \<Longrightarrow> ? l. k = Suc l" by arith
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   607
  show "foldseq f s n = s n"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   608
  apply (case_tac "n=0")
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   609
  apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   610
  apply (insert a)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   611
  apply (drule d)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   612
  apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   613
  apply (simp add: b)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   614
  apply (insert f00x)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   615
  apply (drule foldseq_zerostart)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   616
  by (simp add: x)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   617
qed
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   618
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   619
lemma foldseq_almostzero:
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   620
  assumes f0x:"! x. f 0 x = x" and fx0: "! x. f x 0 = x" and s0:"! i. i \<noteq> j \<longrightarrow> s i = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   621
  shows "foldseq f s n = (if (j <= n) then (s j) else 0)" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   622
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   623
  from s0 have a: "! i. i < j \<longrightarrow> s i = 0" by simp
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   624
  from s0 have b: "! i. j < i \<longrightarrow> s i = 0" by simp
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   625
  show ?concl
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   626
    apply auto
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   627
    apply (subst foldseq_zerotail2[of f, OF fx0, of j, OF b, of n, THEN sym])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   628
    apply simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   629
    apply (subst foldseq_zerostart2)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   630
    apply (simp add: f0x a)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   631
    apply (subst foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   632
    by (simp add: s0 f0x)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   633
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   634
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   635
lemma foldseq_distr_unary:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   636
  assumes "!! a b. g (f a b) = f (g a) (g b)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   637
  shows "g(foldseq f s n) = foldseq f (% x. g(s x)) n" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   638
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   639
  have "! s. g(foldseq f s n) = foldseq f (% x. g(s x)) n"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   640
    apply (induct_tac n)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   641
    apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   642
    apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   643
    apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   644
    apply (drule_tac x="% k. s (Suc k)" in spec)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   645
    by (simp add: prems)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   646
  then show ?concl by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   647
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   648
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   649
constdefs
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   650
  mult_matrix_n :: "nat \<Rightarrow> (('a::zero) \<Rightarrow> ('b::zero) \<Rightarrow> ('c::zero)) \<Rightarrow> ('c \<Rightarrow> 'c \<Rightarrow> 'c) \<Rightarrow> 'a matrix \<Rightarrow> 'b matrix \<Rightarrow> 'c matrix"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   651
  "mult_matrix_n n fmul fadd A B == Abs_matrix(% j i. foldseq fadd (% k. fmul (Rep_matrix A j k) (Rep_matrix B k i)) n)"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   652
  mult_matrix :: "(('a::zero) \<Rightarrow> ('b::zero) \<Rightarrow> ('c::zero)) \<Rightarrow> ('c \<Rightarrow> 'c \<Rightarrow> 'c) \<Rightarrow> 'a matrix \<Rightarrow> 'b matrix \<Rightarrow> 'c matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   653
  "mult_matrix fmul fadd A B == mult_matrix_n (max (ncols A) (nrows B)) fmul fadd A B"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   654
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   655
lemma mult_matrix_n:
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   656
  assumes prems: "ncols A \<le>  n" (is ?An) "nrows B \<le> n" (is ?Bn) "fadd 0 0 = 0" "fmul 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   657
  shows c:"mult_matrix fmul fadd A B = mult_matrix_n n fmul fadd A B" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   658
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   659
  show ?concl using prems
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   660
    apply (simp add: mult_matrix_def mult_matrix_n_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   661
    apply (rule comb[of "Abs_matrix" "Abs_matrix"], simp, (rule ext)+)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   662
    by (rule foldseq_zerotail, simp_all add: nrows_le ncols_le prems)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   663
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   664
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   665
lemma mult_matrix_nm:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   666
  assumes prems: "ncols A <= n" "nrows B <= n" "ncols A <= m" "nrows B <= m" "fadd 0 0 = 0" "fmul 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   667
  shows "mult_matrix_n n fmul fadd A B = mult_matrix_n m fmul fadd A B"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   668
proof -
15580
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
   669
  from prems have "mult_matrix_n n fmul fadd A B = mult_matrix fmul fadd A B" by (simp add: mult_matrix_n)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   670
  also from prems have "\<dots> = mult_matrix_n m fmul fadd A B" by (simp add: mult_matrix_n[THEN sym])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   671
  finally show "mult_matrix_n n fmul fadd A B = mult_matrix_n m fmul fadd A B" by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   672
qed
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   673
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   674
constdefs
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   675
  r_distributive :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> ('b \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> bool"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   676
  "r_distributive fmul fadd == ! a u v. fmul a (fadd u v) = fadd (fmul a u) (fmul a v)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   677
  l_distributive :: "('a \<Rightarrow> 'b \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> bool"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   678
  "l_distributive fmul fadd == ! a u v. fmul (fadd u v) a = fadd (fmul u a) (fmul v a)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   679
  distributive :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> bool"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   680
  "distributive fmul fadd == l_distributive fmul fadd & r_distributive fmul fadd"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   681
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   682
lemma max1: "!! a x y. (a::nat) <= x \<Longrightarrow> a <= max x y" by (arith)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   683
lemma max2: "!! b x y. (b::nat) <= y \<Longrightarrow> b <= max x y" by (arith)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   684
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   685
lemma r_distributive_matrix:
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   686
 assumes prems:
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   687
  "r_distributive fmul fadd"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   688
  "associative fadd"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   689
  "commutative fadd"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   690
  "fadd 0 0 = 0"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   691
  "! a. fmul a 0 = 0"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   692
  "! a. fmul 0 a = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   693
 shows "r_distributive (mult_matrix fmul fadd) (combine_matrix fadd)" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   694
proof -
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   695
  from prems show ?concl
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   696
    apply (simp add: r_distributive_def mult_matrix_def, auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   697
    proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   698
      fix a::"'a matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   699
      fix u::"'b matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   700
      fix v::"'b matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   701
      let ?mx = "max (ncols a) (max (nrows u) (nrows v))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   702
      from prems show "mult_matrix_n (max (ncols a) (nrows (combine_matrix fadd u v))) fmul fadd a (combine_matrix fadd u v) =
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   703
        combine_matrix fadd (mult_matrix_n (max (ncols a) (nrows u)) fmul fadd a u) (mult_matrix_n (max (ncols a) (nrows v)) fmul fadd a v)"
15488
7c638a46dcbb tidying of some subst/simplesubst proofs
paulson
parents: 15485
diff changeset
   704
        apply (subst mult_matrix_nm[of _ _ _ ?mx fadd fmul])
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   705
        apply (simp add: max1 max2 combine_nrows combine_ncols)+
15488
7c638a46dcbb tidying of some subst/simplesubst proofs
paulson
parents: 15485
diff changeset
   706
        apply (subst mult_matrix_nm[of _ _ v ?mx fadd fmul])
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   707
        apply (simp add: max1 max2 combine_nrows combine_ncols)+
15488
7c638a46dcbb tidying of some subst/simplesubst proofs
paulson
parents: 15485
diff changeset
   708
        apply (subst mult_matrix_nm[of _ _ u ?mx fadd fmul])
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   709
        apply (simp add: max1 max2 combine_nrows combine_ncols)+
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   710
        apply (simp add: mult_matrix_n_def r_distributive_def foldseq_distr[of fadd])
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   711
        apply (simp add: combine_matrix_def combine_infmatrix_def)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   712
        apply (rule comb[of "Abs_matrix" "Abs_matrix"], simp, (rule ext)+)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 15392
diff changeset
   713
        apply (simplesubst RepAbs_matrix)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   714
        apply (simp, auto)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   715
        apply (rule exI[of _ "nrows a"], simp add: nrows_le foldseq_zero)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   716
        apply (rule exI[of _ "ncols v"], simp add: ncols_le foldseq_zero)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   717
        apply (subst RepAbs_matrix)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   718
        apply (simp, auto)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   719
        apply (rule exI[of _ "nrows a"], simp add: nrows_le foldseq_zero)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   720
        apply (rule exI[of _ "ncols u"], simp add: ncols_le foldseq_zero)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   721
        done
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   722
    qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   723
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   724
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   725
lemma l_distributive_matrix:
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   726
 assumes prems:
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   727
  "l_distributive fmul fadd"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   728
  "associative fadd"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   729
  "commutative fadd"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   730
  "fadd 0 0 = 0"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   731
  "! a. fmul a 0 = 0"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   732
  "! a. fmul 0 a = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   733
 shows "l_distributive (mult_matrix fmul fadd) (combine_matrix fadd)" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   734
proof -
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   735
  from prems show ?concl
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   736
    apply (simp add: l_distributive_def mult_matrix_def, auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   737
    proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   738
      fix a::"'b matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   739
      fix u::"'a matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   740
      fix v::"'a matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   741
      let ?mx = "max (nrows a) (max (ncols u) (ncols v))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   742
      from prems show "mult_matrix_n (max (ncols (combine_matrix fadd u v)) (nrows a)) fmul fadd (combine_matrix fadd u v) a =
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   743
               combine_matrix fadd (mult_matrix_n (max (ncols u) (nrows a)) fmul fadd u a) (mult_matrix_n (max (ncols v) (nrows a)) fmul fadd v a)"
15488
7c638a46dcbb tidying of some subst/simplesubst proofs
paulson
parents: 15485
diff changeset
   744
        apply (subst mult_matrix_nm[of v _ _ ?mx fadd fmul])
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   745
        apply (simp add: max1 max2 combine_nrows combine_ncols)+
15488
7c638a46dcbb tidying of some subst/simplesubst proofs
paulson
parents: 15485
diff changeset
   746
        apply (subst mult_matrix_nm[of u _ _ ?mx fadd fmul])
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   747
        apply (simp add: max1 max2 combine_nrows combine_ncols)+
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   748
        apply (subst mult_matrix_nm[of _ _ _ ?mx fadd fmul])
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   749
        apply (simp add: max1 max2 combine_nrows combine_ncols)+
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   750
        apply (simp add: mult_matrix_n_def l_distributive_def foldseq_distr[of fadd])
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   751
        apply (simp add: combine_matrix_def combine_infmatrix_def)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   752
        apply (rule comb[of "Abs_matrix" "Abs_matrix"], simp, (rule ext)+)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 15392
diff changeset
   753
        apply (simplesubst RepAbs_matrix)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   754
        apply (simp, auto)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   755
        apply (rule exI[of _ "nrows v"], simp add: nrows_le foldseq_zero)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   756
        apply (rule exI[of _ "ncols a"], simp add: ncols_le foldseq_zero)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   757
        apply (subst RepAbs_matrix)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   758
        apply (simp, auto)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   759
        apply (rule exI[of _ "nrows u"], simp add: nrows_le foldseq_zero)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   760
        apply (rule exI[of _ "ncols a"], simp add: ncols_le foldseq_zero)
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   761
        done
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   762
    qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   763
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   764
14691
e1eedc8cad37 tuned instance statements;
wenzelm
parents: 14662
diff changeset
   765
instance matrix :: (zero) zero ..
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   766
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   767
defs(overloaded)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   768
  zero_matrix_def: "(0::('a::zero) matrix) == Abs_matrix(% j i. 0)"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   769
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   770
lemma Rep_zero_matrix_def[simp]: "Rep_matrix 0 j i = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   771
  apply (simp add: zero_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   772
  apply (subst RepAbs_matrix)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   773
  by (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   774
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   775
lemma zero_matrix_def_nrows[simp]: "nrows 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   776
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   777
  have a:"!! (x::nat). x <= 0 \<Longrightarrow> x = 0" by (arith)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   778
  show "nrows 0 = 0" by (rule a, subst nrows_le, simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   779
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   780
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   781
lemma zero_matrix_def_ncols[simp]: "ncols 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   782
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   783
  have a:"!! (x::nat). x <= 0 \<Longrightarrow> x = 0" by (arith)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   784
  show "ncols 0 = 0" by (rule a, subst ncols_le, simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   785
qed
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   786
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   787
lemma combine_matrix_zero_l_neutral: "zero_l_neutral f \<Longrightarrow> zero_l_neutral (combine_matrix f)"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   788
  by (simp add: zero_l_neutral_def combine_matrix_def combine_infmatrix_def)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   789
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   790
lemma combine_matrix_zero_r_neutral: "zero_r_neutral f \<Longrightarrow> zero_r_neutral (combine_matrix f)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   791
  by (simp add: zero_r_neutral_def combine_matrix_def combine_infmatrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   792
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   793
lemma mult_matrix_zero_closed: "\<lbrakk>fadd 0 0 = 0; zero_closed fmul\<rbrakk> \<Longrightarrow> zero_closed (mult_matrix fmul fadd)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   794
  apply (simp add: zero_closed_def mult_matrix_def mult_matrix_n_def)
15580
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
   795
  apply (auto)
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
   796
  by (subst foldseq_zero, (simp add: zero_matrix_def)+)+
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   797
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   798
lemma mult_matrix_n_zero_right[simp]: "\<lbrakk>fadd 0 0 = 0; !a. fmul a 0 = 0\<rbrakk> \<Longrightarrow> mult_matrix_n n fmul fadd A 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   799
  apply (simp add: mult_matrix_n_def)
15580
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
   800
  apply (subst foldseq_zero)
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
   801
  by (simp_all add: zero_matrix_def)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   802
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   803
lemma mult_matrix_n_zero_left[simp]: "\<lbrakk>fadd 0 0 = 0; !a. fmul 0 a = 0\<rbrakk> \<Longrightarrow> mult_matrix_n n fmul fadd 0 A = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   804
  apply (simp add: mult_matrix_n_def)
15580
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
   805
  apply (subst foldseq_zero)
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
   806
  by (simp_all add: zero_matrix_def)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   807
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   808
lemma mult_matrix_zero_left[simp]: "\<lbrakk>fadd 0 0 = 0; !a. fmul 0 a = 0\<rbrakk> \<Longrightarrow> mult_matrix fmul fadd 0 A = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   809
by (simp add: mult_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   810
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   811
lemma mult_matrix_zero_right[simp]: "\<lbrakk>fadd 0 0 = 0; !a. fmul a 0 = 0\<rbrakk> \<Longrightarrow> mult_matrix fmul fadd A 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   812
by (simp add: mult_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   813
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   814
lemma apply_matrix_zero[simp]: "f 0 = 0 \<Longrightarrow> apply_matrix f 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   815
  apply (simp add: apply_matrix_def apply_infmatrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   816
  by (simp add: zero_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   817
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   818
lemma combine_matrix_zero: "f 0 0 = 0 \<Longrightarrow> combine_matrix f 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   819
  apply (simp add: combine_matrix_def combine_infmatrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   820
  by (simp add: zero_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   821
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   822
lemma transpose_matrix_zero[simp]: "transpose_matrix 0 = 0"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   823
apply (simp add: transpose_matrix_def transpose_infmatrix_def zero_matrix_def RepAbs_matrix)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   824
apply (subst Rep_matrix_inject[symmetric], (rule ext)+)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   825
apply (simp add: RepAbs_matrix)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   826
done
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   827
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   828
lemma apply_zero_matrix_def[simp]: "apply_matrix (% x. 0) A = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   829
  apply (simp add: apply_matrix_def apply_infmatrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   830
  by (simp add: zero_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   831
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   832
constdefs
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   833
  singleton_matrix :: "nat \<Rightarrow> nat \<Rightarrow> ('a::zero) \<Rightarrow> 'a matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   834
  "singleton_matrix j i a == Abs_matrix(% m n. if j = m & i = n then a else 0)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   835
  move_matrix :: "('a::zero) matrix \<Rightarrow> int \<Rightarrow> int \<Rightarrow> 'a matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   836
  "move_matrix A y x == Abs_matrix(% j i. if (neg ((int j)-y)) | (neg ((int i)-x)) then 0 else Rep_matrix A (nat ((int j)-y)) (nat ((int i)-x)))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   837
  take_rows :: "('a::zero) matrix \<Rightarrow> nat \<Rightarrow> 'a matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   838
  "take_rows A r == Abs_matrix(% j i. if (j < r) then (Rep_matrix A j i) else 0)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   839
  take_columns :: "('a::zero) matrix \<Rightarrow> nat \<Rightarrow> 'a matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   840
  "take_columns A c == Abs_matrix(% j i. if (i < c) then (Rep_matrix A j i) else 0)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   841
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   842
constdefs
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   843
  column_of_matrix :: "('a::zero) matrix \<Rightarrow> nat \<Rightarrow> 'a matrix"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   844
  "column_of_matrix A n == take_columns (move_matrix A 0 (- int n)) 1"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   845
  row_of_matrix :: "('a::zero) matrix \<Rightarrow> nat \<Rightarrow> 'a matrix"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   846
  "row_of_matrix A m == take_rows (move_matrix A (- int m) 0) 1"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   847
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   848
lemma Rep_singleton_matrix[simp]: "Rep_matrix (singleton_matrix j i e) m n = (if j = m & i = n then e else 0)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   849
apply (simp add: singleton_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   850
apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   851
apply (subst RepAbs_matrix)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   852
apply (rule exI[of _ "Suc m"], simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   853
apply (rule exI[of _ "Suc n"], simp+)
15580
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
   854
by (subst RepAbs_matrix, rule exI[of _ "Suc j"], simp, rule exI[of _ "Suc i"], simp+)+
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   855
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   856
lemma apply_singleton_matrix[simp]: "f 0 = 0 \<Longrightarrow> apply_matrix f (singleton_matrix j i x) = (singleton_matrix j i (f x))"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   857
apply (subst Rep_matrix_inject[symmetric])
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   858
apply (rule ext)+
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   859
apply (simp)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   860
done
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   861
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   862
lemma singleton_matrix_zero[simp]: "singleton_matrix j i 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   863
  by (simp add: singleton_matrix_def zero_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   864
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   865
lemma nrows_singleton[simp]: "nrows(singleton_matrix j i e) = (if e = 0 then 0 else Suc j)"
23315
df3a7e9ebadb tuned Proof
chaieb
parents: 22458
diff changeset
   866
proof-
df3a7e9ebadb tuned Proof
chaieb
parents: 22458
diff changeset
   867
have th: "\<not> (\<forall>m. m \<le> j)" "\<exists>n. \<not> n \<le> i" by arith+
df3a7e9ebadb tuned Proof
chaieb
parents: 22458
diff changeset
   868
from th show ?thesis 
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   869
apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   870
apply (rule le_anti_sym)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   871
apply (subst nrows_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   872
apply (simp add: singleton_matrix_def, auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   873
apply (subst RepAbs_matrix)
23315
df3a7e9ebadb tuned Proof
chaieb
parents: 22458
diff changeset
   874
apply auto
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   875
apply (simp add: Suc_le_eq)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   876
apply (rule not_leE)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   877
apply (subst nrows_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   878
by simp
23315
df3a7e9ebadb tuned Proof
chaieb
parents: 22458
diff changeset
   879
qed
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   880
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   881
lemma ncols_singleton[simp]: "ncols(singleton_matrix j i e) = (if e = 0 then 0 else Suc i)"
23315
df3a7e9ebadb tuned Proof
chaieb
parents: 22458
diff changeset
   882
proof-
df3a7e9ebadb tuned Proof
chaieb
parents: 22458
diff changeset
   883
have th: "\<not> (\<forall>m. m \<le> j)" "\<exists>n. \<not> n \<le> i" by arith+
df3a7e9ebadb tuned Proof
chaieb
parents: 22458
diff changeset
   884
from th show ?thesis 
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   885
apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   886
apply (rule le_anti_sym)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   887
apply (subst ncols_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   888
apply (simp add: singleton_matrix_def, auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   889
apply (subst RepAbs_matrix)
23315
df3a7e9ebadb tuned Proof
chaieb
parents: 22458
diff changeset
   890
apply auto
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   891
apply (simp add: Suc_le_eq)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   892
apply (rule not_leE)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   893
apply (subst ncols_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   894
by simp
23315
df3a7e9ebadb tuned Proof
chaieb
parents: 22458
diff changeset
   895
qed
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   896
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   897
lemma combine_singleton: "f 0 0 = 0 \<Longrightarrow> combine_matrix f (singleton_matrix j i a) (singleton_matrix j i b) = singleton_matrix j i (f a b)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   898
apply (simp add: singleton_matrix_def combine_matrix_def combine_infmatrix_def)
15580
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
   899
apply (subst RepAbs_matrix)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   900
apply (rule exI[of _ "Suc j"], simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   901
apply (rule exI[of _ "Suc i"], simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   902
apply (rule comb[of "Abs_matrix" "Abs_matrix"], simp, (rule ext)+)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   903
apply (subst RepAbs_matrix)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   904
apply (rule exI[of _ "Suc j"], simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   905
apply (rule exI[of _ "Suc i"], simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   906
by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   907
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   908
lemma transpose_singleton[simp]: "transpose_matrix (singleton_matrix j i a) = singleton_matrix i j a"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   909
apply (subst Rep_matrix_inject[symmetric], (rule ext)+)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   910
apply (simp)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   911
done
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   912
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   913
lemma Rep_move_matrix[simp]:
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   914
  "Rep_matrix (move_matrix A y x) j i =
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   915
  (if (neg ((int j)-y)) | (neg ((int i)-x)) then 0 else Rep_matrix A (nat((int j)-y)) (nat((int i)-x)))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   916
apply (simp add: move_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   917
apply (auto)
15580
900291ee0af8 Cleaning up HOL/Matrix
obua
parents: 15488
diff changeset
   918
by (subst RepAbs_matrix,
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   919
  rule exI[of _ "(nrows A)+(nat (abs y))"], auto, rule nrows, arith,
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   920
  rule exI[of _ "(ncols A)+(nat (abs x))"], auto, rule ncols, arith)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   921
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   922
lemma move_matrix_0_0[simp]: "move_matrix A 0 0 = A"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   923
by (simp add: move_matrix_def)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   924
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   925
lemma move_matrix_ortho: "move_matrix A j i = move_matrix (move_matrix A j 0) 0 i"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   926
apply (subst Rep_matrix_inject[symmetric])
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   927
apply (rule ext)+
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   928
apply (simp)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   929
done
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   930
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   931
lemma transpose_move_matrix[simp]:
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   932
  "transpose_matrix (move_matrix A x y) = move_matrix (transpose_matrix A) y x"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   933
apply (subst Rep_matrix_inject[symmetric], (rule ext)+)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   934
apply (simp)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   935
done
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   936
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   937
lemma move_matrix_singleton[simp]: "move_matrix (singleton_matrix u v x) j i = 
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   938
  (if (j + int u < 0) | (i + int v < 0) then 0 else (singleton_matrix (nat (j + int u)) (nat (i + int v)) x))"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   939
  apply (subst Rep_matrix_inject[symmetric])
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   940
  apply (rule ext)+
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   941
  apply (case_tac "j + int u < 0")
20432
07ec57376051 lin_arith_prover: splitting reverted because of performance loss
webertj
parents: 20283
diff changeset
   942
  apply (simp, arith)
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   943
  apply (case_tac "i + int v < 0")
20432
07ec57376051 lin_arith_prover: splitting reverted because of performance loss
webertj
parents: 20283
diff changeset
   944
  apply (simp add: neg_def, arith)
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   945
  apply (simp add: neg_def)
20432
07ec57376051 lin_arith_prover: splitting reverted because of performance loss
webertj
parents: 20283
diff changeset
   946
  apply arith
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   947
  done
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   948
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   949
lemma Rep_take_columns[simp]:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   950
  "Rep_matrix (take_columns A c) j i =
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   951
  (if i < c then (Rep_matrix A j i) else 0)"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   952
apply (simp add: take_columns_def)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 15392
diff changeset
   953
apply (simplesubst RepAbs_matrix)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   954
apply (rule exI[of _ "nrows A"], auto, simp add: nrows_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   955
apply (rule exI[of _ "ncols A"], auto, simp add: ncols_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   956
done
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   957
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   958
lemma Rep_take_rows[simp]:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   959
  "Rep_matrix (take_rows A r) j i =
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
   960
  (if j < r then (Rep_matrix A j i) else 0)"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   961
apply (simp add: take_rows_def)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 15392
diff changeset
   962
apply (simplesubst RepAbs_matrix)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   963
apply (rule exI[of _ "nrows A"], auto, simp add: nrows_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   964
apply (rule exI[of _ "ncols A"], auto, simp add: ncols_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   965
done
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   966
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   967
lemma Rep_column_of_matrix[simp]:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   968
  "Rep_matrix (column_of_matrix A c) j i = (if i = 0 then (Rep_matrix A j c) else 0)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   969
  by (simp add: column_of_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   970
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   971
lemma Rep_row_of_matrix[simp]:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   972
  "Rep_matrix (row_of_matrix A r) j i = (if j = 0 then (Rep_matrix A r i) else 0)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   973
  by (simp add: row_of_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   974
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   975
lemma column_of_matrix: "ncols A <= n \<Longrightarrow> column_of_matrix A n = 0"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   976
apply (subst Rep_matrix_inject[THEN sym])
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   977
apply (rule ext)+
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   978
by (simp add: ncols)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   979
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   980
lemma row_of_matrix: "nrows A <= n \<Longrightarrow> row_of_matrix A n = 0"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   981
apply (subst Rep_matrix_inject[THEN sym])
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   982
apply (rule ext)+
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   983
by (simp add: nrows)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
   984
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   985
lemma mult_matrix_singleton_right[simp]:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   986
  assumes prems:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   987
  "! x. fmul x 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   988
  "! x. fmul 0 x = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   989
  "! x. fadd 0 x = x"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   990
  "! x. fadd x 0 = x"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   991
  shows "(mult_matrix fmul fadd A (singleton_matrix j i e)) = apply_matrix (% x. fmul x e) (move_matrix (column_of_matrix A j) 0 (int i))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   992
  apply (simp add: mult_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   993
  apply (subst mult_matrix_nm[of _ _ _ "max (ncols A) (Suc j)"])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   994
  apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   995
  apply (simp add: prems)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   996
  apply (simp add: mult_matrix_n_def apply_matrix_def apply_infmatrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   997
  apply (rule comb[of "Abs_matrix" "Abs_matrix"], auto, (rule ext)+)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   998
  apply (subst foldseq_almostzero[of _ j])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
   999
  apply (simp add: prems)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1000
  apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1001
  proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1002
    fix k
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1003
    fix l
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1004
    assume a:"~neg(int l - int i)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1005
    assume b:"nat (int l - int i) = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1006
    from a b have a: "l = i" by(insert not_neg_nat[of "int l - int i"], simp add: a b)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1007
    assume c: "i \<noteq> l"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1008
    from c a show "fmul (Rep_matrix A k j) e = 0" by blast
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1009
  qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1010
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1011
lemma mult_matrix_ext:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1012
  assumes
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1013
  eprem:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1014
  "? e. (! a b. a \<noteq> b \<longrightarrow> fmul a e \<noteq> fmul b e)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1015
  and fprems:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1016
  "! a. fmul 0 a = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1017
  "! a. fmul a 0 = 0"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1018
  "! a. fadd a 0 = a"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1019
  "! a. fadd 0 a = a"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1020
  and contraprems:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1021
  "mult_matrix fmul fadd A = mult_matrix fmul fadd B"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1022
  shows
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1023
  "A = B"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1024
proof(rule contrapos_np[of "False"], simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1025
  assume a: "A \<noteq> B"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1026
  have b: "!! f g. (! x y. f x y = g x y) \<Longrightarrow> f = g" by ((rule ext)+, auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1027
  have "? j i. (Rep_matrix A j i) \<noteq> (Rep_matrix B j i)"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1028
    apply (rule contrapos_np[of "False"], simp+)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1029
    apply (insert b[of "Rep_matrix A" "Rep_matrix B"], simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1030
    by (simp add: Rep_matrix_inject a)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1031
  then obtain J I where c:"(Rep_matrix A J I) \<noteq> (Rep_matrix B J I)" by blast
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1032
  from eprem obtain e where eprops:"(! a b. a \<noteq> b \<longrightarrow> fmul a e \<noteq> fmul b e)" by blast
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1033
  let ?S = "singleton_matrix I 0 e"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1034
  let ?comp = "mult_matrix fmul fadd"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1035
  have d: "!!x f g. f = g \<Longrightarrow> f x = g x" by blast
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1036
  have e: "(% x. fmul x e) 0 = 0" by (simp add: prems)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1037
  have "~(?comp A ?S = ?comp B ?S)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1038
    apply (rule notI)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1039
    apply (simp add: fprems eprops)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1040
    apply (simp add: Rep_matrix_inject[THEN sym])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1041
    apply (drule d[of _ _ "J"], drule d[of _ _ "0"])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1042
    by (simp add: e c eprops)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1043
  with contraprems show "False" by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1044
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1045
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1046
constdefs
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1047
  foldmatrix :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> ('a infmatrix) \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> 'a"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1048
  "foldmatrix f g A m n == foldseq_transposed g (% j. foldseq f (A j) n) m"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1049
  foldmatrix_transposed :: "('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> ('a infmatrix) \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> 'a"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1050
  "foldmatrix_transposed f g A m n == foldseq g (% j. foldseq_transposed f (A j) n) m"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1051
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1052
lemma foldmatrix_transpose:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1053
  assumes
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1054
  "! a b c d. g(f a b) (f c d) = f (g a c) (g b d)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1055
  shows
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1056
  "foldmatrix f g A m n = foldmatrix_transposed g f (transpose_infmatrix A) n m" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1057
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1058
  have forall:"!! P x. (! x. P x) \<Longrightarrow> P x" by auto
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1059
  have tworows:"! A. foldmatrix f g A 1 n = foldmatrix_transposed g f (transpose_infmatrix A) n 1"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1060
    apply (induct n)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1061
    apply (simp add: foldmatrix_def foldmatrix_transposed_def prems)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1062
    apply (auto)
16933
91ded127f5f7 fixed var index in tactic;
wenzelm
parents: 16417
diff changeset
  1063
    by (drule_tac x="(% j i. A j (Suc i))" in forall, simp)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1064
  show "foldmatrix f g A m n = foldmatrix_transposed g f (transpose_infmatrix A) n m"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1065
    apply (simp add: foldmatrix_def foldmatrix_transposed_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1066
    apply (induct m, simp)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1067
    apply (simp)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1068
    apply (insert tworows)
15236
f289e8ba2bb3 Proofs needed to be updated because induction now preserves name of
nipkow
parents: 15197
diff changeset
  1069
    apply (drule_tac x="% j i. (if j = 0 then (foldseq_transposed g (\<lambda>u. A u i) m) else (A (Suc m) i))" in spec)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1070
    by (simp add: foldmatrix_def foldmatrix_transposed_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1071
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1072
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1073
lemma foldseq_foldseq:
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1074
assumes
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1075
  "associative f"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1076
  "associative g"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1077
  "! a b c d. g(f a b) (f c d) = f (g a c) (g b d)"
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1078
shows
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1079
  "foldseq g (% j. foldseq f (A j) n) m = foldseq f (% j. foldseq g ((transpose_infmatrix A) j) m) n"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1080
  apply (insert foldmatrix_transpose[of g f A m n])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1081
  by (simp add: foldmatrix_def foldmatrix_transposed_def foldseq_assoc[THEN sym] prems)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1082
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1083
lemma mult_n_nrows:
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1084
assumes
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1085
"! a. fmul 0 a = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1086
"! a. fmul a 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1087
"fadd 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1088
shows "nrows (mult_matrix_n n fmul fadd A B) \<le> nrows A"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1089
apply (subst nrows_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1090
apply (simp add: mult_matrix_n_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1091
apply (subst RepAbs_matrix)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1092
apply (rule_tac x="nrows A" in exI)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1093
apply (simp add: nrows prems foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1094
apply (rule_tac x="ncols B" in exI)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1095
apply (simp add: ncols prems foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1096
by (simp add: nrows prems foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1097
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1098
lemma mult_n_ncols:
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1099
assumes
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1100
"! a. fmul 0 a = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1101
"! a. fmul a 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1102
"fadd 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1103
shows "ncols (mult_matrix_n n fmul fadd A B) \<le> ncols B"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1104
apply (subst ncols_le)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1105
apply (simp add: mult_matrix_n_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1106
apply (subst RepAbs_matrix)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1107
apply (rule_tac x="nrows A" in exI)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1108
apply (simp add: nrows prems foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1109
apply (rule_tac x="ncols B" in exI)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1110
apply (simp add: ncols prems foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1111
by (simp add: ncols prems foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1112
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1113
lemma mult_nrows:
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1114
assumes
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1115
"! a. fmul 0 a = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1116
"! a. fmul a 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1117
"fadd 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1118
shows "nrows (mult_matrix fmul fadd A B) \<le> nrows A"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1119
by (simp add: mult_matrix_def mult_n_nrows prems)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1120
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1121
lemma mult_ncols:
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1122
assumes
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1123
"! a. fmul 0 a = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1124
"! a. fmul a 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1125
"fadd 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1126
shows "ncols (mult_matrix fmul fadd A B) \<le> ncols B"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1127
by (simp add: mult_matrix_def mult_n_ncols prems)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1128
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1129
lemma nrows_move_matrix_le: "nrows (move_matrix A j i) <= nat((int (nrows A)) + j)"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1130
  apply (auto simp add: nrows_le)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1131
  apply (rule nrows)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1132
  apply (arith)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1133
  done
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1134
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1135
lemma ncols_move_matrix_le: "ncols (move_matrix A j i) <= nat((int (ncols A)) + i)"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1136
  apply (auto simp add: ncols_le)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1137
  apply (rule ncols)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1138
  apply (arith)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1139
  done
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1140
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1141
lemma mult_matrix_assoc:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1142
  assumes prems:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1143
  "! a. fmul1 0 a = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1144
  "! a. fmul1 a 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1145
  "! a. fmul2 0 a = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1146
  "! a. fmul2 a 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1147
  "fadd1 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1148
  "fadd2 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1149
  "! a b c d. fadd2 (fadd1 a b) (fadd1 c d) = fadd1 (fadd2 a c) (fadd2 b d)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1150
  "associative fadd1"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1151
  "associative fadd2"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1152
  "! a b c. fmul2 (fmul1 a b) c = fmul1 a (fmul2 b c)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1153
  "! a b c. fmul2 (fadd1 a b) c = fadd1 (fmul2 a c) (fmul2 b c)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1154
  "! a b c. fmul1 c (fadd2 a b) = fadd2 (fmul1 c a) (fmul1 c b)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1155
  shows "mult_matrix fmul2 fadd2 (mult_matrix fmul1 fadd1 A B) C = mult_matrix fmul1 fadd1 A (mult_matrix fmul2 fadd2 B C)" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1156
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1157
  have comb_left:  "!! A B x y. A = B \<Longrightarrow> (Rep_matrix (Abs_matrix A)) x y = (Rep_matrix(Abs_matrix B)) x y" by blast
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1158
  have fmul2fadd1fold: "!! x s n. fmul2 (foldseq fadd1 s n)  x = foldseq fadd1 (% k. fmul2 (s k) x) n"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1159
    by (rule_tac g1 = "% y. fmul2 y x" in ssubst [OF foldseq_distr_unary], simp_all!)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1160
  have fmul1fadd2fold: "!! x s n. fmul1 x (foldseq fadd2 s n) = foldseq fadd2 (% k. fmul1 x (s k)) n"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1161
      by (rule_tac g1 = "% y. fmul1 x y" in ssubst [OF foldseq_distr_unary], simp_all!)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1162
  let ?N = "max (ncols A) (max (ncols B) (max (nrows B) (nrows C)))"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1163
  show ?concl
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1164
    apply (simp add: Rep_matrix_inject[THEN sym])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1165
    apply (rule ext)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1166
    apply (simp add: mult_matrix_def)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 15392
diff changeset
  1167
    apply (simplesubst mult_matrix_nm[of _ "max (ncols (mult_matrix_n (max (ncols A) (nrows B)) fmul1 fadd1 A B)) (nrows C)" _ "max (ncols B) (nrows C)"])
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1168
    apply (simp add: max1 max2 mult_n_ncols mult_n_nrows prems)+
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 15392
diff changeset
  1169
    apply (simplesubst mult_matrix_nm[of _ "max (ncols A) (nrows (mult_matrix_n (max (ncols B) (nrows C)) fmul2 fadd2 B C))" _ "max (ncols A) (nrows B)"])     apply (simp add: max1 max2 mult_n_ncols mult_n_nrows prems)+
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 15392
diff changeset
  1170
    apply (simplesubst mult_matrix_nm[of _ _ _ "?N"])
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1171
    apply (simp add: max1 max2 mult_n_ncols mult_n_nrows prems)+
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 15392
diff changeset
  1172
    apply (simplesubst mult_matrix_nm[of _ _ _ "?N"])
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1173
    apply (simp add: max1 max2 mult_n_ncols mult_n_nrows prems)+
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 15392
diff changeset
  1174
    apply (simplesubst mult_matrix_nm[of _ _ _ "?N"])
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1175
    apply (simp add: max1 max2 mult_n_ncols mult_n_nrows prems)+
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 15392
diff changeset
  1176
    apply (simplesubst mult_matrix_nm[of _ _ _ "?N"])
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1177
    apply (simp add: max1 max2 mult_n_ncols mult_n_nrows prems)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1178
    apply (simp add: mult_matrix_n_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1179
    apply (rule comb_left)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1180
    apply ((rule ext)+, simp)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 15392
diff changeset
  1181
    apply (simplesubst RepAbs_matrix)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1182
    apply (rule exI[of _ "nrows B"])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1183
    apply (simp add: nrows prems foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1184
    apply (rule exI[of _ "ncols C"])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1185
    apply (simp add: prems ncols foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1186
    apply (subst RepAbs_matrix)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1187
    apply (rule exI[of _ "nrows A"])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1188
    apply (simp add: nrows prems foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1189
    apply (rule exI[of _ "ncols B"])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1190
    apply (simp add: prems ncols foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1191
    apply (simp add: fmul2fadd1fold fmul1fadd2fold prems)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1192
    apply (subst foldseq_foldseq)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1193
    apply (simp add: prems)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1194
    by (simp add: transpose_infmatrix)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1195
qed
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1196
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1197
lemma
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1198
  assumes prems:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1199
  "! a. fmul1 0 a = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1200
  "! a. fmul1 a 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1201
  "! a. fmul2 0 a = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1202
  "! a. fmul2 a 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1203
  "fadd1 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1204
  "fadd2 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1205
  "! a b c d. fadd2 (fadd1 a b) (fadd1 c d) = fadd1 (fadd2 a c) (fadd2 b d)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1206
  "associative fadd1"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1207
  "associative fadd2"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1208
  "! a b c. fmul2 (fmul1 a b) c = fmul1 a (fmul2 b c)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1209
  "! a b c. fmul2 (fadd1 a b) c = fadd1 (fmul2 a c) (fmul2 b c)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1210
  "! a b c. fmul1 c (fadd2 a b) = fadd2 (fmul1 c a) (fmul1 c b)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1211
  shows
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1212
  "(mult_matrix fmul1 fadd1 A) o (mult_matrix fmul2 fadd2 B) = mult_matrix fmul2 fadd2 (mult_matrix fmul1 fadd1 A B)"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1213
apply (rule ext)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1214
apply (simp add: comp_def )
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1215
by (simp add: mult_matrix_assoc prems)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1216
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1217
lemma mult_matrix_assoc_simple:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1218
  assumes prems:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1219
  "! a. fmul 0 a = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1220
  "! a. fmul a 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1221
  "fadd 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1222
  "associative fadd"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1223
  "commutative fadd"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1224
  "associative fmul"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1225
  "distributive fmul fadd"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1226
  shows "mult_matrix fmul fadd (mult_matrix fmul fadd A B) C = mult_matrix fmul fadd A (mult_matrix fmul fadd B C)" (is ?concl)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1227
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1228
  have "!! a b c d. fadd (fadd a b) (fadd c d) = fadd (fadd a c) (fadd b d)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1229
    by (simp! add: associative_def commutative_def)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1230
  then show ?concl
15488
7c638a46dcbb tidying of some subst/simplesubst proofs
paulson
parents: 15485
diff changeset
  1231
    apply (subst mult_matrix_assoc)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1232
    apply (simp_all!)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1233
    by (simp add: associative_def distributive_def l_distributive_def r_distributive_def)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1234
qed
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1235
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1236
lemma transpose_apply_matrix: "f 0 = 0 \<Longrightarrow> transpose_matrix (apply_matrix f A) = apply_matrix f (transpose_matrix A)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1237
apply (simp add: Rep_matrix_inject[THEN sym])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1238
apply (rule ext)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1239
by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1240
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1241
lemma transpose_combine_matrix: "f 0 0 = 0 \<Longrightarrow> transpose_matrix (combine_matrix f A B) = combine_matrix f (transpose_matrix A) (transpose_matrix B)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1242
apply (simp add: Rep_matrix_inject[THEN sym])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1243
apply (rule ext)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1244
by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1245
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1246
lemma Rep_mult_matrix:
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1247
  assumes
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1248
  "! a. fmul 0 a = 0"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1249
  "! a. fmul a 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1250
  "fadd 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1251
  shows
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1252
  "Rep_matrix(mult_matrix fmul fadd A B) j i =
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1253
  foldseq fadd (% k. fmul (Rep_matrix A j k) (Rep_matrix B k i)) (max (ncols A) (nrows B))"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1254
apply (simp add: mult_matrix_def mult_matrix_n_def)
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1255
apply (subst RepAbs_matrix)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1256
apply (rule exI[of _ "nrows A"], simp! add: nrows foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1257
apply (rule exI[of _ "ncols B"], simp! add: ncols foldseq_zero)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1258
by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1259
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1260
lemma transpose_mult_matrix:
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1261
  assumes
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1262
  "! a. fmul 0 a = 0"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1263
  "! a. fmul a 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1264
  "fadd 0 0 = 0"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1265
  "! x y. fmul y x = fmul x y"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1266
  shows
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1267
  "transpose_matrix (mult_matrix fmul fadd A B) = mult_matrix fmul fadd (transpose_matrix B) (transpose_matrix A)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1268
  apply (simp add: Rep_matrix_inject[THEN sym])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1269
  apply (rule ext)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1270
  by (simp! add: Rep_mult_matrix max_ac)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1271
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1272
lemma column_transpose_matrix: "column_of_matrix (transpose_matrix A) n = transpose_matrix (row_of_matrix A n)"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1273
apply (simp add:  Rep_matrix_inject[THEN sym])
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1274
apply (rule ext)+
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1275
by simp
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1276
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1277
lemma take_columns_transpose_matrix: "take_columns (transpose_matrix A) n = transpose_matrix (take_rows A n)"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1278
apply (simp add: Rep_matrix_inject[THEN sym])
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1279
apply (rule ext)+
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1280
by simp
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1281
22458
haftmann
parents: 22230
diff changeset
  1282
instance matrix :: ("{ord, zero}") ord
haftmann
parents: 22230
diff changeset
  1283
  le_matrix_def: "A \<le> B \<equiv> \<forall>j i. Rep_matrix A j i \<le> Rep_matrix B j i"
25502
9200b36280c0 instance command as rudimentary class target
haftmann
parents: 23373
diff changeset
  1284
  less_def: "A < (B\<Colon>'a matrix) \<equiv> A \<le> B \<and> A \<noteq> B" ..
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1285
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1286
instance matrix :: ("{order, zero}") order
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1287
apply intro_classes
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1288
apply (simp_all add: le_matrix_def less_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1289
apply (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1290
apply (drule_tac x=j in spec, drule_tac x=j in spec)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1291
apply (drule_tac x=i in spec, drule_tac x=i in spec)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1292
apply (simp)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1293
apply (simp add: Rep_matrix_inject[THEN sym])
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1294
apply (rule ext)+
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1295
apply (drule_tac x=xa in spec, drule_tac x=xa in spec)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1296
apply (drule_tac x=xb in spec, drule_tac x=xb in spec)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1297
by simp
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1298
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1299
lemma le_apply_matrix:
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1300
  assumes
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1301
  "f 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1302
  "! x y. x <= y \<longrightarrow> f x <= f y"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1303
  "(a::('a::{ord, zero}) matrix) <= b"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1304
  shows
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1305
  "apply_matrix f a <= apply_matrix f b"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1306
  by (simp! add: le_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1307
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1308
lemma le_combine_matrix:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1309
  assumes
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1310
  "f 0 0 = 0"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1311
  "! a b c d. a <= b & c <= d \<longrightarrow> f a c <= f b d"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1312
  "A <= B"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1313
  "C <= D"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1314
  shows
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1315
  "combine_matrix f A C <= combine_matrix f B D"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1316
by (simp! add: le_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1317
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1318
lemma le_left_combine_matrix:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1319
  assumes
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1320
  "f 0 0 = 0"
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1321
  "! a b c. a <= b \<longrightarrow> f c a <= f c b"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1322
  "A <= B"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1323
  shows
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1324
  "combine_matrix f C A <= combine_matrix f C B"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1325
  by (simp! add: le_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1326
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1327
lemma le_right_combine_matrix:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1328
  assumes
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1329
  "f 0 0 = 0"
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1330
  "! a b c. a <= b \<longrightarrow> f a c <= f b c"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1331
  "A <= B"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1332
  shows
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1333
  "combine_matrix f A C <= combine_matrix f B C"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1334
  by (simp! add: le_matrix_def)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1335
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1336
lemma le_transpose_matrix: "(A <= B) = (transpose_matrix A <= transpose_matrix B)"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1337
  by (simp add: le_matrix_def, auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1338
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1339
lemma le_foldseq:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1340
  assumes
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1341
  "! a b c d . a <= b & c <= d \<longrightarrow> f a c <= f b d"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1342
  "! i. i <= n \<longrightarrow> s i <= t i"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1343
  shows
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1344
  "foldseq f s n <= foldseq f t n"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1345
proof -
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1346
  have "! s t. (! i. i<=n \<longrightarrow> s i <= t i) \<longrightarrow> foldseq f s n <= foldseq f t n" by (induct_tac n, simp_all!)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1347
  then show "foldseq f s n <= foldseq f t n" by (simp!)
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1348
qed
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1349
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1350
lemma le_left_mult:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1351
  assumes
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1352
  "! a b c d. a <= b & c <= d \<longrightarrow> fadd a c <= fadd b d"
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1353
  "! c a b.   0 <= c & a <= b \<longrightarrow> fmul c a <= fmul c b"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1354
  "! a. fmul 0 a = 0"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1355
  "! a. fmul a 0 = 0"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1356
  "fadd 0 0 = 0"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1357
  "0 <= C"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1358
  "A <= B"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1359
  shows
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1360
  "mult_matrix fmul fadd C A <= mult_matrix fmul fadd C B"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1361
  apply (simp! add: le_matrix_def Rep_mult_matrix)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1362
  apply (auto)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 15392
diff changeset
  1363
  apply (simplesubst foldseq_zerotail[of _ _ _ "max (ncols C) (max (nrows A) (nrows B))"], simp_all add: nrows ncols max1 max2)+
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1364
  apply (rule le_foldseq)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1365
  by (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1366
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1367
lemma le_right_mult:
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1368
  assumes
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1369
  "! a b c d. a <= b & c <= d \<longrightarrow> fadd a c <= fadd b d"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1370
  "! c a b. 0 <= c & a <= b \<longrightarrow> fmul a c <= fmul b c"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1371
  "! a. fmul 0 a = 0"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1372
  "! a. fmul a 0 = 0"
14662
d2c6a0f030ab proper document setup;
wenzelm
parents: 14654
diff changeset
  1373
  "fadd 0 0 = 0"
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1374
  "0 <= C"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1375
  "A <= B"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1376
  shows
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1377
  "mult_matrix fmul fadd A C <= mult_matrix fmul fadd B C"
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1378
  apply (simp! add: le_matrix_def Rep_mult_matrix)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1379
  apply (auto)
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 15392
diff changeset
  1380
  apply (simplesubst foldseq_zerotail[of _ _ _ "max (nrows C) (max (ncols A) (ncols B))"], simp_all add: nrows ncols max1 max2)+
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1381
  apply (rule le_foldseq)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1382
  by (auto)
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1383
15178
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1384
lemma spec2: "! j i. P j i \<Longrightarrow> P j i" by blast
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1385
lemma neg_imp: "(\<not> Q \<longrightarrow> \<not> P) \<Longrightarrow> P \<longrightarrow> Q" by blast
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1386
14940
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1387
lemma singleton_matrix_le[simp]: "(singleton_matrix j i a <= singleton_matrix j i b) = (a <= (b::_::order))"
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1388
  by (auto simp add: le_matrix_def)
b9ab8babd8b3 Further development of matrix theory
obua
parents: 14691
diff changeset
  1389
15178
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1390
lemma singleton_le_zero[simp]: "(singleton_matrix j i x <= 0) = (x <= (0::'a::{order,zero}))"
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1391
  apply (auto)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1392
  apply (simp add: le_matrix_def)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1393
  apply (drule_tac j=j and i=i in spec2)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1394
  apply (simp)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1395
  apply (simp add: le_matrix_def)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1396
  done
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1397
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1398
lemma singleton_ge_zero[simp]: "(0 <= singleton_matrix j i x) = ((0::'a::{order,zero}) <= x)"
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1399
  apply (auto)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1400
  apply (simp add: le_matrix_def)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1401
  apply (drule_tac j=j and i=i in spec2)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1402
  apply (simp)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1403
  apply (simp add: le_matrix_def)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1404
  done
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1405
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1406
lemma move_matrix_le_zero[simp]: "0 <= j \<Longrightarrow> 0 <= i \<Longrightarrow> (move_matrix A j i <= 0) = (A <= (0::('a::{order,zero}) matrix))"
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1407
  apply (auto simp add: le_matrix_def neg_def)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1408
  apply (drule_tac j="ja+(nat j)" and i="ia+(nat i)" in spec2)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1409
  apply (auto)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1410
  done
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1411
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1412
lemma move_matrix_zero_le[simp]: "0 <= j \<Longrightarrow> 0 <= i \<Longrightarrow> (0 <= move_matrix A j i) = ((0::('a::{order,zero}) matrix) <= A)"
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1413
  apply (auto simp add: le_matrix_def neg_def)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1414
  apply (drule_tac j="ja+(nat j)" and i="ia+(nat i)" in spec2)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1415
  apply (auto)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1416
  done
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1417
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1418
lemma move_matrix_le_move_matrix_iff[simp]: "0 <= j \<Longrightarrow> 0 <= i \<Longrightarrow> (move_matrix A j i <= move_matrix B j i) = (A <= (B::('a::{order,zero}) matrix))"
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1419
  apply (auto simp add: le_matrix_def neg_def)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1420
  apply (drule_tac j="ja+(nat j)" and i="ia+(nat i)" in spec2)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1421
  apply (auto)
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1422
  done  
5f621aa35c25 Matrix theory, linear programming
obua
parents: 14940
diff changeset
  1423
14593
90c88e7ef62d first version of matrices for HOL/Isabelle
obua
parents:
diff changeset
  1424
end