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