src/HOL/Library/Boolean_Algebra.thy
 author haftmann Wed Apr 22 19:09:21 2009 +0200 (2009-04-22) changeset 30960 fec1a04b7220 parent 30663 0b6aff7451b2 child 34973 ae634fad947e permissions -rw-r--r--
power operation defined generic
 haftmann@29629 ` 1` ```(* Title: HOL/Library/Boolean_Algebra.thy ``` haftmann@29629 ` 2` ``` Author: Brian Huffman ``` kleing@24332 ` 3` ```*) ``` kleing@24332 ` 4` kleing@24332 ` 5` ```header {* Boolean Algebras *} ``` kleing@24332 ` 6` kleing@24332 ` 7` ```theory Boolean_Algebra ``` haftmann@30663 ` 8` ```imports Main ``` kleing@24332 ` 9` ```begin ``` kleing@24332 ` 10` kleing@24332 ` 11` ```locale boolean = ``` huffman@24357 ` 12` ``` fixes conj :: "'a \ 'a \ 'a" (infixr "\" 70) ``` huffman@24357 ` 13` ``` fixes disj :: "'a \ 'a \ 'a" (infixr "\" 65) ``` huffman@24357 ` 14` ``` fixes compl :: "'a \ 'a" ("\ _" [81] 80) ``` kleing@24332 ` 15` ``` fixes zero :: "'a" ("\") ``` kleing@24332 ` 16` ``` fixes one :: "'a" ("\") ``` kleing@24332 ` 17` ``` assumes conj_assoc: "(x \ y) \ z = x \ (y \ z)" ``` kleing@24332 ` 18` ``` assumes disj_assoc: "(x \ y) \ z = x \ (y \ z)" ``` kleing@24332 ` 19` ``` assumes conj_commute: "x \ y = y \ x" ``` kleing@24332 ` 20` ``` assumes disj_commute: "x \ y = y \ x" ``` kleing@24332 ` 21` ``` assumes conj_disj_distrib: "x \ (y \ z) = (x \ y) \ (x \ z)" ``` kleing@24332 ` 22` ``` assumes disj_conj_distrib: "x \ (y \ z) = (x \ y) \ (x \ z)" ``` huffman@24357 ` 23` ``` assumes conj_one_right [simp]: "x \ \ = x" ``` huffman@24357 ` 24` ``` assumes disj_zero_right [simp]: "x \ \ = x" ``` huffman@24357 ` 25` ``` assumes conj_cancel_right [simp]: "x \ \ x = \" ``` huffman@24357 ` 26` ``` assumes disj_cancel_right [simp]: "x \ \ x = \" ``` kleing@24332 ` 27` ```begin ``` kleing@24332 ` 28` kleing@24332 ` 29` ```lemmas disj_ac = ``` kleing@24332 ` 30` ``` disj_assoc disj_commute ``` ballarin@25283 ` 31` ``` mk_left_commute [where 'a = 'a, of "disj", OF disj_assoc disj_commute] ``` kleing@24332 ` 32` kleing@24332 ` 33` ```lemmas conj_ac = ``` kleing@24332 ` 34` ``` conj_assoc conj_commute ``` ballarin@25283 ` 35` ``` mk_left_commute [where 'a = 'a, of "conj", OF conj_assoc conj_commute] ``` kleing@24332 ` 36` kleing@24332 ` 37` ```lemma dual: "boolean disj conj compl one zero" ``` kleing@24332 ` 38` ```apply (rule boolean.intro) ``` kleing@24332 ` 39` ```apply (rule disj_assoc) ``` kleing@24332 ` 40` ```apply (rule conj_assoc) ``` kleing@24332 ` 41` ```apply (rule disj_commute) ``` kleing@24332 ` 42` ```apply (rule conj_commute) ``` kleing@24332 ` 43` ```apply (rule disj_conj_distrib) ``` kleing@24332 ` 44` ```apply (rule conj_disj_distrib) ``` kleing@24332 ` 45` ```apply (rule disj_zero_right) ``` kleing@24332 ` 46` ```apply (rule conj_one_right) ``` kleing@24332 ` 47` ```apply (rule disj_cancel_right) ``` kleing@24332 ` 48` ```apply (rule conj_cancel_right) ``` kleing@24332 ` 49` ```done ``` kleing@24332 ` 50` huffman@24357 ` 51` ```subsection {* Complement *} ``` kleing@24332 ` 52` kleing@24332 ` 53` ```lemma complement_unique: ``` kleing@24332 ` 54` ``` assumes 1: "a \ x = \" ``` kleing@24332 ` 55` ``` assumes 2: "a \ x = \" ``` kleing@24332 ` 56` ``` assumes 3: "a \ y = \" ``` kleing@24332 ` 57` ``` assumes 4: "a \ y = \" ``` kleing@24332 ` 58` ``` shows "x = y" ``` kleing@24332 ` 59` ```proof - ``` kleing@24332 ` 60` ``` have "(a \ x) \ (x \ y) = (a \ y) \ (x \ y)" using 1 3 by simp ``` kleing@24332 ` 61` ``` hence "(x \ a) \ (x \ y) = (y \ a) \ (y \ x)" using conj_commute by simp ``` kleing@24332 ` 62` ``` hence "x \ (a \ y) = y \ (a \ x)" using conj_disj_distrib by simp ``` kleing@24332 ` 63` ``` hence "x \ \ = y \ \" using 2 4 by simp ``` kleing@24332 ` 64` ``` thus "x = y" using conj_one_right by simp ``` kleing@24332 ` 65` ```qed ``` kleing@24332 ` 66` huffman@24357 ` 67` ```lemma compl_unique: "\x \ y = \; x \ y = \\ \ \ x = y" ``` kleing@24332 ` 68` ```by (rule complement_unique [OF conj_cancel_right disj_cancel_right]) ``` kleing@24332 ` 69` kleing@24332 ` 70` ```lemma double_compl [simp]: "\ (\ x) = x" ``` kleing@24332 ` 71` ```proof (rule compl_unique) ``` huffman@24357 ` 72` ``` from conj_cancel_right show "\ x \ x = \" by (simp only: conj_commute) ``` huffman@24357 ` 73` ``` from disj_cancel_right show "\ x \ x = \" by (simp only: disj_commute) ``` kleing@24332 ` 74` ```qed ``` kleing@24332 ` 75` kleing@24332 ` 76` ```lemma compl_eq_compl_iff [simp]: "(\ x = \ y) = (x = y)" ``` kleing@24332 ` 77` ```by (rule inj_eq [OF inj_on_inverseI], rule double_compl) ``` kleing@24332 ` 78` huffman@24357 ` 79` ```subsection {* Conjunction *} ``` kleing@24332 ` 80` huffman@24393 ` 81` ```lemma conj_absorb [simp]: "x \ x = x" ``` kleing@24332 ` 82` ```proof - ``` kleing@24332 ` 83` ``` have "x \ x = (x \ x) \ \" using disj_zero_right by simp ``` kleing@24332 ` 84` ``` also have "... = (x \ x) \ (x \ \ x)" using conj_cancel_right by simp ``` huffman@24357 ` 85` ``` also have "... = x \ (x \ \ x)" using conj_disj_distrib by (simp only:) ``` kleing@24332 ` 86` ``` also have "... = x \ \" using disj_cancel_right by simp ``` kleing@24332 ` 87` ``` also have "... = x" using conj_one_right by simp ``` kleing@24332 ` 88` ``` finally show ?thesis . ``` kleing@24332 ` 89` ```qed ``` kleing@24332 ` 90` kleing@24332 ` 91` ```lemma conj_zero_right [simp]: "x \ \ = \" ``` kleing@24332 ` 92` ```proof - ``` kleing@24332 ` 93` ``` have "x \ \ = x \ (x \ \ x)" using conj_cancel_right by simp ``` huffman@24393 ` 94` ``` also have "... = (x \ x) \ \ x" using conj_assoc by (simp only:) ``` kleing@24332 ` 95` ``` also have "... = x \ \ x" using conj_absorb by simp ``` kleing@24332 ` 96` ``` also have "... = \" using conj_cancel_right by simp ``` kleing@24332 ` 97` ``` finally show ?thesis . ``` kleing@24332 ` 98` ```qed ``` kleing@24332 ` 99` kleing@24332 ` 100` ```lemma compl_one [simp]: "\ \ = \" ``` kleing@24332 ` 101` ```by (rule compl_unique [OF conj_zero_right disj_zero_right]) ``` kleing@24332 ` 102` kleing@24332 ` 103` ```lemma conj_zero_left [simp]: "\ \ x = \" ``` kleing@24332 ` 104` ```by (subst conj_commute) (rule conj_zero_right) ``` kleing@24332 ` 105` kleing@24332 ` 106` ```lemma conj_one_left [simp]: "\ \ x = x" ``` kleing@24332 ` 107` ```by (subst conj_commute) (rule conj_one_right) ``` kleing@24332 ` 108` kleing@24332 ` 109` ```lemma conj_cancel_left [simp]: "\ x \ x = \" ``` kleing@24332 ` 110` ```by (subst conj_commute) (rule conj_cancel_right) ``` kleing@24332 ` 111` kleing@24332 ` 112` ```lemma conj_left_absorb [simp]: "x \ (x \ y) = x \ y" ``` huffman@24357 ` 113` ```by (simp only: conj_assoc [symmetric] conj_absorb) ``` kleing@24332 ` 114` kleing@24332 ` 115` ```lemma conj_disj_distrib2: ``` kleing@24332 ` 116` ``` "(y \ z) \ x = (y \ x) \ (z \ x)" ``` huffman@24357 ` 117` ```by (simp only: conj_commute conj_disj_distrib) ``` kleing@24332 ` 118` kleing@24332 ` 119` ```lemmas conj_disj_distribs = ``` kleing@24332 ` 120` ``` conj_disj_distrib conj_disj_distrib2 ``` kleing@24332 ` 121` huffman@24357 ` 122` ```subsection {* Disjunction *} ``` kleing@24332 ` 123` kleing@24332 ` 124` ```lemma disj_absorb [simp]: "x \ x = x" ``` kleing@24332 ` 125` ```by (rule boolean.conj_absorb [OF dual]) ``` kleing@24332 ` 126` kleing@24332 ` 127` ```lemma disj_one_right [simp]: "x \ \ = \" ``` kleing@24332 ` 128` ```by (rule boolean.conj_zero_right [OF dual]) ``` kleing@24332 ` 129` kleing@24332 ` 130` ```lemma compl_zero [simp]: "\ \ = \" ``` kleing@24332 ` 131` ```by (rule boolean.compl_one [OF dual]) ``` kleing@24332 ` 132` kleing@24332 ` 133` ```lemma disj_zero_left [simp]: "\ \ x = x" ``` kleing@24332 ` 134` ```by (rule boolean.conj_one_left [OF dual]) ``` kleing@24332 ` 135` kleing@24332 ` 136` ```lemma disj_one_left [simp]: "\ \ x = \" ``` kleing@24332 ` 137` ```by (rule boolean.conj_zero_left [OF dual]) ``` kleing@24332 ` 138` kleing@24332 ` 139` ```lemma disj_cancel_left [simp]: "\ x \ x = \" ``` kleing@24332 ` 140` ```by (rule boolean.conj_cancel_left [OF dual]) ``` kleing@24332 ` 141` kleing@24332 ` 142` ```lemma disj_left_absorb [simp]: "x \ (x \ y) = x \ y" ``` kleing@24332 ` 143` ```by (rule boolean.conj_left_absorb [OF dual]) ``` kleing@24332 ` 144` kleing@24332 ` 145` ```lemma disj_conj_distrib2: ``` kleing@24332 ` 146` ``` "(y \ z) \ x = (y \ x) \ (z \ x)" ``` kleing@24332 ` 147` ```by (rule boolean.conj_disj_distrib2 [OF dual]) ``` kleing@24332 ` 148` kleing@24332 ` 149` ```lemmas disj_conj_distribs = ``` kleing@24332 ` 150` ``` disj_conj_distrib disj_conj_distrib2 ``` kleing@24332 ` 151` huffman@24357 ` 152` ```subsection {* De Morgan's Laws *} ``` kleing@24332 ` 153` kleing@24332 ` 154` ```lemma de_Morgan_conj [simp]: "\ (x \ y) = \ x \ \ y" ``` kleing@24332 ` 155` ```proof (rule compl_unique) ``` kleing@24332 ` 156` ``` have "(x \ y) \ (\ x \ \ y) = ((x \ y) \ \ x) \ ((x \ y) \ \ y)" ``` kleing@24332 ` 157` ``` by (rule conj_disj_distrib) ``` kleing@24332 ` 158` ``` also have "... = (y \ (x \ \ x)) \ (x \ (y \ \ y))" ``` huffman@24357 ` 159` ``` by (simp only: conj_ac) ``` kleing@24332 ` 160` ``` finally show "(x \ y) \ (\ x \ \ y) = \" ``` huffman@24357 ` 161` ``` by (simp only: conj_cancel_right conj_zero_right disj_zero_right) ``` kleing@24332 ` 162` ```next ``` kleing@24332 ` 163` ``` have "(x \ y) \ (\ x \ \ y) = (x \ (\ x \ \ y)) \ (y \ (\ x \ \ y))" ``` kleing@24332 ` 164` ``` by (rule disj_conj_distrib2) ``` kleing@24332 ` 165` ``` also have "... = (\ y \ (x \ \ x)) \ (\ x \ (y \ \ y))" ``` huffman@24357 ` 166` ``` by (simp only: disj_ac) ``` kleing@24332 ` 167` ``` finally show "(x \ y) \ (\ x \ \ y) = \" ``` huffman@24357 ` 168` ``` by (simp only: disj_cancel_right disj_one_right conj_one_right) ``` kleing@24332 ` 169` ```qed ``` kleing@24332 ` 170` kleing@24332 ` 171` ```lemma de_Morgan_disj [simp]: "\ (x \ y) = \ x \ \ y" ``` kleing@24332 ` 172` ```by (rule boolean.de_Morgan_conj [OF dual]) ``` kleing@24332 ` 173` kleing@24332 ` 174` ```end ``` kleing@24332 ` 175` huffman@24357 ` 176` ```subsection {* Symmetric Difference *} ``` kleing@24332 ` 177` kleing@24332 ` 178` ```locale boolean_xor = boolean + ``` kleing@24332 ` 179` ``` fixes xor :: "'a => 'a => 'a" (infixr "\" 65) ``` kleing@24332 ` 180` ``` assumes xor_def: "x \ y = (x \ \ y) \ (\ x \ y)" ``` kleing@24332 ` 181` ```begin ``` kleing@24332 ` 182` kleing@24332 ` 183` ```lemma xor_def2: ``` kleing@24332 ` 184` ``` "x \ y = (x \ y) \ (\ x \ \ y)" ``` huffman@24357 ` 185` ```by (simp only: xor_def conj_disj_distribs ``` huffman@24357 ` 186` ``` disj_ac conj_ac conj_cancel_right disj_zero_left) ``` kleing@24332 ` 187` kleing@24332 ` 188` ```lemma xor_commute: "x \ y = y \ x" ``` huffman@24357 ` 189` ```by (simp only: xor_def conj_commute disj_commute) ``` kleing@24332 ` 190` kleing@24332 ` 191` ```lemma xor_assoc: "(x \ y) \ z = x \ (y \ z)" ``` kleing@24332 ` 192` ```proof - ``` kleing@24332 ` 193` ``` let ?t = "(x \ y \ z) \ (x \ \ y \ \ z) \ ``` kleing@24332 ` 194` ``` (\ x \ y \ \ z) \ (\ x \ \ y \ z)" ``` kleing@24332 ` 195` ``` have "?t \ (z \ x \ \ x) \ (z \ y \ \ y) = ``` kleing@24332 ` 196` ``` ?t \ (x \ y \ \ y) \ (x \ z \ \ z)" ``` huffman@24357 ` 197` ``` by (simp only: conj_cancel_right conj_zero_right) ``` kleing@24332 ` 198` ``` thus "(x \ y) \ z = x \ (y \ z)" ``` huffman@24357 ` 199` ``` apply (simp only: xor_def de_Morgan_disj de_Morgan_conj double_compl) ``` huffman@24357 ` 200` ``` apply (simp only: conj_disj_distribs conj_ac disj_ac) ``` kleing@24332 ` 201` ``` done ``` kleing@24332 ` 202` ```qed ``` kleing@24332 ` 203` kleing@24332 ` 204` ```lemmas xor_ac = ``` kleing@24332 ` 205` ``` xor_assoc xor_commute ``` ballarin@25283 ` 206` ``` mk_left_commute [where 'a = 'a, of "xor", OF xor_assoc xor_commute] ``` kleing@24332 ` 207` kleing@24332 ` 208` ```lemma xor_zero_right [simp]: "x \ \ = x" ``` huffman@24357 ` 209` ```by (simp only: xor_def compl_zero conj_one_right conj_zero_right disj_zero_right) ``` kleing@24332 ` 210` kleing@24332 ` 211` ```lemma xor_zero_left [simp]: "\ \ x = x" ``` kleing@24332 ` 212` ```by (subst xor_commute) (rule xor_zero_right) ``` kleing@24332 ` 213` kleing@24332 ` 214` ```lemma xor_one_right [simp]: "x \ \ = \ x" ``` huffman@24357 ` 215` ```by (simp only: xor_def compl_one conj_zero_right conj_one_right disj_zero_left) ``` kleing@24332 ` 216` kleing@24332 ` 217` ```lemma xor_one_left [simp]: "\ \ x = \ x" ``` kleing@24332 ` 218` ```by (subst xor_commute) (rule xor_one_right) ``` kleing@24332 ` 219` kleing@24332 ` 220` ```lemma xor_self [simp]: "x \ x = \" ``` huffman@24357 ` 221` ```by (simp only: xor_def conj_cancel_right conj_cancel_left disj_zero_right) ``` kleing@24332 ` 222` kleing@24332 ` 223` ```lemma xor_left_self [simp]: "x \ (x \ y) = y" ``` huffman@24357 ` 224` ```by (simp only: xor_assoc [symmetric] xor_self xor_zero_left) ``` kleing@24332 ` 225` huffman@29996 ` 226` ```lemma xor_compl_left [simp]: "\ x \ y = \ (x \ y)" ``` huffman@24357 ` 227` ```apply (simp only: xor_def de_Morgan_disj de_Morgan_conj double_compl) ``` huffman@24357 ` 228` ```apply (simp only: conj_disj_distribs) ``` huffman@24357 ` 229` ```apply (simp only: conj_cancel_right conj_cancel_left) ``` huffman@24357 ` 230` ```apply (simp only: disj_zero_left disj_zero_right) ``` huffman@24357 ` 231` ```apply (simp only: disj_ac conj_ac) ``` kleing@24332 ` 232` ```done ``` kleing@24332 ` 233` huffman@29996 ` 234` ```lemma xor_compl_right [simp]: "x \ \ y = \ (x \ y)" ``` huffman@24357 ` 235` ```apply (simp only: xor_def de_Morgan_disj de_Morgan_conj double_compl) ``` huffman@24357 ` 236` ```apply (simp only: conj_disj_distribs) ``` huffman@24357 ` 237` ```apply (simp only: conj_cancel_right conj_cancel_left) ``` huffman@24357 ` 238` ```apply (simp only: disj_zero_left disj_zero_right) ``` huffman@24357 ` 239` ```apply (simp only: disj_ac conj_ac) ``` kleing@24332 ` 240` ```done ``` kleing@24332 ` 241` huffman@29996 ` 242` ```lemma xor_cancel_right: "x \ \ x = \" ``` huffman@24357 ` 243` ```by (simp only: xor_compl_right xor_self compl_zero) ``` kleing@24332 ` 244` huffman@29996 ` 245` ```lemma xor_cancel_left: "\ x \ x = \" ``` huffman@29996 ` 246` ```by (simp only: xor_compl_left xor_self compl_zero) ``` kleing@24332 ` 247` kleing@24332 ` 248` ```lemma conj_xor_distrib: "x \ (y \ z) = (x \ y) \ (x \ z)" ``` kleing@24332 ` 249` ```proof - ``` kleing@24332 ` 250` ``` have "(x \ y \ \ z) \ (x \ \ y \ z) = ``` kleing@24332 ` 251` ``` (y \ x \ \ x) \ (z \ x \ \ x) \ (x \ y \ \ z) \ (x \ \ y \ z)" ``` huffman@24357 ` 252` ``` by (simp only: conj_cancel_right conj_zero_right disj_zero_left) ``` kleing@24332 ` 253` ``` thus "x \ (y \ z) = (x \ y) \ (x \ z)" ``` huffman@24357 ` 254` ``` by (simp (no_asm_use) only: ``` kleing@24332 ` 255` ``` xor_def de_Morgan_disj de_Morgan_conj double_compl ``` kleing@24332 ` 256` ``` conj_disj_distribs conj_ac disj_ac) ``` kleing@24332 ` 257` ```qed ``` kleing@24332 ` 258` kleing@24332 ` 259` ```lemma conj_xor_distrib2: ``` kleing@24332 ` 260` ``` "(y \ z) \ x = (y \ x) \ (z \ x)" ``` kleing@24332 ` 261` ```proof - ``` kleing@24332 ` 262` ``` have "x \ (y \ z) = (x \ y) \ (x \ z)" ``` kleing@24332 ` 263` ``` by (rule conj_xor_distrib) ``` kleing@24332 ` 264` ``` thus "(y \ z) \ x = (y \ x) \ (z \ x)" ``` huffman@24357 ` 265` ``` by (simp only: conj_commute) ``` kleing@24332 ` 266` ```qed ``` kleing@24332 ` 267` kleing@24332 ` 268` ```lemmas conj_xor_distribs = ``` kleing@24332 ` 269` ``` conj_xor_distrib conj_xor_distrib2 ``` kleing@24332 ` 270` kleing@24332 ` 271` ```end ``` kleing@24332 ` 272` kleing@24332 ` 273` ```end ```