src/HOL/Real/HahnBanach/VectorSpace.thy
author wenzelm
Tue Jul 15 19:39:37 2008 +0200 (2008-07-15)
changeset 27612 d3eb431db035
parent 23378 1d138d6bb461
child 29234 60f7fb56f8cd
permissions -rw-r--r--
modernized specifications and proofs;
tuned document;
wenzelm@7917
     1
(*  Title:      HOL/Real/HahnBanach/VectorSpace.thy
wenzelm@7917
     2
    ID:         $Id$
wenzelm@7917
     3
    Author:     Gertrud Bauer, TU Munich
wenzelm@7917
     4
*)
wenzelm@7917
     5
wenzelm@9035
     6
header {* Vector spaces *}
wenzelm@7917
     7
wenzelm@27612
     8
theory VectorSpace
wenzelm@27612
     9
imports Real Bounds Zorn
wenzelm@27612
    10
begin
wenzelm@7917
    11
wenzelm@9035
    12
subsection {* Signature *}
wenzelm@7917
    13
wenzelm@10687
    14
text {*
wenzelm@10687
    15
  For the definition of real vector spaces a type @{typ 'a} of the
wenzelm@10687
    16
  sort @{text "{plus, minus, zero}"} is considered, on which a real
wenzelm@10687
    17
  scalar multiplication @{text \<cdot>} is declared.
wenzelm@10687
    18
*}
wenzelm@7917
    19
wenzelm@7917
    20
consts
wenzelm@10687
    21
  prod  :: "real \<Rightarrow> 'a::{plus, minus, zero} \<Rightarrow> 'a"     (infixr "'(*')" 70)
wenzelm@7917
    22
wenzelm@21210
    23
notation (xsymbols)
wenzelm@19736
    24
  prod  (infixr "\<cdot>" 70)
wenzelm@21210
    25
notation (HTML output)
wenzelm@19736
    26
  prod  (infixr "\<cdot>" 70)
wenzelm@7917
    27
wenzelm@7917
    28
wenzelm@9035
    29
subsection {* Vector space laws *}
wenzelm@7917
    30
wenzelm@10687
    31
text {*
wenzelm@10687
    32
  A \emph{vector space} is a non-empty set @{text V} of elements from
wenzelm@10687
    33
  @{typ 'a} with the following vector space laws: The set @{text V} is
wenzelm@10687
    34
  closed under addition and scalar multiplication, addition is
wenzelm@10687
    35
  associative and commutative; @{text "- x"} is the inverse of @{text
wenzelm@10687
    36
  x} w.~r.~t.~addition and @{text 0} is the neutral element of
wenzelm@10687
    37
  addition.  Addition and multiplication are distributive; scalar
paulson@12018
    38
  multiplication is associative and the real number @{text "1"} is
wenzelm@10687
    39
  the neutral element of scalar multiplication.
wenzelm@9035
    40
*}
wenzelm@7917
    41
wenzelm@13515
    42
locale vectorspace = var V +
wenzelm@13515
    43
  assumes non_empty [iff, intro?]: "V \<noteq> {}"
wenzelm@13515
    44
    and add_closed [iff]: "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> x + y \<in> V"
wenzelm@13515
    45
    and mult_closed [iff]: "x \<in> V \<Longrightarrow> a \<cdot> x \<in> V"
wenzelm@13515
    46
    and add_assoc: "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> z \<in> V \<Longrightarrow> (x + y) + z = x + (y + z)"
wenzelm@13515
    47
    and add_commute: "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> x + y = y + x"
wenzelm@13515
    48
    and diff_self [simp]: "x \<in> V \<Longrightarrow> x - x = 0"
wenzelm@13515
    49
    and add_zero_left [simp]: "x \<in> V \<Longrightarrow> 0 + x = x"
wenzelm@13515
    50
    and add_mult_distrib1: "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> a \<cdot> (x + y) = a \<cdot> x + a \<cdot> y"
wenzelm@13515
    51
    and add_mult_distrib2: "x \<in> V \<Longrightarrow> (a + b) \<cdot> x = a \<cdot> x + b \<cdot> x"
wenzelm@13515
    52
    and mult_assoc: "x \<in> V \<Longrightarrow> (a * b) \<cdot> x = a \<cdot> (b \<cdot> x)"
wenzelm@13515
    53
    and mult_1 [simp]: "x \<in> V \<Longrightarrow> 1 \<cdot> x = x"
wenzelm@13515
    54
    and negate_eq1: "x \<in> V \<Longrightarrow> - x = (- 1) \<cdot> x"
wenzelm@13515
    55
    and diff_eq1: "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> x - y = x + - y"
wenzelm@7917
    56
wenzelm@13515
    57
lemma (in vectorspace) negate_eq2: "x \<in> V \<Longrightarrow> (- 1) \<cdot> x = - x"
wenzelm@13515
    58
  by (rule negate_eq1 [symmetric])
fleuriot@9013
    59
wenzelm@13515
    60
lemma (in vectorspace) negate_eq2a: "x \<in> V \<Longrightarrow> -1 \<cdot> x = - x"
wenzelm@13515
    61
  by (simp add: negate_eq1)
wenzelm@7917
    62
wenzelm@13515
    63
lemma (in vectorspace) diff_eq2: "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> x + - y = x - y"
wenzelm@13515
    64
  by (rule diff_eq1 [symmetric])
wenzelm@7917
    65
wenzelm@13515
    66
lemma (in vectorspace) diff_closed [iff]: "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> x - y \<in> V"
wenzelm@9035
    67
  by (simp add: diff_eq1 negate_eq1)
wenzelm@7917
    68
wenzelm@13515
    69
lemma (in vectorspace) neg_closed [iff]: "x \<in> V \<Longrightarrow> - x \<in> V"
wenzelm@9035
    70
  by (simp add: negate_eq1)
wenzelm@7917
    71
wenzelm@13515
    72
lemma (in vectorspace) add_left_commute:
wenzelm@13515
    73
  "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> z \<in> V \<Longrightarrow> x + (y + z) = y + (x + z)"
wenzelm@9035
    74
proof -
wenzelm@13515
    75
  assume xyz: "x \<in> V"  "y \<in> V"  "z \<in> V"
wenzelm@27612
    76
  then have "x + (y + z) = (x + y) + z"
wenzelm@13515
    77
    by (simp only: add_assoc)
wenzelm@27612
    78
  also from xyz have "\<dots> = (y + x) + z" by (simp only: add_commute)
wenzelm@27612
    79
  also from xyz have "\<dots> = y + (x + z)" by (simp only: add_assoc)
wenzelm@9035
    80
  finally show ?thesis .
wenzelm@9035
    81
qed
wenzelm@7917
    82
wenzelm@13515
    83
theorems (in vectorspace) add_ac =
wenzelm@13515
    84
  add_assoc add_commute add_left_commute
wenzelm@7917
    85
wenzelm@7917
    86
wenzelm@7978
    87
text {* The existence of the zero element of a vector space
wenzelm@13515
    88
  follows from the non-emptiness of carrier set. *}
wenzelm@7917
    89
wenzelm@13515
    90
lemma (in vectorspace) zero [iff]: "0 \<in> V"
wenzelm@10687
    91
proof -
wenzelm@13515
    92
  from non_empty obtain x where x: "x \<in> V" by blast
wenzelm@13515
    93
  then have "0 = x - x" by (rule diff_self [symmetric])
wenzelm@27612
    94
  also from x x have "\<dots> \<in> V" by (rule diff_closed)
wenzelm@11472
    95
  finally show ?thesis .
wenzelm@9035
    96
qed
wenzelm@7917
    97
wenzelm@13515
    98
lemma (in vectorspace) add_zero_right [simp]:
wenzelm@13515
    99
  "x \<in> V \<Longrightarrow>  x + 0 = x"
wenzelm@9035
   100
proof -
wenzelm@13515
   101
  assume x: "x \<in> V"
wenzelm@13515
   102
  from this and zero have "x + 0 = 0 + x" by (rule add_commute)
wenzelm@27612
   103
  also from x have "\<dots> = x" by (rule add_zero_left)
wenzelm@9035
   104
  finally show ?thesis .
wenzelm@9035
   105
qed
wenzelm@7917
   106
wenzelm@13515
   107
lemma (in vectorspace) mult_assoc2:
wenzelm@13515
   108
    "x \<in> V \<Longrightarrow> a \<cdot> b \<cdot> x = (a * b) \<cdot> x"
wenzelm@13515
   109
  by (simp only: mult_assoc)
wenzelm@7917
   110
wenzelm@13515
   111
lemma (in vectorspace) diff_mult_distrib1:
wenzelm@13515
   112
    "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> a \<cdot> (x - y) = a \<cdot> x - a \<cdot> y"
wenzelm@13515
   113
  by (simp add: diff_eq1 negate_eq1 add_mult_distrib1 mult_assoc2)
wenzelm@7917
   114
wenzelm@13515
   115
lemma (in vectorspace) diff_mult_distrib2:
wenzelm@13515
   116
  "x \<in> V \<Longrightarrow> (a - b) \<cdot> x = a \<cdot> x - (b \<cdot> x)"
wenzelm@9035
   117
proof -
wenzelm@13515
   118
  assume x: "x \<in> V"
wenzelm@10687
   119
  have " (a - b) \<cdot> x = (a + - b) \<cdot> x"
wenzelm@13515
   120
    by (simp add: real_diff_def)
wenzelm@27612
   121
  also from x have "\<dots> = a \<cdot> x + (- b) \<cdot> x"
wenzelm@13515
   122
    by (rule add_mult_distrib2)
wenzelm@27612
   123
  also from x have "\<dots> = a \<cdot> x + - (b \<cdot> x)"
wenzelm@13515
   124
    by (simp add: negate_eq1 mult_assoc2)
wenzelm@27612
   125
  also from x have "\<dots> = a \<cdot> x - (b \<cdot> x)"
wenzelm@13515
   126
    by (simp add: diff_eq1)
wenzelm@9035
   127
  finally show ?thesis .
wenzelm@9035
   128
qed
wenzelm@7917
   129
wenzelm@13515
   130
lemmas (in vectorspace) distrib =
wenzelm@13515
   131
  add_mult_distrib1 add_mult_distrib2
wenzelm@13515
   132
  diff_mult_distrib1 diff_mult_distrib2
wenzelm@13515
   133
wenzelm@10687
   134
wenzelm@10687
   135
text {* \medskip Further derived laws: *}
wenzelm@7917
   136
wenzelm@13515
   137
lemma (in vectorspace) mult_zero_left [simp]:
wenzelm@13515
   138
  "x \<in> V \<Longrightarrow> 0 \<cdot> x = 0"
wenzelm@9035
   139
proof -
wenzelm@13515
   140
  assume x: "x \<in> V"
wenzelm@13515
   141
  have "0 \<cdot> x = (1 - 1) \<cdot> x" by simp
wenzelm@27612
   142
  also have "\<dots> = (1 + - 1) \<cdot> x" by simp
wenzelm@27612
   143
  also from x have "\<dots> =  1 \<cdot> x + (- 1) \<cdot> x"
wenzelm@13515
   144
    by (rule add_mult_distrib2)
wenzelm@27612
   145
  also from x have "\<dots> = x + (- 1) \<cdot> x" by simp
wenzelm@27612
   146
  also from x have "\<dots> = x + - x" by (simp add: negate_eq2a)
wenzelm@27612
   147
  also from x have "\<dots> = x - x" by (simp add: diff_eq2)
wenzelm@27612
   148
  also from x have "\<dots> = 0" by simp
wenzelm@9035
   149
  finally show ?thesis .
wenzelm@9035
   150
qed
wenzelm@7917
   151
wenzelm@13515
   152
lemma (in vectorspace) mult_zero_right [simp]:
wenzelm@13515
   153
  "a \<cdot> 0 = (0::'a)"
wenzelm@9035
   154
proof -
wenzelm@13515
   155
  have "a \<cdot> 0 = a \<cdot> (0 - (0::'a))" by simp
wenzelm@27612
   156
  also have "\<dots> =  a \<cdot> 0 - a \<cdot> 0"
wenzelm@13515
   157
    by (rule diff_mult_distrib1) simp_all
wenzelm@27612
   158
  also have "\<dots> = 0" by simp
wenzelm@9035
   159
  finally show ?thesis .
wenzelm@9035
   160
qed
wenzelm@7917
   161
wenzelm@13515
   162
lemma (in vectorspace) minus_mult_cancel [simp]:
wenzelm@13515
   163
    "x \<in> V \<Longrightarrow> (- a) \<cdot> - x = a \<cdot> x"
wenzelm@13515
   164
  by (simp add: negate_eq1 mult_assoc2)
wenzelm@7917
   165
wenzelm@13515
   166
lemma (in vectorspace) add_minus_left_eq_diff:
wenzelm@13515
   167
  "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> - x + y = y - x"
wenzelm@10687
   168
proof -
wenzelm@13515
   169
  assume xy: "x \<in> V"  "y \<in> V"
wenzelm@27612
   170
  then have "- x + y = y + - x" by (simp add: add_commute)
wenzelm@27612
   171
  also from xy have "\<dots> = y - x" by (simp add: diff_eq1)
wenzelm@9035
   172
  finally show ?thesis .
wenzelm@9035
   173
qed
wenzelm@7917
   174
wenzelm@13515
   175
lemma (in vectorspace) add_minus [simp]:
wenzelm@13515
   176
    "x \<in> V \<Longrightarrow> x + - x = 0"
wenzelm@13515
   177
  by (simp add: diff_eq2)
wenzelm@7917
   178
wenzelm@13515
   179
lemma (in vectorspace) add_minus_left [simp]:
wenzelm@13515
   180
    "x \<in> V \<Longrightarrow> - x + x = 0"
wenzelm@13515
   181
  by (simp add: diff_eq2 add_commute)
wenzelm@7917
   182
wenzelm@13515
   183
lemma (in vectorspace) minus_minus [simp]:
wenzelm@13515
   184
    "x \<in> V \<Longrightarrow> - (- x) = x"
wenzelm@13515
   185
  by (simp add: negate_eq1 mult_assoc2)
wenzelm@13515
   186
wenzelm@13515
   187
lemma (in vectorspace) minus_zero [simp]:
wenzelm@13515
   188
    "- (0::'a) = 0"
wenzelm@9035
   189
  by (simp add: negate_eq1)
wenzelm@7917
   190
wenzelm@13515
   191
lemma (in vectorspace) minus_zero_iff [simp]:
wenzelm@13515
   192
  "x \<in> V \<Longrightarrow> (- x = 0) = (x = 0)"
wenzelm@13515
   193
proof
wenzelm@13515
   194
  assume x: "x \<in> V"
wenzelm@13515
   195
  {
wenzelm@13515
   196
    from x have "x = - (- x)" by (simp add: minus_minus)
wenzelm@13515
   197
    also assume "- x = 0"
wenzelm@27612
   198
    also have "- \<dots> = 0" by (rule minus_zero)
wenzelm@13515
   199
    finally show "x = 0" .
wenzelm@13515
   200
  next
wenzelm@13515
   201
    assume "x = 0"
wenzelm@13515
   202
    then show "- x = 0" by simp
wenzelm@13515
   203
  }
wenzelm@9035
   204
qed
wenzelm@7917
   205
wenzelm@13515
   206
lemma (in vectorspace) add_minus_cancel [simp]:
wenzelm@13515
   207
    "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> x + (- x + y) = y"
wenzelm@13515
   208
  by (simp add: add_assoc [symmetric] del: add_commute)
wenzelm@7917
   209
wenzelm@13515
   210
lemma (in vectorspace) minus_add_cancel [simp]:
wenzelm@13515
   211
    "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> - x + (x + y) = y"
wenzelm@13515
   212
  by (simp add: add_assoc [symmetric] del: add_commute)
wenzelm@7917
   213
wenzelm@13515
   214
lemma (in vectorspace) minus_add_distrib [simp]:
wenzelm@13515
   215
    "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> - (x + y) = - x + - y"
wenzelm@13515
   216
  by (simp add: negate_eq1 add_mult_distrib1)
wenzelm@7917
   217
wenzelm@13515
   218
lemma (in vectorspace) diff_zero [simp]:
wenzelm@13515
   219
    "x \<in> V \<Longrightarrow> x - 0 = x"
wenzelm@13515
   220
  by (simp add: diff_eq1)
wenzelm@13515
   221
wenzelm@13515
   222
lemma (in vectorspace) diff_zero_right [simp]:
wenzelm@13515
   223
    "x \<in> V \<Longrightarrow> 0 - x = - x"
wenzelm@10687
   224
  by (simp add: diff_eq1)
wenzelm@7917
   225
wenzelm@13515
   226
lemma (in vectorspace) add_left_cancel:
wenzelm@13515
   227
  "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> z \<in> V \<Longrightarrow> (x + y = x + z) = (y = z)"
wenzelm@9035
   228
proof
wenzelm@13515
   229
  assume x: "x \<in> V" and y: "y \<in> V" and z: "z \<in> V"
wenzelm@13515
   230
  {
wenzelm@13515
   231
    from y have "y = 0 + y" by simp
wenzelm@27612
   232
    also from x y have "\<dots> = (- x + x) + y" by simp
wenzelm@27612
   233
    also from x y have "\<dots> = - x + (x + y)"
wenzelm@13515
   234
      by (simp add: add_assoc neg_closed)
wenzelm@13515
   235
    also assume "x + y = x + z"
wenzelm@13515
   236
    also from x z have "- x + (x + z) = - x + x + z"
wenzelm@13515
   237
      by (simp add: add_assoc [symmetric] neg_closed)
wenzelm@27612
   238
    also from x z have "\<dots> = z" by simp
wenzelm@13515
   239
    finally show "y = z" .
wenzelm@13515
   240
  next
wenzelm@13515
   241
    assume "y = z"
wenzelm@13515
   242
    then show "x + y = x + z" by (simp only:)
wenzelm@13515
   243
  }
wenzelm@13515
   244
qed
wenzelm@7917
   245
wenzelm@13515
   246
lemma (in vectorspace) add_right_cancel:
wenzelm@13515
   247
    "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> z \<in> V \<Longrightarrow> (y + x = z + x) = (y = z)"
wenzelm@13515
   248
  by (simp only: add_commute add_left_cancel)
wenzelm@7917
   249
wenzelm@13515
   250
lemma (in vectorspace) add_assoc_cong:
wenzelm@13515
   251
  "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> x' \<in> V \<Longrightarrow> y' \<in> V \<Longrightarrow> z \<in> V
wenzelm@13515
   252
    \<Longrightarrow> x + y = x' + y' \<Longrightarrow> x + (y + z) = x' + (y' + z)"
wenzelm@13515
   253
  by (simp only: add_assoc [symmetric])
wenzelm@7917
   254
wenzelm@13515
   255
lemma (in vectorspace) mult_left_commute:
wenzelm@13515
   256
    "x \<in> V \<Longrightarrow> a \<cdot> b \<cdot> x = b \<cdot> a \<cdot> x"
wenzelm@13515
   257
  by (simp add: real_mult_commute mult_assoc2)
wenzelm@7917
   258
wenzelm@13515
   259
lemma (in vectorspace) mult_zero_uniq:
wenzelm@13515
   260
  "x \<in> V \<Longrightarrow> x \<noteq> 0 \<Longrightarrow> a \<cdot> x = 0 \<Longrightarrow> a = 0"
wenzelm@9035
   261
proof (rule classical)
wenzelm@13515
   262
  assume a: "a \<noteq> 0"
wenzelm@13515
   263
  assume x: "x \<in> V"  "x \<noteq> 0" and ax: "a \<cdot> x = 0"
wenzelm@13515
   264
  from x a have "x = (inverse a * a) \<cdot> x" by simp
wenzelm@27612
   265
  also from `x \<in> V` have "\<dots> = inverse a \<cdot> (a \<cdot> x)" by (rule mult_assoc)
wenzelm@27612
   266
  also from ax have "\<dots> = inverse a \<cdot> 0" by simp
wenzelm@27612
   267
  also have "\<dots> = 0" by simp
bauerg@9374
   268
  finally have "x = 0" .
wenzelm@23378
   269
  with `x \<noteq> 0` show "a = 0" by contradiction
wenzelm@9035
   270
qed
wenzelm@7917
   271
wenzelm@13515
   272
lemma (in vectorspace) mult_left_cancel:
wenzelm@13515
   273
  "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> (a \<cdot> x = a \<cdot> y) = (x = y)"
wenzelm@9035
   274
proof
wenzelm@13515
   275
  assume x: "x \<in> V" and y: "y \<in> V" and a: "a \<noteq> 0"
wenzelm@13515
   276
  from x have "x = 1 \<cdot> x" by simp
wenzelm@27612
   277
  also from a have "\<dots> = (inverse a * a) \<cdot> x" by simp
wenzelm@27612
   278
  also from x have "\<dots> = inverse a \<cdot> (a \<cdot> x)"
wenzelm@13515
   279
    by (simp only: mult_assoc)
wenzelm@13515
   280
  also assume "a \<cdot> x = a \<cdot> y"
wenzelm@27612
   281
  also from a y have "inverse a \<cdot> \<dots> = y"
wenzelm@13515
   282
    by (simp add: mult_assoc2)
wenzelm@13515
   283
  finally show "x = y" .
wenzelm@13515
   284
next
wenzelm@13515
   285
  assume "x = y"
wenzelm@13515
   286
  then show "a \<cdot> x = a \<cdot> y" by (simp only:)
wenzelm@13515
   287
qed
wenzelm@7917
   288
wenzelm@13515
   289
lemma (in vectorspace) mult_right_cancel:
wenzelm@13515
   290
  "x \<in> V \<Longrightarrow> x \<noteq> 0 \<Longrightarrow> (a \<cdot> x = b \<cdot> x) = (a = b)"
wenzelm@9035
   291
proof
wenzelm@13515
   292
  assume x: "x \<in> V" and neq: "x \<noteq> 0"
wenzelm@13515
   293
  {
wenzelm@13515
   294
    from x have "(a - b) \<cdot> x = a \<cdot> x - b \<cdot> x"
wenzelm@13515
   295
      by (simp add: diff_mult_distrib2)
wenzelm@13515
   296
    also assume "a \<cdot> x = b \<cdot> x"
wenzelm@13515
   297
    with x have "a \<cdot> x - b \<cdot> x = 0" by simp
wenzelm@13515
   298
    finally have "(a - b) \<cdot> x = 0" .
wenzelm@13515
   299
    with x neq have "a - b = 0" by (rule mult_zero_uniq)
wenzelm@27612
   300
    then show "a = b" by simp
wenzelm@13515
   301
  next
wenzelm@13515
   302
    assume "a = b"
wenzelm@13515
   303
    then show "a \<cdot> x = b \<cdot> x" by (simp only:)
wenzelm@13515
   304
  }
wenzelm@13515
   305
qed
wenzelm@7917
   306
wenzelm@13515
   307
lemma (in vectorspace) eq_diff_eq:
wenzelm@13515
   308
  "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> z \<in> V \<Longrightarrow> (x = z - y) = (x + y = z)"
wenzelm@13515
   309
proof
wenzelm@13515
   310
  assume x: "x \<in> V" and y: "y \<in> V" and z: "z \<in> V"
wenzelm@13515
   311
  {
wenzelm@13515
   312
    assume "x = z - y"
wenzelm@27612
   313
    then have "x + y = z - y + y" by simp
wenzelm@27612
   314
    also from y z have "\<dots> = z + - y + y"
wenzelm@13515
   315
      by (simp add: diff_eq1)
wenzelm@27612
   316
    also have "\<dots> = z + (- y + y)"
wenzelm@13515
   317
      by (rule add_assoc) (simp_all add: y z)
wenzelm@27612
   318
    also from y z have "\<dots> = z + 0"
wenzelm@13515
   319
      by (simp only: add_minus_left)
wenzelm@27612
   320
    also from z have "\<dots> = z"
wenzelm@13515
   321
      by (simp only: add_zero_right)
wenzelm@13515
   322
    finally show "x + y = z" .
wenzelm@9035
   323
  next
wenzelm@13515
   324
    assume "x + y = z"
wenzelm@27612
   325
    then have "z - y = (x + y) - y" by simp
wenzelm@27612
   326
    also from x y have "\<dots> = x + y + - y"
wenzelm@9035
   327
      by (simp add: diff_eq1)
wenzelm@27612
   328
    also have "\<dots> = x + (y + - y)"
wenzelm@13515
   329
      by (rule add_assoc) (simp_all add: x y)
wenzelm@27612
   330
    also from x y have "\<dots> = x" by simp
wenzelm@13515
   331
    finally show "x = z - y" ..
wenzelm@13515
   332
  }
wenzelm@9035
   333
qed
wenzelm@7917
   334
wenzelm@13515
   335
lemma (in vectorspace) add_minus_eq_minus:
wenzelm@13515
   336
  "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> x + y = 0 \<Longrightarrow> x = - y"
wenzelm@9035
   337
proof -
wenzelm@13515
   338
  assume x: "x \<in> V" and y: "y \<in> V"
wenzelm@13515
   339
  from x y have "x = (- y + y) + x" by simp
wenzelm@27612
   340
  also from x y have "\<dots> = - y + (x + y)" by (simp add: add_ac)
bauerg@9374
   341
  also assume "x + y = 0"
wenzelm@13515
   342
  also from y have "- y + 0 = - y" by simp
wenzelm@9035
   343
  finally show "x = - y" .
wenzelm@9035
   344
qed
wenzelm@7917
   345
wenzelm@13515
   346
lemma (in vectorspace) add_minus_eq:
wenzelm@13515
   347
  "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> x - y = 0 \<Longrightarrow> x = y"
wenzelm@9035
   348
proof -
wenzelm@13515
   349
  assume x: "x \<in> V" and y: "y \<in> V"
bauerg@9374
   350
  assume "x - y = 0"
wenzelm@13515
   351
  with x y have eq: "x + - y = 0" by (simp add: diff_eq1)
wenzelm@13515
   352
  with _ _ have "x = - (- y)"
wenzelm@13515
   353
    by (rule add_minus_eq_minus) (simp_all add: x y)
wenzelm@13515
   354
  with x y show "x = y" by simp
wenzelm@9035
   355
qed
wenzelm@7917
   356
wenzelm@13515
   357
lemma (in vectorspace) add_diff_swap:
wenzelm@13515
   358
  "a \<in> V \<Longrightarrow> b \<in> V \<Longrightarrow> c \<in> V \<Longrightarrow> d \<in> V \<Longrightarrow> a + b = c + d
wenzelm@13515
   359
    \<Longrightarrow> a - c = d - b"
wenzelm@10687
   360
proof -
wenzelm@13515
   361
  assume vs: "a \<in> V"  "b \<in> V"  "c \<in> V"  "d \<in> V"
wenzelm@9035
   362
    and eq: "a + b = c + d"
wenzelm@13515
   363
  then have "- c + (a + b) = - c + (c + d)"
wenzelm@13515
   364
    by (simp add: add_left_cancel)
wenzelm@27612
   365
  also have "\<dots> = d" using `c \<in> V` `d \<in> V` by (rule minus_add_cancel)
wenzelm@9035
   366
  finally have eq: "- c + (a + b) = d" .
wenzelm@10687
   367
  from vs have "a - c = (- c + (a + b)) + - b"
wenzelm@13515
   368
    by (simp add: add_ac diff_eq1)
wenzelm@27612
   369
  also from vs eq have "\<dots>  = d + - b"
wenzelm@13515
   370
    by (simp add: add_right_cancel)
wenzelm@27612
   371
  also from vs have "\<dots> = d - b" by (simp add: diff_eq2)
wenzelm@9035
   372
  finally show "a - c = d - b" .
wenzelm@9035
   373
qed
wenzelm@7917
   374
wenzelm@13515
   375
lemma (in vectorspace) vs_add_cancel_21:
wenzelm@13515
   376
  "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> z \<in> V \<Longrightarrow> u \<in> V
wenzelm@13515
   377
    \<Longrightarrow> (x + (y + z) = y + u) = (x + z = u)"
wenzelm@13515
   378
proof
wenzelm@13515
   379
  assume vs: "x \<in> V"  "y \<in> V"  "z \<in> V"  "u \<in> V"
wenzelm@13515
   380
  {
wenzelm@13515
   381
    from vs have "x + z = - y + y + (x + z)" by simp
wenzelm@27612
   382
    also have "\<dots> = - y + (y + (x + z))"
wenzelm@13515
   383
      by (rule add_assoc) (simp_all add: vs)
wenzelm@13515
   384
    also from vs have "y + (x + z) = x + (y + z)"
wenzelm@13515
   385
      by (simp add: add_ac)
wenzelm@13515
   386
    also assume "x + (y + z) = y + u"
wenzelm@13515
   387
    also from vs have "- y + (y + u) = u" by simp
wenzelm@13515
   388
    finally show "x + z = u" .
wenzelm@13515
   389
  next
wenzelm@13515
   390
    assume "x + z = u"
wenzelm@13515
   391
    with vs show "x + (y + z) = y + u"
wenzelm@13515
   392
      by (simp only: add_left_commute [of x])
wenzelm@13515
   393
  }
wenzelm@9035
   394
qed
wenzelm@7917
   395
wenzelm@13515
   396
lemma (in vectorspace) add_cancel_end:
wenzelm@13515
   397
  "x \<in> V \<Longrightarrow> y \<in> V \<Longrightarrow> z \<in> V \<Longrightarrow> (x + (y + z) = y) = (x = - z)"
wenzelm@13515
   398
proof
wenzelm@13515
   399
  assume vs: "x \<in> V"  "y \<in> V"  "z \<in> V"
wenzelm@13515
   400
  {
wenzelm@13515
   401
    assume "x + (y + z) = y"
wenzelm@13515
   402
    with vs have "(x + z) + y = 0 + y"
wenzelm@13515
   403
      by (simp add: add_ac)
wenzelm@13515
   404
    with vs have "x + z = 0"
wenzelm@13515
   405
      by (simp only: add_right_cancel add_closed zero)
wenzelm@13515
   406
    with vs show "x = - z" by (simp add: add_minus_eq_minus)
wenzelm@9035
   407
  next
wenzelm@13515
   408
    assume eq: "x = - z"
wenzelm@27612
   409
    then have "x + (y + z) = - z + (y + z)" by simp
wenzelm@27612
   410
    also have "\<dots> = y + (- z + z)"
wenzelm@13515
   411
      by (rule add_left_commute) (simp_all add: vs)
wenzelm@27612
   412
    also from vs have "\<dots> = y"  by simp
wenzelm@13515
   413
    finally show "x + (y + z) = y" .
wenzelm@13515
   414
  }
wenzelm@9035
   415
qed
wenzelm@7917
   416
wenzelm@10687
   417
end