src/HOL/ex/Locales.thy
author wenzelm
Tue, 01 Jun 2004 12:33:50 +0200
changeset 14854 61bdf2ae4dc5
parent 14254 342634f38451
child 14981 e73f8140af78
permissions -rw-r--r--
removed obsolete sort 'logic';
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/ex/Locales.thy
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
12574
wenzelm
parents: 12507
diff changeset
     3
    Author:     Markus Wenzel, LMU München
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
     5
*)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
     6
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
     7
header {* Using locales in Isabelle/Isar *}
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
     8
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
     9
theory Locales = Main:
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
    10
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    11
text_raw {*
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    12
  \newcommand{\isasyminv}{\isasyminverse}
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    13
  \newcommand{\isasymIN}{\isatext{\isakeyword{in}}}
12965
c8a97eb1e3c7 renamed 'uses' to 'includes';
wenzelm
parents: 12955
diff changeset
    14
  \newcommand{\isasymINCLUDES}{\isatext{\isakeyword{includes}}}
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    15
*}
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    16
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    17
subsection {* Overview *}
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    18
12091
08b4da78d1ad added structures;
wenzelm
parents: 12075
diff changeset
    19
text {*
12105
wenzelm
parents: 12099
diff changeset
    20
  Locales provide a mechanism for encapsulating local contexts.  The
12574
wenzelm
parents: 12507
diff changeset
    21
  original version due to Florian Kammüller \cite{Kamm-et-al:1999}
13538
wenzelm
parents: 13457
diff changeset
    22
  refers directly to Isabelle's meta-logic \cite{Paulson:1989}, which
wenzelm
parents: 13457
diff changeset
    23
  is minimal higher-order logic with connectives @{text "\<And>"}
wenzelm
parents: 13457
diff changeset
    24
  (universal quantification), @{text "\<Longrightarrow>"} (implication), and @{text
wenzelm
parents: 13457
diff changeset
    25
  "\<equiv>"} (equality).
wenzelm
parents: 13457
diff changeset
    26
wenzelm
parents: 13457
diff changeset
    27
  From this perspective, a locale is essentially a meta-level
wenzelm
parents: 13457
diff changeset
    28
  predicate, together with some infrastructure to manage the
wenzelm
parents: 13457
diff changeset
    29
  abstracted parameters (@{text "\<And>"}), assumptions (@{text "\<Longrightarrow>"}), and
wenzelm
parents: 13457
diff changeset
    30
  definitions for (@{text "\<equiv>"}) in a reasonable way during the proof
wenzelm
parents: 13457
diff changeset
    31
  process.  This simple predicate view also provides a solid
wenzelm
parents: 13457
diff changeset
    32
  semantical basis for our specification concepts to be developed
wenzelm
parents: 13457
diff changeset
    33
  later.
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    34
13538
wenzelm
parents: 13457
diff changeset
    35
  \medskip The present version of locales for Isabelle/Isar builds on
wenzelm
parents: 13457
diff changeset
    36
  top of the rich infrastructure of proof contexts
wenzelm
parents: 13457
diff changeset
    37
  \cite{Wenzel:1999,Wenzel:2001:isar-ref,Wenzel:2001:Thesis}, which in
wenzelm
parents: 13457
diff changeset
    38
  turn is based on the same meta-logic.  Thus we achieve a tight
wenzelm
parents: 13457
diff changeset
    39
  integration with Isar proof texts, and a slightly more abstract view
wenzelm
parents: 13457
diff changeset
    40
  of the underlying logical concepts.  An Isar proof context
wenzelm
parents: 13457
diff changeset
    41
  encapsulates certain language elements that correspond to @{text
wenzelm
parents: 13457
diff changeset
    42
  "\<And>/\<Longrightarrow>/\<equiv>"} at the level of structure proof texts.  Moreover, there are
wenzelm
parents: 13457
diff changeset
    43
  extra-logical concepts like term abbreviations or local theorem
wenzelm
parents: 13457
diff changeset
    44
  attributes (declarations of simplification rules etc.) that are
wenzelm
parents: 13457
diff changeset
    45
  useful in applications (e.g.\ consider standard simplification rules
wenzelm
parents: 13457
diff changeset
    46
  declared in a group context).
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    47
13538
wenzelm
parents: 13457
diff changeset
    48
  Locales also support concrete syntax, i.e.\ a localized version of
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    49
  the existing concept of mixfix annotations of Isabelle
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    50
  \cite{Paulson:1994:Isabelle}.  Furthermore, there is a separate
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    51
  concept of ``implicit structures'' that admits to refer to
13538
wenzelm
parents: 13457
diff changeset
    52
  particular locale parameters in a casual manner (basically a
wenzelm
parents: 13457
diff changeset
    53
  simplified version of the idea of ``anti-quotations'', or
wenzelm
parents: 13457
diff changeset
    54
  generalized de-Bruijn indexes as demonstrated elsewhere
wenzelm
parents: 13457
diff changeset
    55
  \cite[\S13--14]{Wenzel:2001:Isar-examples}).
12105
wenzelm
parents: 12099
diff changeset
    56
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    57
  Implicit structures work particular well together with extensible
13538
wenzelm
parents: 13457
diff changeset
    58
  records in HOL \cite{Naraschewski-Wenzel:1998} (without the
wenzelm
parents: 13457
diff changeset
    59
  ``object-oriented'' features discussed there as well).  Thus we
wenzelm
parents: 13457
diff changeset
    60
  achieve a specification technique where record type schemes
wenzelm
parents: 13457
diff changeset
    61
  represent polymorphic signatures of mathematical structures, and
wenzelm
parents: 13457
diff changeset
    62
  actual locales describe the corresponding logical properties.
wenzelm
parents: 13457
diff changeset
    63
  Semantically speaking, such abstract mathematical structures are
wenzelm
parents: 13457
diff changeset
    64
  just predicates over record types.  Due to type inference of
wenzelm
parents: 13457
diff changeset
    65
  simply-typed records (which subsumes structural subtyping) we arrive
wenzelm
parents: 13457
diff changeset
    66
  at succinct specification texts --- ``signature morphisms''
wenzelm
parents: 13457
diff changeset
    67
  degenerate to implicit type-instantiations.  Additional eye-candy is
wenzelm
parents: 13457
diff changeset
    68
  provided by the separate concept of ``indexed concrete syntax'' used
wenzelm
parents: 13457
diff changeset
    69
  for record selectors, so we get close to informal mathematical
wenzelm
parents: 13457
diff changeset
    70
  notation.
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    71
13538
wenzelm
parents: 13457
diff changeset
    72
  \medskip Operations for building up locale contexts from existing
wenzelm
parents: 13457
diff changeset
    73
  ones include \emph{merge} (disjoint union) and \emph{rename} (of
wenzelm
parents: 13457
diff changeset
    74
  term parameters only, types are inferred automatically).  Here we
wenzelm
parents: 13457
diff changeset
    75
  draw from existing traditions of algebraic specification languages.
wenzelm
parents: 13457
diff changeset
    76
  A structured specification corresponds to a directed acyclic graph
wenzelm
parents: 13457
diff changeset
    77
  of potentially renamed nodes (due to distributivity renames may
wenzelm
parents: 13457
diff changeset
    78
  pushed inside of merges).  The result is a ``flattened'' list of
wenzelm
parents: 13457
diff changeset
    79
  primitive context elements in canonical order (corresponding to
wenzelm
parents: 13457
diff changeset
    80
  left-to-right reading of merges, while suppressing duplicates).
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    81
13538
wenzelm
parents: 13457
diff changeset
    82
  \medskip The present version of Isabelle/Isar locales still lacks
wenzelm
parents: 13457
diff changeset
    83
  some important specification concepts.
wenzelm
parents: 13457
diff changeset
    84
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    85
  \begin{itemize}
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
    86
13538
wenzelm
parents: 13457
diff changeset
    87
  \item Separate language elements for \emph{instantiation} of
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    88
  locales.
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    89
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    90
  Currently users may simulate this to some extend by having primitive
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    91
  Isabelle/Isar operations (@{text of} for substitution and @{text OF}
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    92
  for composition, \cite{Wenzel:2001:isar-ref}) act on the
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    93
  automatically exported results stemming from different contexts.
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    94
13538
wenzelm
parents: 13457
diff changeset
    95
  \item Interpretation of locales (think of ``views'', ``functors''
wenzelm
parents: 13457
diff changeset
    96
  etc.).
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    97
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    98
  In principle one could directly work with functions over structures
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
    99
  (extensible records), and predicates being derived from locale
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   100
  definitions.
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   101
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   102
  \end{itemize}
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   103
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   104
  \medskip Subsequently, we demonstrate some readily available
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   105
  concepts of Isabelle/Isar locales by some simple examples of
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   106
  abstract algebraic reasoning.
12091
08b4da78d1ad added structures;
wenzelm
parents: 12075
diff changeset
   107
*}
08b4da78d1ad added structures;
wenzelm
parents: 12075
diff changeset
   108
13538
wenzelm
parents: 13457
diff changeset
   109
12091
08b4da78d1ad added structures;
wenzelm
parents: 12075
diff changeset
   110
subsection {* Local contexts as mathematical structures *}
08b4da78d1ad added structures;
wenzelm
parents: 12075
diff changeset
   111
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   112
text {*
13538
wenzelm
parents: 13457
diff changeset
   113
  The following definitions of @{text group_context} and @{text
wenzelm
parents: 13457
diff changeset
   114
  abelian_group_context} merely encapsulate local parameters (with
wenzelm
parents: 13457
diff changeset
   115
  private syntax) and assumptions; local definitions of derived
wenzelm
parents: 13457
diff changeset
   116
  concepts could be given, too, but are unused below.
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   117
*}
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   118
12574
wenzelm
parents: 12507
diff changeset
   119
locale group_context =
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   120
  fixes prod :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"    (infixl "\<cdot>" 70)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   121
    and inv :: "'a \<Rightarrow> 'a"    ("(_\<inv>)" [1000] 999)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   122
    and one :: 'a    ("\<one>")
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   123
  assumes assoc: "(x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)"
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   124
    and left_inv: "x\<inv> \<cdot> x = \<one>"
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   125
    and left_one: "\<one> \<cdot> x = x"
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   126
12574
wenzelm
parents: 12507
diff changeset
   127
locale abelian_group_context = group_context +
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   128
  assumes commute: "x \<cdot> y = y \<cdot> x"
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   129
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   130
text {*
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   131
  \medskip We may now prove theorems within a local context, just by
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   132
  including a directive ``@{text "(\<IN> name)"}'' in the goal
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   133
  specification.  The final result will be stored within the named
13538
wenzelm
parents: 13457
diff changeset
   134
  locale, still holding the context; a second copy is exported to the
wenzelm
parents: 13457
diff changeset
   135
  enclosing theory context (with qualified name).
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   136
*}
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   137
12574
wenzelm
parents: 12507
diff changeset
   138
theorem (in group_context)
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   139
  right_inv: "x \<cdot> x\<inv> = \<one>"
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   140
proof -
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   141
  have "x \<cdot> x\<inv> = \<one> \<cdot> (x \<cdot> x\<inv>)" by (simp only: left_one)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   142
  also have "\<dots> = \<one> \<cdot> x \<cdot> x\<inv>" by (simp only: assoc)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   143
  also have "\<dots> = (x\<inv>)\<inv> \<cdot> x\<inv> \<cdot> x \<cdot> x\<inv>" by (simp only: left_inv)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   144
  also have "\<dots> = (x\<inv>)\<inv> \<cdot> (x\<inv> \<cdot> x) \<cdot> x\<inv>" by (simp only: assoc)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   145
  also have "\<dots> = (x\<inv>)\<inv> \<cdot> \<one> \<cdot> x\<inv>" by (simp only: left_inv)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   146
  also have "\<dots> = (x\<inv>)\<inv> \<cdot> (\<one> \<cdot> x\<inv>)" by (simp only: assoc)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   147
  also have "\<dots> = (x\<inv>)\<inv> \<cdot> x\<inv>" by (simp only: left_one)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   148
  also have "\<dots> = \<one>" by (simp only: left_inv)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   149
  finally show ?thesis .
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   150
qed
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   151
12574
wenzelm
parents: 12507
diff changeset
   152
theorem (in group_context)
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   153
  right_one: "x \<cdot> \<one> = x"
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   154
proof -
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   155
  have "x \<cdot> \<one> = x \<cdot> (x\<inv> \<cdot> x)" by (simp only: left_inv)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   156
  also have "\<dots> = x \<cdot> x\<inv> \<cdot> x" by (simp only: assoc)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   157
  also have "\<dots> = \<one> \<cdot> x" by (simp only: right_inv)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   158
  also have "\<dots> = x" by (simp only: left_one)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   159
  finally show ?thesis .
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   160
qed
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   161
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   162
text {*
13538
wenzelm
parents: 13457
diff changeset
   163
  Facts like @{text right_one} are available @{text group_context} as
wenzelm
parents: 13457
diff changeset
   164
  stated above.  The exported version looses the additional
wenzelm
parents: 13457
diff changeset
   165
  infrastructure of Isar proof contexts (syntax etc.) retaining only
wenzelm
parents: 13457
diff changeset
   166
  the pure logical content: @{thm [source] group_context.right_one}
wenzelm
parents: 13457
diff changeset
   167
  becomes @{thm group_context.right_one} (in Isabelle outermost @{text
wenzelm
parents: 13457
diff changeset
   168
  \<And>} quantification is replaced by schematic variables).
wenzelm
parents: 13457
diff changeset
   169
wenzelm
parents: 13457
diff changeset
   170
  \medskip Apart from a named locale we may also refer to further
wenzelm
parents: 13457
diff changeset
   171
  context elements (parameters, assumptions, etc.) in an ad-hoc
wenzelm
parents: 13457
diff changeset
   172
  fashion, just for this particular statement.  In the result (local
wenzelm
parents: 13457
diff changeset
   173
  or global), any additional elements are discharged as usual.
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   174
*}
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   175
12574
wenzelm
parents: 12507
diff changeset
   176
theorem (in group_context)
12937
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12574
diff changeset
   177
  assumes eq: "e \<cdot> x = x"
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12574
diff changeset
   178
  shows one_equality: "\<one> = e"
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   179
proof -
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   180
  have "\<one> = x \<cdot> x\<inv>" by (simp only: right_inv)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   181
  also have "\<dots> = (e \<cdot> x) \<cdot> x\<inv>" by (simp only: eq)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   182
  also have "\<dots> = e \<cdot> (x \<cdot> x\<inv>)" by (simp only: assoc)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   183
  also have "\<dots> = e \<cdot> \<one>" by (simp only: right_inv)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   184
  also have "\<dots> = e" by (simp only: right_one)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   185
  finally show ?thesis .
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   186
qed
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   187
12574
wenzelm
parents: 12507
diff changeset
   188
theorem (in group_context)
12937
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12574
diff changeset
   189
  assumes eq: "x' \<cdot> x = \<one>"
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12574
diff changeset
   190
  shows inv_equality: "x\<inv> = x'"
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   191
proof -
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   192
  have "x\<inv> = \<one> \<cdot> x\<inv>" by (simp only: left_one)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   193
  also have "\<dots> = (x' \<cdot> x) \<cdot> x\<inv>" by (simp only: eq)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   194
  also have "\<dots> = x' \<cdot> (x \<cdot> x\<inv>)" by (simp only: assoc)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   195
  also have "\<dots> = x' \<cdot> \<one>" by (simp only: right_inv)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   196
  also have "\<dots> = x'" by (simp only: right_one)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   197
  finally show ?thesis .
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   198
qed
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   199
12574
wenzelm
parents: 12507
diff changeset
   200
theorem (in group_context)
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   201
  inv_prod: "(x \<cdot> y)\<inv> = y\<inv> \<cdot> x\<inv>"
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   202
proof (rule inv_equality)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   203
  show "(y\<inv> \<cdot> x\<inv>) \<cdot> (x \<cdot> y) = \<one>"
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   204
  proof -
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   205
    have "(y\<inv> \<cdot> x\<inv>) \<cdot> (x \<cdot> y) = (y\<inv> \<cdot> (x\<inv> \<cdot> x)) \<cdot> y" by (simp only: assoc)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   206
    also have "\<dots> = (y\<inv> \<cdot> \<one>) \<cdot> y" by (simp only: left_inv)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   207
    also have "\<dots> = y\<inv> \<cdot> y" by (simp only: right_one)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   208
    also have "\<dots> = \<one>" by (simp only: left_inv)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   209
    finally show ?thesis .
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   210
  qed
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   211
qed
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   212
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   213
text {*
12105
wenzelm
parents: 12099
diff changeset
   214
  \medskip Established results are automatically propagated through
wenzelm
parents: 12099
diff changeset
   215
  the hierarchy of locales.  Below we establish a trivial fact in
wenzelm
parents: 12099
diff changeset
   216
  commutative groups, while referring both to theorems of @{text
wenzelm
parents: 12099
diff changeset
   217
  group} and the additional assumption of @{text abelian_group}.
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   218
*}
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   219
12574
wenzelm
parents: 12507
diff changeset
   220
theorem (in abelian_group_context)
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   221
  inv_prod': "(x \<cdot> y)\<inv> = x\<inv> \<cdot> y\<inv>"
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   222
proof -
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   223
  have "(x \<cdot> y)\<inv> = y\<inv> \<cdot> x\<inv>" by (rule inv_prod)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   224
  also have "\<dots> = x\<inv> \<cdot> y\<inv>" by (rule commute)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   225
  finally show ?thesis .
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   226
qed
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   227
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   228
text {*
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   229
  We see that the initial import of @{text group} within the
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   230
  definition of @{text abelian_group} is actually evaluated
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   231
  dynamically.  Thus any results in @{text group} are made available
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   232
  to the derived context of @{text abelian_group} as well.  Note that
12965
c8a97eb1e3c7 renamed 'uses' to 'includes';
wenzelm
parents: 12955
diff changeset
   233
  the alternative context element @{text \<INCLUDES>} would import
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   234
  existing locales in a static fashion, without participating in
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   235
  further facts emerging later on.
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   236
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   237
  \medskip Some more properties of inversion in general group theory
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   238
  follow.
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   239
*}
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   240
12574
wenzelm
parents: 12507
diff changeset
   241
theorem (in group_context)
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   242
  inv_inv: "(x\<inv>)\<inv> = x"
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   243
proof (rule inv_equality)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   244
  show "x \<cdot> x\<inv> = \<one>" by (simp only: right_inv)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   245
qed
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   246
12574
wenzelm
parents: 12507
diff changeset
   247
theorem (in group_context)
12937
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12574
diff changeset
   248
  assumes eq: "x\<inv> = y\<inv>"
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12574
diff changeset
   249
  shows inv_inject: "x = y"
12075
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   250
proof -
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   251
  have "x = x \<cdot> \<one>" by (simp only: right_one)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   252
  also have "\<dots> = x \<cdot> (y\<inv> \<cdot> y)" by (simp only: left_inv)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   253
  also have "\<dots> = x \<cdot> (x\<inv> \<cdot> y)" by (simp only: eq)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   254
  also have "\<dots> = (x \<cdot> x\<inv>) \<cdot> y" by (simp only: assoc)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   255
  also have "\<dots> = \<one> \<cdot> y" by (simp only: right_inv)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   256
  also have "\<dots> = y" by (simp only: left_one)
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   257
  finally show ?thesis .
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   258
qed
8d65dd96381f Locales and simple mathematical structures;
wenzelm
parents:
diff changeset
   259
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   260
text {*
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   261
  \bigskip We see that this representation of structures as local
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   262
  contexts is rather light-weight and convenient to use for abstract
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   263
  reasoning.  Here the ``components'' (the group operations) have been
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   264
  exhibited directly as context parameters; logically this corresponds
13383
041d78bf9403 adapted locales;
wenzelm
parents: 13107
diff changeset
   265
  to a curried predicate definition:
041d78bf9403 adapted locales;
wenzelm
parents: 13107
diff changeset
   266
13419
wenzelm
parents: 13383
diff changeset
   267
  @{thm [display] group_context_def [no_vars]}
wenzelm
parents: 13383
diff changeset
   268
wenzelm
parents: 13383
diff changeset
   269
  The corresponding introduction rule is as follows:
wenzelm
parents: 13383
diff changeset
   270
13457
wenzelm
parents: 13419
diff changeset
   271
  @{thm [display, mode = no_brackets] group_context.intro [no_vars]}
13383
041d78bf9403 adapted locales;
wenzelm
parents: 13107
diff changeset
   272
041d78bf9403 adapted locales;
wenzelm
parents: 13107
diff changeset
   273
  Occasionally, this ``externalized'' version of the informal idea of
041d78bf9403 adapted locales;
wenzelm
parents: 13107
diff changeset
   274
  classes of tuple structures may cause some inconveniences,
041d78bf9403 adapted locales;
wenzelm
parents: 13107
diff changeset
   275
  especially in meta-theoretical studies (involving functors from
041d78bf9403 adapted locales;
wenzelm
parents: 13107
diff changeset
   276
  groups to groups, for example).
12091
08b4da78d1ad added structures;
wenzelm
parents: 12075
diff changeset
   277
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   278
  Another minor drawback of the naive approach above is that concrete
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   279
  syntax will get lost on any kind of operation on the locale itself
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   280
  (such as renaming, copying, or instantiation).  Whenever the
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   281
  particular terminology of local parameters is affected the
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   282
  associated syntax would have to be changed as well, which is hard to
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   283
  achieve formally.
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   284
*}
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   285
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   286
12105
wenzelm
parents: 12099
diff changeset
   287
subsection {* Explicit structures referenced implicitly *}
12091
08b4da78d1ad added structures;
wenzelm
parents: 12075
diff changeset
   288
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   289
text {*
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   290
  We introduce the same hierarchy of basic group structures as above,
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   291
  this time using extensible record types for the signature part,
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   292
  together with concrete syntax for selector functions.
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   293
*}
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   294
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   295
record 'a semigroup =
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   296
  prod :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"    (infixl "\<cdot>\<index>" 70)
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   297
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   298
record 'a group = "'a semigroup" +
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   299
  inv :: "'a \<Rightarrow> 'a"    ("(_\<inv>\<index>)" [1000] 999)
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   300
  one :: 'a    ("\<one>\<index>")
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   301
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   302
text {*
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   303
  The mixfix annotations above include a special ``structure index
13457
wenzelm
parents: 13419
diff changeset
   304
  indicator'' @{text \<index>} that makes grammar productions dependent on
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   305
  certain parameters that have been declared as ``structure'' in a
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   306
  locale context later on.  Thus we achieve casual notation as
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   307
  encountered in informal mathematics, e.g.\ @{text "x \<cdot> y"} for
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   308
  @{text "prod G x y"}.
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   309
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   310
  \medskip The following locale definitions introduce operate on a
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   311
  single parameter declared as ``\isakeyword{structure}''.  Type
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   312
  inference takes care to fill in the appropriate record type schemes
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   313
  internally.
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   314
*}
12091
08b4da78d1ad added structures;
wenzelm
parents: 12075
diff changeset
   315
12574
wenzelm
parents: 12507
diff changeset
   316
locale semigroup =
13457
wenzelm
parents: 13419
diff changeset
   317
  fixes S    (structure)
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   318
  assumes assoc: "(x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)"
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   319
12574
wenzelm
parents: 12507
diff changeset
   320
locale group = semigroup G +
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   321
  assumes left_inv: "x\<inv> \<cdot> x = \<one>"
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   322
    and left_one: "\<one> \<cdot> x = x"
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   323
14254
342634f38451 Isar/Locales: <loc>.intro and <loc>.axioms no longer intro? and elim? by
ballarin
parents: 13538
diff changeset
   324
declare semigroup.intro [intro?]
342634f38451 Isar/Locales: <loc>.intro and <loc>.axioms no longer intro? and elim? by
ballarin
parents: 13538
diff changeset
   325
  group.intro [intro?] group_axioms.intro [intro?]
342634f38451 Isar/Locales: <loc>.intro and <loc>.axioms no longer intro? and elim? by
ballarin
parents: 13538
diff changeset
   326
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   327
text {*
12507
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   328
  Note that we prefer to call the @{text group} record structure
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   329
  @{text G} rather than @{text S} inherited from @{text semigroup}.
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   330
  This does not affect our concrete syntax, which is only dependent on
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   331
  the \emph{positional} arrangements of currently active structures
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   332
  (actually only one above), rather than names.  In fact, these
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   333
  parameter names rarely occur in the term language at all (due to the
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   334
  ``indexed syntax'' facility of Isabelle).  On the other hand, names
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   335
  of locale facts will get qualified accordingly, e.g. @{text S.assoc}
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   336
  versus @{text G.assoc}.
cc36d5da9bc0 updated;
wenzelm
parents: 12356
diff changeset
   337
12574
wenzelm
parents: 12507
diff changeset
   338
  \medskip We may now proceed to prove results within @{text group}
wenzelm
parents: 12507
diff changeset
   339
  just as before for @{text group}.  The subsequent proof texts are
wenzelm
parents: 12507
diff changeset
   340
  exactly the same as despite the more advanced internal arrangement.
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   341
*}
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   342
12574
wenzelm
parents: 12507
diff changeset
   343
theorem (in group)
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   344
  right_inv: "x \<cdot> x\<inv> = \<one>"
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   345
proof -
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   346
  have "x \<cdot> x\<inv> = \<one> \<cdot> (x \<cdot> x\<inv>)" by (simp only: left_one)
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   347
  also have "\<dots> = \<one> \<cdot> x \<cdot> x\<inv>" by (simp only: assoc)
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   348
  also have "\<dots> = (x\<inv>)\<inv> \<cdot> x\<inv> \<cdot> x \<cdot> x\<inv>" by (simp only: left_inv)
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   349
  also have "\<dots> = (x\<inv>)\<inv> \<cdot> (x\<inv> \<cdot> x) \<cdot> x\<inv>" by (simp only: assoc)
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   350
  also have "\<dots> = (x\<inv>)\<inv> \<cdot> \<one> \<cdot> x\<inv>" by (simp only: left_inv)
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   351
  also have "\<dots> = (x\<inv>)\<inv> \<cdot> (\<one> \<cdot> x\<inv>)" by (simp only: assoc)
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   352
  also have "\<dots> = (x\<inv>)\<inv> \<cdot> x\<inv>" by (simp only: left_one)
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   353
  also have "\<dots> = \<one>" by (simp only: left_inv)
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   354
  finally show ?thesis .
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   355
qed
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   356
12574
wenzelm
parents: 12507
diff changeset
   357
theorem (in group)
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   358
  right_one: "x \<cdot> \<one> = x"
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   359
proof -
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   360
  have "x \<cdot> \<one> = x \<cdot> (x\<inv> \<cdot> x)" by (simp only: left_inv)
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   361
  also have "\<dots> = x \<cdot> x\<inv> \<cdot> x" by (simp only: assoc)
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   362
  also have "\<dots> = \<one> \<cdot> x" by (simp only: right_inv)
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   363
  also have "\<dots> = x" by (simp only: left_one)
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   364
  finally show ?thesis .
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   365
qed
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   366
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   367
text {*
12574
wenzelm
parents: 12507
diff changeset
   368
  \medskip Several implicit structures may be active at the same time.
wenzelm
parents: 12507
diff changeset
   369
  The concrete syntax facility for locales actually maintains indexed
wenzelm
parents: 12507
diff changeset
   370
  structures that may be references implicitly --- via mixfix
wenzelm
parents: 12507
diff changeset
   371
  annotations that have been decorated by an ``index argument''
wenzelm
parents: 12507
diff changeset
   372
  (@{text \<index>}).
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   373
12574
wenzelm
parents: 12507
diff changeset
   374
  The following synthetic example demonstrates how to refer to several
wenzelm
parents: 12507
diff changeset
   375
  structures of type @{text group} succinctly.  We work with two
wenzelm
parents: 12507
diff changeset
   376
  versions of the @{text group} locale above.
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   377
*}
12091
08b4da78d1ad added structures;
wenzelm
parents: 12075
diff changeset
   378
12937
0c4fd7529467 clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents: 12574
diff changeset
   379
lemma
12955
f4d60f358cb6 renamed "uses" to "includes";
wenzelm
parents: 12937
diff changeset
   380
  includes group G
f4d60f358cb6 renamed "uses" to "includes";
wenzelm
parents: 12937
diff changeset
   381
  includes group H
13107
8743cc847224 tuned presentation;
wenzelm
parents: 12965
diff changeset
   382
  shows "x \<cdot> y \<cdot> \<one> = prod G (prod G x y) (one G)"
8743cc847224 tuned presentation;
wenzelm
parents: 12965
diff changeset
   383
    and "x \<cdot>\<^sub>2 y \<cdot>\<^sub>2 \<one>\<^sub>2 = prod H (prod H x y) (one H)"
8743cc847224 tuned presentation;
wenzelm
parents: 12965
diff changeset
   384
    and "x \<cdot> \<one>\<^sub>2 = prod G x (one H)"
8743cc847224 tuned presentation;
wenzelm
parents: 12965
diff changeset
   385
  by (rule refl)+
12574
wenzelm
parents: 12507
diff changeset
   386
wenzelm
parents: 12507
diff changeset
   387
text {*
wenzelm
parents: 12507
diff changeset
   388
  Note that the trivial statements above need to be given as a
wenzelm
parents: 12507
diff changeset
   389
  simultaneous goal in order to have type-inference make the implicit
wenzelm
parents: 12507
diff changeset
   390
  typing of structures @{text G} and @{text H} agree.
wenzelm
parents: 12507
diff changeset
   391
*}
12091
08b4da78d1ad added structures;
wenzelm
parents: 12075
diff changeset
   392
13457
wenzelm
parents: 13419
diff changeset
   393
wenzelm
parents: 13419
diff changeset
   394
subsection {* Simple meta-theory of structures *}
wenzelm
parents: 13419
diff changeset
   395
wenzelm
parents: 13419
diff changeset
   396
text {*
wenzelm
parents: 13419
diff changeset
   397
  The packaging of the logical specification as a predicate and the
wenzelm
parents: 13419
diff changeset
   398
  syntactic structure as a record type provides a reasonable starting
wenzelm
parents: 13419
diff changeset
   399
  point for simple meta-theoretic studies of mathematical structures.
wenzelm
parents: 13419
diff changeset
   400
  This includes operations on structures (also known as ``functors''),
wenzelm
parents: 13419
diff changeset
   401
  and statements about such constructions.
wenzelm
parents: 13419
diff changeset
   402
wenzelm
parents: 13419
diff changeset
   403
  For example, the direct product of semigroups works as follows.
wenzelm
parents: 13419
diff changeset
   404
*}
wenzelm
parents: 13419
diff changeset
   405
wenzelm
parents: 13419
diff changeset
   406
constdefs
wenzelm
parents: 13419
diff changeset
   407
  semigroup_product :: "'a semigroup \<Rightarrow> 'b semigroup \<Rightarrow> ('a \<times> 'b) semigroup"
13538
wenzelm
parents: 13457
diff changeset
   408
  "semigroup_product S T \<equiv>
wenzelm
parents: 13457
diff changeset
   409
    \<lparr>prod = \<lambda>p q. (prod S (fst p) (fst q), prod T (snd p) (snd q))\<rparr>"
13457
wenzelm
parents: 13419
diff changeset
   410
wenzelm
parents: 13419
diff changeset
   411
lemma semigroup_product [intro]:
wenzelm
parents: 13419
diff changeset
   412
  assumes S: "semigroup S"
wenzelm
parents: 13419
diff changeset
   413
    and T: "semigroup T"
wenzelm
parents: 13419
diff changeset
   414
  shows "semigroup (semigroup_product S T)"
wenzelm
parents: 13419
diff changeset
   415
proof
wenzelm
parents: 13419
diff changeset
   416
  fix p q r :: "'a \<times> 'b"
wenzelm
parents: 13419
diff changeset
   417
  have "prod S (prod S (fst p) (fst q)) (fst r) =
wenzelm
parents: 13419
diff changeset
   418
      prod S (fst p) (prod S (fst q) (fst r))"
wenzelm
parents: 13419
diff changeset
   419
    by (rule semigroup.assoc [OF S])
wenzelm
parents: 13419
diff changeset
   420
  moreover have "prod T (prod T (snd p) (snd q)) (snd r) =
wenzelm
parents: 13419
diff changeset
   421
      prod T (snd p) (prod T (snd q) (snd r))"
wenzelm
parents: 13419
diff changeset
   422
    by (rule semigroup.assoc [OF T])
13538
wenzelm
parents: 13457
diff changeset
   423
  ultimately
wenzelm
parents: 13457
diff changeset
   424
  show "prod (semigroup_product S T) (prod (semigroup_product S T) p q) r =
13457
wenzelm
parents: 13419
diff changeset
   425
      prod (semigroup_product S T) p (prod (semigroup_product S T) q r)"
wenzelm
parents: 13419
diff changeset
   426
    by (simp add: semigroup_product_def)
wenzelm
parents: 13419
diff changeset
   427
qed
wenzelm
parents: 13419
diff changeset
   428
wenzelm
parents: 13419
diff changeset
   429
text {*
wenzelm
parents: 13419
diff changeset
   430
  The above proof is fairly easy, but obscured by the lack of concrete
wenzelm
parents: 13419
diff changeset
   431
  syntax.  In fact, we didn't make use of the infrastructure of
wenzelm
parents: 13419
diff changeset
   432
  locales, apart from the raw predicate definition of @{text
wenzelm
parents: 13419
diff changeset
   433
  semigroup}.
wenzelm
parents: 13419
diff changeset
   434
wenzelm
parents: 13419
diff changeset
   435
  The alternative version below uses local context expressions to
wenzelm
parents: 13419
diff changeset
   436
  achieve a succinct proof body.  The resulting statement is exactly
wenzelm
parents: 13419
diff changeset
   437
  the same as before, even though its specification is a bit more
wenzelm
parents: 13419
diff changeset
   438
  complex.
wenzelm
parents: 13419
diff changeset
   439
*}
wenzelm
parents: 13419
diff changeset
   440
wenzelm
parents: 13419
diff changeset
   441
lemma
wenzelm
parents: 13419
diff changeset
   442
  includes semigroup S + semigroup T
wenzelm
parents: 13419
diff changeset
   443
  fixes U    (structure)
wenzelm
parents: 13419
diff changeset
   444
  defines "U \<equiv> semigroup_product S T"
wenzelm
parents: 13419
diff changeset
   445
  shows "semigroup U"
wenzelm
parents: 13419
diff changeset
   446
proof
wenzelm
parents: 13419
diff changeset
   447
  fix p q r :: "'a \<times> 'b"
wenzelm
parents: 13419
diff changeset
   448
  have "(fst p \<cdot>\<^sub>1 fst q) \<cdot>\<^sub>1 fst r = fst p \<cdot>\<^sub>1 (fst q \<cdot>\<^sub>1 fst r)"
wenzelm
parents: 13419
diff changeset
   449
    by (rule S.assoc)
wenzelm
parents: 13419
diff changeset
   450
  moreover have "(snd p \<cdot>\<^sub>2 snd q) \<cdot>\<^sub>2 snd r = snd p \<cdot>\<^sub>2 (snd q \<cdot>\<^sub>2 snd r)"
wenzelm
parents: 13419
diff changeset
   451
    by (rule T.assoc)
wenzelm
parents: 13419
diff changeset
   452
  ultimately show "(p \<cdot>\<^sub>3 q) \<cdot>\<^sub>3 r = p \<cdot>\<^sub>3 (q \<cdot>\<^sub>3 r)"
wenzelm
parents: 13419
diff changeset
   453
    by (simp add: U_def semigroup_product_def semigroup.defs)
wenzelm
parents: 13419
diff changeset
   454
qed
wenzelm
parents: 13419
diff changeset
   455
wenzelm
parents: 13419
diff changeset
   456
text {*
wenzelm
parents: 13419
diff changeset
   457
  Direct products of group structures may be defined in a similar
wenzelm
parents: 13419
diff changeset
   458
  manner, taking two further operations into account.  Subsequently,
wenzelm
parents: 13419
diff changeset
   459
  we use high-level record operations to convert between different
wenzelm
parents: 13419
diff changeset
   460
  signature types explicitly; see also
wenzelm
parents: 13419
diff changeset
   461
  \cite[\S8.3]{isabelle-hol-book}.
wenzelm
parents: 13419
diff changeset
   462
*}
wenzelm
parents: 13419
diff changeset
   463
wenzelm
parents: 13419
diff changeset
   464
constdefs
wenzelm
parents: 13419
diff changeset
   465
  group_product :: "'a group \<Rightarrow> 'b group \<Rightarrow> ('a \<times> 'b) group"
wenzelm
parents: 13419
diff changeset
   466
  "group_product G H \<equiv>
wenzelm
parents: 13419
diff changeset
   467
    semigroup.extend
wenzelm
parents: 13419
diff changeset
   468
      (semigroup_product (semigroup.truncate G) (semigroup.truncate H))
wenzelm
parents: 13419
diff changeset
   469
      (group.fields (\<lambda>p. (inv G (fst p), inv H (snd p))) (one G, one H))"
wenzelm
parents: 13419
diff changeset
   470
wenzelm
parents: 13419
diff changeset
   471
lemma group_product_aux:
wenzelm
parents: 13419
diff changeset
   472
  includes group G + group H
wenzelm
parents: 13419
diff changeset
   473
  fixes I    (structure)
wenzelm
parents: 13419
diff changeset
   474
  defines "I \<equiv> group_product G H"
wenzelm
parents: 13419
diff changeset
   475
  shows "group I"
wenzelm
parents: 13419
diff changeset
   476
proof
wenzelm
parents: 13419
diff changeset
   477
  show "semigroup I"
wenzelm
parents: 13419
diff changeset
   478
  proof -
wenzelm
parents: 13419
diff changeset
   479
    let ?G' = "semigroup.truncate G" and ?H' = "semigroup.truncate H"
wenzelm
parents: 13419
diff changeset
   480
    have "prod (semigroup_product ?G' ?H') = prod I"
13538
wenzelm
parents: 13457
diff changeset
   481
      by (simp add: I_def group_product_def group.defs
wenzelm
parents: 13457
diff changeset
   482
	semigroup_product_def semigroup.defs)
13457
wenzelm
parents: 13419
diff changeset
   483
    moreover
wenzelm
parents: 13419
diff changeset
   484
    have "semigroup ?G'" and "semigroup ?H'"
wenzelm
parents: 13419
diff changeset
   485
      using prems by (simp_all add: semigroup_def semigroup.defs)
wenzelm
parents: 13419
diff changeset
   486
    then have "semigroup (semigroup_product ?G' ?H')" ..
wenzelm
parents: 13419
diff changeset
   487
    ultimately show ?thesis by (simp add: I_def semigroup_def)
wenzelm
parents: 13419
diff changeset
   488
  qed
wenzelm
parents: 13419
diff changeset
   489
  show "group_axioms I"
wenzelm
parents: 13419
diff changeset
   490
  proof
wenzelm
parents: 13419
diff changeset
   491
    fix p :: "'a \<times> 'b"
wenzelm
parents: 13419
diff changeset
   492
    have "(fst p)\<inv>\<^sub>1 \<cdot>\<^sub>1 fst p = \<one>\<^sub>1"
wenzelm
parents: 13419
diff changeset
   493
      by (rule G.left_inv)
wenzelm
parents: 13419
diff changeset
   494
    moreover have "(snd p)\<inv>\<^sub>2 \<cdot>\<^sub>2 snd p = \<one>\<^sub>2"
wenzelm
parents: 13419
diff changeset
   495
      by (rule H.left_inv)
wenzelm
parents: 13419
diff changeset
   496
    ultimately show "p\<inv>\<^sub>3 \<cdot>\<^sub>3 p = \<one>\<^sub>3"
13538
wenzelm
parents: 13457
diff changeset
   497
      by (simp add: I_def group_product_def group.defs
wenzelm
parents: 13457
diff changeset
   498
	semigroup_product_def semigroup.defs)
13457
wenzelm
parents: 13419
diff changeset
   499
    have "\<one>\<^sub>1 \<cdot>\<^sub>1 fst p = fst p" by (rule G.left_one)
wenzelm
parents: 13419
diff changeset
   500
    moreover have "\<one>\<^sub>2 \<cdot>\<^sub>2 snd p = snd p" by (rule H.left_one)
wenzelm
parents: 13419
diff changeset
   501
    ultimately show "\<one>\<^sub>3 \<cdot>\<^sub>3 p = p"
13538
wenzelm
parents: 13457
diff changeset
   502
      by (simp add: I_def group_product_def group.defs
wenzelm
parents: 13457
diff changeset
   503
	semigroup_product_def semigroup.defs)
13457
wenzelm
parents: 13419
diff changeset
   504
  qed
wenzelm
parents: 13419
diff changeset
   505
qed
wenzelm
parents: 13419
diff changeset
   506
wenzelm
parents: 13419
diff changeset
   507
theorem group_product: "group G \<Longrightarrow> group H \<Longrightarrow> group (group_product G H)"
wenzelm
parents: 13419
diff changeset
   508
  by (rule group_product_aux) (assumption | rule group.axioms)+
wenzelm
parents: 13419
diff changeset
   509
12099
8504c948fae2 more explanations on advanced syntax;
wenzelm
parents: 12091
diff changeset
   510
end