src/Doc/Typeclass_Hierarchy/Typeclass_Hierarchy.thy
author haftmann
Sun, 24 Jul 2016 16:48:41 +0200
changeset 63555 d00db72d8697
parent 63026 9a9c2d846d4a
child 66453 cc19f7ca2ed6
permissions -rw-r--r--
more on type class hierarchy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63026
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     1
theory Typeclass_Hierarchy
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     2
imports Setup
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     3
begin
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     4
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     5
section \<open>Introduction\<close>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     6
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     7
text \<open>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     8
  The {Isabelle/HOL} type-class hierarchy entered the stage
63555
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
     9
  in a quite ancient era -- first related \<^emph>\<open>NEWS\<close> entries date
63026
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    10
  back to release {Isabelle99-1}.  Since then, there have been
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    11
  ongoing modifications and additions, leading to ({Isabelle2016})
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    12
  more than 180 type-classes.  This sheer complexity makes access
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    13
  and understanding of that type-class hierarchy difficult and
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    14
  involved, let alone maintenance.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    15
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    16
  The purpose of this primer is to shed some light on this,
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    17
  not only on the mere ingredients, but also on the design
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    18
  principles which have evolved and proven useful over time.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    19
\<close>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    20
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    21
section \<open>Foundations\<close>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    22
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    23
subsection \<open>Locales and type classes\<close>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    24
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    25
text \<open>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    26
  Some familiarity with the Isabelle module system is assumed:
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    27
  defining locales and type-classes, interpreting locales and
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    28
  instantiating type-classes, adding relationships between
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    29
  locales (@{command sublocale}) and type-classes
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    30
  (@{command subclass}).  Handy introductions are the
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    31
  respective tutorials \cite{isabelle-locale}
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    32
  \cite{isabelle-classes}.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    33
\<close>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    34
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    35
subsection \<open>Strengths and restrictions of type classes\<close>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    36
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    37
text \<open>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    38
  The primary motivation for using type classes in {Isabelle/HOL}
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    39
  always have been numerical types, which form an inclusion chain:
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    40
  
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    41
  \begin{center}
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    42
    @{typ nat} @{text \<sqsubset>} @{typ int} @{text \<sqsubset>} @{typ rat}
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    43
      @{text \<sqsubset>} @{typ real} @{text \<sqsubset>} @{typ complex}
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    44
  \end{center}
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    45
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    46
  \noindent The inclusion @{text \<sqsubset>} means that any value of the numerical
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    47
  type to the left hand side mathematically can be transferred
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    48
  to the numerical type on the right hand side.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    49
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    50
  How to accomplish this given the quite restrictive type system
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    51
  of {Isabelle/HOL}?  Paulson \cite{paulson-numerical} explains
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    52
  that each numerical type has some characteristic properties
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    53
  which define an characteristic algebraic structure;  @{text \<sqsubset>}
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    54
  then corresponds to specialization of the corresponding
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    55
  characteristic algebraic structures.  These algebraic structures
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    56
  are expressed using algebraic type classes and embeddings
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    57
  of numerical types into them:
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    58
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    59
  \begin{center}\begin{tabular}{lccc}
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    60
    @{term of_nat} @{text "::"}  & @{typ nat}  & @{text \<Rightarrow>} & @{typ [source] "'a::semiring_1"} \\
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    61
                                 & @{text \<sqinter>}   &            & @{text \<up>} \\
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    62
    @{term of_int} @{text "::"}  & @{typ int}  & @{text \<Rightarrow>} & @{typ [source] "'a::ring_1"} \\
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    63
                                 & @{text \<sqinter>}   &            & @{text \<up>} \\
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    64
    @{term of_rat} @{text "::"}  & @{typ rat}  & @{text \<Rightarrow>} & @{typ [source] "'a::field_char_0"} \\
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    65
                                 & @{text \<sqinter>}   &            & @{text \<up>} \\
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    66
    @{term of_real} @{text "::"} & @{typ real} & @{text \<Rightarrow>} & @{typ [source] "'a::real_algebra_1"} \\
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    67
                                 & @{text \<sqinter>} \\
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    68
                                 & @{typ complex}
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    69
  \end{tabular}\end{center}
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    70
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    71
  \noindent @{text "d \<leftarrow> c"} means that @{text c} is subclass of @{text d}.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    72
  Hence each characteristic embedding @{text of_num} can transform
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    73
  any value of type @{text num} to any numerical type further
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    74
  up in the inclusion chain.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    75
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    76
  This canonical example exhibits key strengths of type classes:
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    77
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    78
    \<^item> Sharing of operations and facts among different
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    79
      types, hence also sharing of notation and names: there
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    80
      is only one plus operation using infix syntax @{text "+"},
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    81
      only one zero written @{text 0}, and neutrality
63555
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    82
      (@{thm (frugal_sorts) add_0_left [all, no_vars]} and
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    83
      @{thm (frugal_sorts) add_0_right [all, no_vars]})
63026
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    84
      is referred to
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    85
      uniformly by names @{fact add_0_left} and @{fact add_0_right}.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    86
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    87
    \<^item> Proof tool setups are shared implicitly:
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    88
      @{fact add_0} and @{fact add_0_right} are simplification
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    89
      rules by default.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    90
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    91
    \<^item> Hence existing proofs about particular numerical
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    92
      types are often easy to generalize to algebraic structures,
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    93
      given that they do not depend on specific properties of
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    94
      those numerical types.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    95
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    96
  Considerable restrictions include:
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    97
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    98
    \<^item> Type class operations are restricted to one
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    99
      type parameter; this is insufficient e.g. for expressing
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   100
      a unified power operation adequately (see \secref{sec:power}).
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   101
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   102
    \<^item> Parameters are fixed over the whole type class
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   103
      hierarchy and cannot be refined in specific situations:
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   104
      think of integral domains with a predicate @{term is_unit};
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   105
      for natural numbers, this degenerates to the much simpler
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   106
      @{term [source] "HOL.equal (1::nat)"} but facts
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   107
      refer to @{term is_unit} nonetheless.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   108
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   109
    \<^item> Type classes are not apt for meta-theory.  There
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   110
      is no practically usable way to express that the units
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   111
      of an integral domain form a multiplicative group using
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   112
      type classes.  But see session @{text "HOL-Algebra"}
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   113
      which provides locales with an explicit carrier.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   114
\<close>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   115
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   116
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   117
subsection \<open>Navigating the hierarchy\<close>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   118
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   119
text \<open>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   120
  An indispensable tool to inspect the class hierarchy is
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   121
  @{command class_deps} which displays the graph of classes,
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   122
  optionally showing the logical content for each class also.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   123
  Optional parameters restrict the graph to a particular segment
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   124
  which is useful to get a graspable view.  See
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   125
  the Isar reference manual \cite{isabelle-isar-ref} for details.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   126
\<close>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   127
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   128
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   129
section \<open>The hierarchy\<close>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   130
63555
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   131
subsection \<open>Syntactic type classes \label{sec:syntactic-type-class}\<close>
63026
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   132
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   133
text \<open>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   134
  At the top of the hierarchy there are a couple of syntactic type
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   135
  classes, ie. classes with operations but with no axioms,
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   136
  most notably:
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   137
63555
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   138
    \<^item> @{command class} @{class plus} with @{term [source] "(a::'a::plus) + b"}
63026
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   139
63555
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   140
    \<^item> @{command class} @{class zero} with @{term [source] "0::'a::zero"}
63026
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   141
63555
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   142
    \<^item> @{command class} @{class times} with @{term [source] "(a::'a::times) * b"}
63026
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   143
63555
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   144
    \<^item> @{command class} @{class one} with @{term [source] "1::'a::one"}
63026
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   145
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   146
  \noindent Before the introduction of the @{command class} statement in
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   147
  Isabelle \cite{Haftmann-Wenzel:2006:classes} it was impossible
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   148
  to define operations with associated axioms in the same class,
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   149
  hence there were always pairs of syntactic and logical type
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   150
  classes.  This restriction is lifted nowadays, but there are
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   151
  still reasons to maintain syntactic type classes:
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   152
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   153
    \<^item> Syntactic type classes allow generic notation to be used
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   154
      regardless of a particular logical interpretation; e.g.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   155
      although multiplication @{text "*"} is usually associative,
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   156
      there are examples where it is not (e.g. octonions), and
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   157
      leaving @{text "*"} without axioms allows to re-use this
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   158
      syntax by means of type class instantiation also for such
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   159
      exotic examples.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   160
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   161
    \<^item> Type classes might share operations but not necessarily
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   162
      axioms on them, e.g. @{term gcd} (see \secref{sec:gcd}).
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   163
      Hence their common base is a syntactic type class.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   164
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   165
  \noindent However syntactic type classes should only be used with striking
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   166
  cause.  Otherwise there is risk for confusion if the notation
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   167
  suggests properties which do not hold without particular
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   168
  constraints.  This can be illustrated using numerals
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   169
  (see \secref{sec:numerals}):  @{lemma "2 + 2 = 4" by simp} is
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   170
  provable without further ado, and this also meets the typical
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   171
  expectation towards a numeral notation;  in more ancient releases
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   172
  numerals were purely syntactic and @{prop "2 + 2 = 4"} was
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   173
  not provable without particular type constraints.
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   174
\<close>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   175
63555
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   176
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   177
subsection \<open>Additive and multiplicative semigroups and monoids\<close>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   178
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   179
text \<open>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   180
  In common literature, notation for semigroups and monoids
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   181
  is either multiplicative @{text "(*, 1)"} or additive
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   182
  @{text "(+, 0)"} with underlying properties isomorphic.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   183
  In {Isabelle/HOL}, this is accomplished using the following
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   184
  abstract setup:
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   185
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   186
    \<^item> A @{locale semigroup} introduces an abstract binary
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   187
      associative operation.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   188
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   189
    \<^item> A @{locale monoid} is an extension of @{locale semigroup}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   190
      with a neutral element.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   191
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   192
    \<^item> Both @{locale semigroup} and @{locale monoid} provide
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   193
      dedicated syntax for their operations @{text "(\<^bold>*, \<^bold>1)"}.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   194
      This syntax is not visible on the global theory level
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   195
      but only for abstract reasoning inside the respective
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   196
      locale.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   197
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   198
    \<^item> Concrete global syntax is added building on existing
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   199
      syntactic type classes \secref{sec:syntactic-type-class}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   200
      using the following classes:
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   201
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   202
        \<^item> @{command class} @{class semigroup_mult} = @{class times}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   203
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   204
        \<^item> @{command class} @{class monoid_mult} = @{class one} + @{class semigroup_mult}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   205
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   206
        \<^item> @{command class} @{class semigroup_add} = @{class plus}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   207
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   208
        \<^item> @{command class} @{class monoid_add} = @{class zero} + @{class semigroup_add}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   209
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   210
      Locales @{locale semigroup} and @{locale monoid} are
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   211
      interpreted (using @{command sublocale}) into their
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   212
      corresponding type classes, with prefixes @{text add}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   213
      and @{text mult}; hence facts derived in @{locale semigroup}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   214
      and @{locale monoid} are propagated simultaneously to
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   215
      \<^emph>\<open>both\<close> using a consistent naming policy, ie.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   216
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   217
        \<^item> @{fact semigroup.assoc}: @{thm (frugal_sorts) semigroup.assoc [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   218
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   219
        \<^item> @{fact mult.assoc}: @{thm (frugal_sorts) mult.assoc [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   220
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   221
        \<^item> @{fact add.assoc}: @{thm (frugal_sorts) add.assoc [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   222
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   223
        \<^item> @{fact monoid.right_neutral}: @{thm (frugal_sorts) monoid.right_neutral [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   224
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   225
        \<^item> @{fact mult.right_neutral}: @{thm (frugal_sorts) mult.right_neutral [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   226
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   227
        \<^item> @{fact add.right_neutral}: @{thm (frugal_sorts) add.right_neutral [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   228
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   229
    \<^item> Note that the syntax in @{locale semigroup} and @{locale monoid}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   230
      is bold; this avoids clashes when writing properties
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   231
      inside one of these locales in presence of that global
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   232
      concrete type class syntax.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   233
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   234
  \noindent That hierarchy extends in a straightforward manner
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   235
  to abelian semigroups and commutative monoids\footnote{The
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   236
  designation \<^emph>\<open>abelian\<close> is quite standard concerning
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   237
  (semi)groups, but not for monoids}:
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   238
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   239
    \<^item> Locales @{locale abel_semigroup} and @{locale comm_monoid}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   240
      add commutativity as property.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   241
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   242
    \<^item> Concrete syntax emerges through
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   243
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   244
        \<^item> @{command class} @{class ab_semigroup_add} = @{class semigroup_add}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   245
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   246
        \<^item> @{command class} @{class ab_semigroup_mult} = @{class semigroup_mult}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   247
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   248
        \<^item> @{command class} @{class comm_monoid_add} = @{class zero} + @{class ab_semigroup_add}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   249
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   250
        \<^item> @{command class} @{class comm_monoid_mult} = @{class one} + @{class ab_semigroup_mult}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   251
  
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   252
      and corresponding interpretation of the locales above, yielding
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   253
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   254
        \<^item> @{fact abel_semigroup.commute}: @{thm (frugal_sorts) abel_semigroup.commute [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   255
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   256
        \<^item> @{fact mult.commute}: @{thm (frugal_sorts) mult.commute [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   257
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   258
        \<^item> @{fact add.commute}: @{thm (frugal_sorts) add.commute [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   259
\<close>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   260
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   261
paragraph \<open>Named collection of theorems\<close>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   262
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   263
text \<open>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   264
  Locale interpretation interacts smoothly with named collections of
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   265
  theorems as introduced by command @{command named_theorems}.  In our
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   266
  example, rules concerning associativity and commutativity are no
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   267
  simplification rules by default since they desired orientation may
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   268
  vary depending on the situation.  However, there is a collection
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   269
  @{fact ac_simps} where facts @{fact abel_semigroup.assoc},
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   270
  @{fact abel_semigroup.commute} and @{fact abel_semigroup.left_commute}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   271
  are declared as members.  Due to interpretation, also
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   272
  @{fact mult.assoc}, @{fact mult.commute} and @{fact mult.left_commute}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   273
  are also members of @{fact ac_simps}, as any corresponding facts
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   274
  stemming from interpretation of @{locale abel_semigroup}.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   275
  Hence adding @{fact ac_simps} to the simplification rules for
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   276
  a single method call uses all associativity and commutativity
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   277
  rules known by means of interpretation.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   278
\<close>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   279
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   280
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   281
subsection \<open>Additive and multiplicative groups\<close>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   282
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   283
text \<open>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   284
  The hierarchy for inverse group operations takes into account
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   285
  that there are weaker algebraic structures with only a partially
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   286
  inverse operation.  E. g. the natural numbers have bounded
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   287
  subtraction @{term "m - (n::nat)"} which is only an inverse
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   288
  operation if @{term "m \<ge> (n::nat)"};  unary minus @{text "-"}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   289
  is pointless on the natural numbers.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   290
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   291
  Hence for both additive and multiplicative notation there
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   292
  are syntactic classes for inverse operations, both unary
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   293
  and binary:
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   294
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   295
    \<^item> @{command class} @{class minus} with @{term [source] "(a::'a::minus) - b"}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   296
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   297
    \<^item> @{command class} @{class uminus} with @{term [source] "- a::'a::uminus"}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   298
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   299
    \<^item> @{command class} @{class divide} with @{term [source] "(a::'a::divide) div b"}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   300
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   301
    \<^item> @{command class} @{class inverse} = @{class divide} with @{term [source] "inverse a::'a::inverse"}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   302
        \\ and @{term [source] "(a::'a::inverse) / b"}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   303
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   304
  \noindent Here @{class inverse} specializes the ``partial'' syntax
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   305
  @{term [source] "a div b"} to the more specific
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   306
  @{term [source] "a / b"}. 
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   307
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   308
  Semantic properties are added by
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   309
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   310
    \<^item> @{command class} @{class cancel_ab_semigroup_add} = @{class ab_semigroup_add} + @{class minus}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   311
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   312
    \<^item> @{command class} @{class cancel_comm_monoid_add} = @{class cancel_ab_semigroup_add} + @{class comm_monoid_add}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   313
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   314
  \noindent which specify a minimal binary partially inverse operation as
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   315
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   316
    \<^item> @{fact add_diff_cancel_left'}: @{thm (frugal_sorts) add_diff_cancel_left' [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   317
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   318
    \<^item> @{fact diff_diff_add}: @{thm (frugal_sorts) diff_diff_add [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   319
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   320
  \noindent which in turn allow to derive facts like
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   321
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   322
    \<^item> @{fact add_left_imp_eq}: @{thm (frugal_sorts) add_left_imp_eq [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   323
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   324
  \noindent The total inverse operation is established as follows:
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   325
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   326
    \<^item> Locale @{locale group} extends the abstract hierarchy with
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   327
      the inverse operation.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   328
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   329
    \<^item> The concrete additive inverse operation emerges through
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   330
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   331
      \<^item> @{command class} @{class group_add} = @{class minus} + @{class uminus} + @{class monoid_add} (in @{theory Groups}) \\
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   332
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   333
      \<^item> @{command class} @{class ab_group_add} = @{class minus} + @{class uminus} + @{class comm_monoid_add} (in @{theory Groups})
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   334
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   335
      and corresponding interpretation of locale @{locale group}, yielding e.g.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   336
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   337
      \<^item> @{fact group.left_inverse}: @{thm (frugal_sorts) group.left_inverse [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   338
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   339
      \<^item> @{fact add.left_inverse}: @{thm (frugal_sorts) add.left_inverse [all, no_vars]}
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   340
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   341
  \noindent There is no multiplicative counterpart.  Why?  In rings,
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   342
  the multiplicative group excludes the zero element, hence
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   343
  the inverse operation is not total.  See further \secref{sec:rings}.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   344
\<close>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   345
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   346
paragraph \<open>Mitigating against redundancy by default simplification rules\<close>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   347
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   348
text \<open>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   349
  Inverse operations imposes some redundancy on the type class
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   350
  hierarchy: in a group with a total inverse operation, the
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   351
  unary operation is simpler and more primitive than the binary
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   352
  one; but we cannot eliminate the binary one in favour of
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   353
  a mere syntactic abbreviation since the binary one is vital
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   354
  to express a partial inverse operation.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   355
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   356
  This is mitigated by providing suitable default simplification
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   357
  rules: expression involving the unary inverse operation are
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   358
  simplified to binary inverse operation whenever appropriate.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   359
  The rationale is that simplification is a central device in
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   360
  explorative proving, where proof obligation remaining after certain
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   361
  default proof steps including simplification are inspected
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   362
  to get an idea what is missing to finish a proof.  When
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   363
  preferable normal forms are encoded into
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   364
  default simplification rules, proof obligations after simplification
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   365
  are normalized and hence more proof-friendly.
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   366
\<close>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
   367
63026
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
   368
end