src/HOL/Library/Product_plus.thy
author Christian Sternagel
Wed, 29 Aug 2012 12:24:26 +0900
changeset 49084 e3973567ed4f
parent 44066 d74182c93f04
child 51002 496013a6eb38
permissions -rw-r--r--
base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
     1
(*  Title:      HOL/Library/Product_plus.thy
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
     2
    Author:     Brian Huffman
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
     3
*)
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
     4
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
     5
header {* Additive group operations on product types *}
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
     6
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
     7
theory Product_plus
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
     8
imports Main
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
     9
begin
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    10
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    11
subsection {* Operations *}
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    12
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37664
diff changeset
    13
instantiation prod :: (zero, zero) zero
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    14
begin
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    15
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    16
definition zero_prod_def: "0 = (0, 0)"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    17
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    18
instance ..
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    19
end
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    20
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37664
diff changeset
    21
instantiation prod :: (plus, plus) plus
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    22
begin
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    23
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    24
definition plus_prod_def:
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    25
  "x + y = (fst x + fst y, snd x + snd y)"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    26
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    27
instance ..
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    28
end
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    29
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37664
diff changeset
    30
instantiation prod :: (minus, minus) minus
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    31
begin
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    32
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    33
definition minus_prod_def:
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    34
  "x - y = (fst x - fst y, snd x - snd y)"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    35
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    36
instance ..
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    37
end
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    38
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37664
diff changeset
    39
instantiation prod :: (uminus, uminus) uminus
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    40
begin
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    41
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    42
definition uminus_prod_def:
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    43
  "- x = (- fst x, - snd x)"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    44
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    45
instance ..
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    46
end
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    47
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    48
lemma fst_zero [simp]: "fst 0 = 0"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    49
  unfolding zero_prod_def by simp
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    50
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    51
lemma snd_zero [simp]: "snd 0 = 0"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    52
  unfolding zero_prod_def by simp
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    53
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    54
lemma fst_add [simp]: "fst (x + y) = fst x + fst y"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    55
  unfolding plus_prod_def by simp
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    56
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    57
lemma snd_add [simp]: "snd (x + y) = snd x + snd y"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    58
  unfolding plus_prod_def by simp
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    59
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    60
lemma fst_diff [simp]: "fst (x - y) = fst x - fst y"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    61
  unfolding minus_prod_def by simp
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    62
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    63
lemma snd_diff [simp]: "snd (x - y) = snd x - snd y"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    64
  unfolding minus_prod_def by simp
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    65
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    66
lemma fst_uminus [simp]: "fst (- x) = - fst x"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    67
  unfolding uminus_prod_def by simp
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    68
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    69
lemma snd_uminus [simp]: "snd (- x) = - snd x"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    70
  unfolding uminus_prod_def by simp
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    71
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    72
lemma add_Pair [simp]: "(a, b) + (c, d) = (a + c, b + d)"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    73
  unfolding plus_prod_def by simp
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    74
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    75
lemma diff_Pair [simp]: "(a, b) - (c, d) = (a - c, b - d)"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    76
  unfolding minus_prod_def by simp
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    77
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    78
lemma uminus_Pair [simp, code]: "- (a, b) = (- a, - b)"
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    79
  unfolding uminus_prod_def by simp
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    80
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    81
subsection {* Class instances *}
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    82
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37664
diff changeset
    83
instance prod :: (semigroup_add, semigroup_add) semigroup_add
44066
d74182c93f04 rename Pair_fst_snd_eq to prod_eq_iff (keeping old name too)
huffman
parents: 37678
diff changeset
    84
  by default (simp add: prod_eq_iff add_assoc)
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    85
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37664
diff changeset
    86
instance prod :: (ab_semigroup_add, ab_semigroup_add) ab_semigroup_add
44066
d74182c93f04 rename Pair_fst_snd_eq to prod_eq_iff (keeping old name too)
huffman
parents: 37678
diff changeset
    87
  by default (simp add: prod_eq_iff add_commute)
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    88
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37664
diff changeset
    89
instance prod :: (monoid_add, monoid_add) monoid_add
44066
d74182c93f04 rename Pair_fst_snd_eq to prod_eq_iff (keeping old name too)
huffman
parents: 37678
diff changeset
    90
  by default (simp_all add: prod_eq_iff)
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    91
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37664
diff changeset
    92
instance prod :: (comm_monoid_add, comm_monoid_add) comm_monoid_add
44066
d74182c93f04 rename Pair_fst_snd_eq to prod_eq_iff (keeping old name too)
huffman
parents: 37678
diff changeset
    93
  by default (simp add: prod_eq_iff)
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    94
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37664
diff changeset
    95
instance prod ::
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    96
  (cancel_semigroup_add, cancel_semigroup_add) cancel_semigroup_add
44066
d74182c93f04 rename Pair_fst_snd_eq to prod_eq_iff (keeping old name too)
huffman
parents: 37678
diff changeset
    97
    by default (simp_all add: prod_eq_iff)
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
    98
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37664
diff changeset
    99
instance prod ::
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
   100
  (cancel_ab_semigroup_add, cancel_ab_semigroup_add) cancel_ab_semigroup_add
44066
d74182c93f04 rename Pair_fst_snd_eq to prod_eq_iff (keeping old name too)
huffman
parents: 37678
diff changeset
   101
    by default (simp add: prod_eq_iff)
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
   102
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37664
diff changeset
   103
instance prod ::
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
   104
  (cancel_comm_monoid_add, cancel_comm_monoid_add) cancel_comm_monoid_add ..
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
   105
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37664
diff changeset
   106
instance prod :: (group_add, group_add) group_add
44066
d74182c93f04 rename Pair_fst_snd_eq to prod_eq_iff (keeping old name too)
huffman
parents: 37678
diff changeset
   107
  by default (simp_all add: prod_eq_iff diff_minus)
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
   108
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37664
diff changeset
   109
instance prod :: (ab_group_add, ab_group_add) ab_group_add
44066
d74182c93f04 rename Pair_fst_snd_eq to prod_eq_iff (keeping old name too)
huffman
parents: 37678
diff changeset
   110
  by default (simp_all add: prod_eq_iff)
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
   111
36627
39b2516a1970 move setsum lemmas to Product_plus.thy
huffman
parents: 30018
diff changeset
   112
lemma fst_setsum: "fst (\<Sum>x\<in>A. f x) = (\<Sum>x\<in>A. fst (f x))"
39b2516a1970 move setsum lemmas to Product_plus.thy
huffman
parents: 30018
diff changeset
   113
by (cases "finite A", induct set: finite, simp_all)
39b2516a1970 move setsum lemmas to Product_plus.thy
huffman
parents: 30018
diff changeset
   114
39b2516a1970 move setsum lemmas to Product_plus.thy
huffman
parents: 30018
diff changeset
   115
lemma snd_setsum: "snd (\<Sum>x\<in>A. f x) = (\<Sum>x\<in>A. snd (f x))"
39b2516a1970 move setsum lemmas to Product_plus.thy
huffman
parents: 30018
diff changeset
   116
by (cases "finite A", induct set: finite, simp_all)
39b2516a1970 move setsum lemmas to Product_plus.thy
huffman
parents: 30018
diff changeset
   117
37664
2946b8f057df Instantiate product type as euclidean space.
hoelzl
parents: 36627
diff changeset
   118
lemma setsum_prod: "(\<Sum>x\<in>A. (f x, g x)) = (\<Sum>x\<in>A. f x, \<Sum>x\<in>A. g x)"
2946b8f057df Instantiate product type as euclidean space.
hoelzl
parents: 36627
diff changeset
   119
by (cases "finite A", induct set: finite) (simp_all add: zero_prod_def)
2946b8f057df Instantiate product type as euclidean space.
hoelzl
parents: 36627
diff changeset
   120
30018
690c65b8ad1a add new theory Product_plus.thy to Library
huffman
parents:
diff changeset
   121
end