src/HOL/Algebras.thy
author haftmann
Thu, 28 Jan 2010 11:48:49 +0100
changeset 34974 18b41bba42b5
child 35026 02850d0b95ac
permissions -rw-r--r--
new theory Algebras.thy for generic algebraic structures
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34974
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
     1
(*  Title:      HOL/Algebras.thy
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
     2
    Author:     Florian Haftmann, TU Muenchen
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
     3
*)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
     4
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
     5
header {* Generic algebraic structures and operations *}
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
     6
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
     7
theory Algebras
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
     8
imports HOL
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
     9
begin
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    10
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    11
subsection {* Generic algebraic structures *}
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    12
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    13
locale semigroup =
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    14
  fixes f :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "*" 70)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    15
  assumes assoc: "a * b * c = a * (b * c)"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    16
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    17
locale abel_semigroup = semigroup +
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    18
  assumes commute: "a * b = b * a"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    19
begin
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    20
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    21
lemma left_commute:
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    22
  "b * (a * c) = a * (b * c)"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    23
proof -
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    24
  have "(b * a) * c = (a * b) * c"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    25
    by (simp only: commute)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    26
  then show ?thesis
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    27
    by (simp only: assoc)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    28
qed
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    29
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    30
end
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    31
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    32
locale semilattice = abel_semigroup +
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    33
  assumes idem [simp]: "a * a = a"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    34
begin
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    35
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    36
lemma left_idem [simp]:
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    37
  "a * (a * b) = a * b"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    38
  by (simp add: assoc [symmetric])
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    39
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    40
end
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    41
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    42
locale lattice = inf!: abel_semigroup inf + sup!: abel_semigroup sup
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    43
  for inf (infixl "\<sqinter>" 70) and sup (infixl "\<squnion>" 70) +
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    44
  assumes sup_inf_absorb: "a \<squnion> (a \<sqinter> b) = a"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    45
  and inf_sup_absorb: "a \<sqinter> (a \<squnion> b) = a"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    46
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    47
sublocale lattice < inf!: semilattice inf
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    48
proof
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    49
  fix a
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    50
  have "a \<sqinter> (a \<squnion> (a \<sqinter> a)) = a" by (fact inf_sup_absorb)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    51
  then show "a \<sqinter> a = a" by (simp add: sup_inf_absorb)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    52
qed
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    53
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    54
sublocale lattice < sup!: semilattice sup
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    55
proof
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    56
  fix a
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    57
  have "a \<squnion> (a \<sqinter> (a \<squnion> a)) = a" by (fact sup_inf_absorb)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    58
  then show "a \<squnion> a = a" by (simp add: inf_sup_absorb)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    59
qed
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    60
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    61
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    62
subsection {* Generic algebraic operations *}
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    63
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    64
class zero = 
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    65
  fixes zero :: 'a  ("0")
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    66
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    67
class one =
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    68
  fixes one  :: 'a  ("1")
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    69
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    70
lemma Let_0 [simp]: "Let 0 f = f 0"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    71
  unfolding Let_def ..
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    72
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    73
lemma Let_1 [simp]: "Let 1 f = f 1"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    74
  unfolding Let_def ..
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    75
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    76
setup {*
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    77
  Reorient_Proc.add
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    78
    (fn Const(@{const_name Algebras.zero}, _) => true
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    79
      | Const(@{const_name Algebras.one}, _) => true
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    80
      | _ => false)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    81
*}
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    82
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    83
simproc_setup reorient_zero ("0 = x") = Reorient_Proc.proc
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    84
simproc_setup reorient_one ("1 = x") = Reorient_Proc.proc
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    85
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    86
typed_print_translation {*
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    87
let
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    88
  fun tr' c = (c, fn show_sorts => fn T => fn ts =>
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    89
    if (not o null) ts orelse T = dummyT
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    90
      orelse not (! show_types) andalso can Term.dest_Type T
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    91
    then raise Match
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    92
    else Syntax.const Syntax.constrainC $ Syntax.const c $ Syntax.term_of_typ show_sorts T);
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    93
in map tr' [@{const_syntax Algebras.one}, @{const_syntax Algebras.zero}] end;
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    94
*} -- {* show types that are presumably too general *}
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    95
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    96
hide (open) const zero one
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    97
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    98
class plus =
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
    99
  fixes plus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "+" 65)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   100
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   101
class minus =
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   102
  fixes minus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "-" 65)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   103
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   104
class uminus =
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   105
  fixes uminus :: "'a \<Rightarrow> 'a"  ("- _" [81] 80)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   106
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   107
class times =
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   108
  fixes times :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "*" 70)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   109
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   110
class inverse =
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   111
  fixes inverse :: "'a \<Rightarrow> 'a"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   112
    and divide :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixl "'/" 70)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   113
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   114
class abs =
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   115
  fixes abs :: "'a \<Rightarrow> 'a"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   116
begin
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   117
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   118
notation (xsymbols)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   119
  abs  ("\<bar>_\<bar>")
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   120
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   121
notation (HTML output)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   122
  abs  ("\<bar>_\<bar>")
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   123
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   124
end
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   125
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   126
class sgn =
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   127
  fixes sgn :: "'a \<Rightarrow> 'a"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   128
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   129
class ord =
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   130
  fixes less_eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   131
    and less :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   132
begin
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   133
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   134
notation
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   135
  less_eq  ("op <=") and
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   136
  less_eq  ("(_/ <= _)" [51, 51] 50) and
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   137
  less  ("op <") and
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   138
  less  ("(_/ < _)"  [51, 51] 50)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   139
  
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   140
notation (xsymbols)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   141
  less_eq  ("op \<le>") and
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   142
  less_eq  ("(_/ \<le> _)"  [51, 51] 50)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   143
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   144
notation (HTML output)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   145
  less_eq  ("op \<le>") and
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   146
  less_eq  ("(_/ \<le> _)"  [51, 51] 50)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   147
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   148
abbreviation (input)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   149
  greater_eq  (infix ">=" 50) where
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   150
  "x >= y \<equiv> y <= x"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   151
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   152
notation (input)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   153
  greater_eq  (infix "\<ge>" 50)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   154
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   155
abbreviation (input)
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   156
  greater  (infix ">" 50) where
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   157
  "x > y \<equiv> y < x"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   158
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   159
end
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   160
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   161
syntax
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   162
  "_index1"  :: index    ("\<^sub>1")
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   163
translations
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   164
  (index) "\<^sub>1" => (index) "\<^bsub>\<struct>\<^esub>"
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   165
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents:
diff changeset
   166
end