src/Doc/Implementation/Eq.thy
author wenzelm
Mon, 25 Mar 2019 17:21:26 +0100
changeset 69981 3dced198b9ec
parent 69597 ff784d5a5bfb
child 73592 c642c3cbbf0e
permissions -rw-r--r--
more strict AFP properties;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61656
cfabbc083977 more uniform jEdit properties;
wenzelm
parents: 61493
diff changeset
     1
(*:maxLineLen=78:*)
cfabbc083977 more uniform jEdit properties;
wenzelm
parents: 61493
diff changeset
     2
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
     3
theory Eq
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
     4
imports Base
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
     5
begin
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
     6
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
     7
chapter \<open>Equational reasoning\<close>
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
     8
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
     9
text \<open>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    10
  Equality is one of the most fundamental concepts of mathematics. The
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    11
  Isabelle/Pure logic (\chref{ch:logic}) provides a builtin relation \<open>\<equiv> :: \<alpha> \<Rightarrow>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    12
  \<alpha> \<Rightarrow> prop\<close> that expresses equality of arbitrary terms (or propositions) at
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    13
  the framework level, as expressed by certain basic inference rules
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    14
  (\secref{sec:eq-rules}).
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    15
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    16
  Equational reasoning means to replace equals by equals, using reflexivity
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    17
  and transitivity to form chains of replacement steps, and congruence rules
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    18
  to access sub-structures. Conversions (\secref{sec:conv}) provide a
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    19
  convenient framework to compose basic equational steps to build specific
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    20
  equational reasoning tools.
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    21
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    22
  Higher-order matching is able to provide suitable instantiations for giving
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    23
  equality rules, which leads to the versatile concept of \<open>\<lambda>\<close>-term rewriting
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    24
  (\secref{sec:rewriting}). Internally this is based on the general-purpose
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    25
  Simplifier engine of Isabelle, which is more specific and more efficient
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    26
  than plain conversions.
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    27
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    28
  Object-logics usually introduce specific notions of equality or equivalence,
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    29
  and relate it with the Pure equality. This enables to re-use the Pure tools
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    30
  for equational reasoning for particular object-logic connectives as well.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    31
\<close>
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    32
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    33
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    34
section \<open>Basic equality rules \label{sec:eq-rules}\<close>
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    35
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    36
text \<open>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    37
  Isabelle/Pure uses \<open>\<equiv>\<close> for equality of arbitrary terms, which includes
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    38
  equivalence of propositions of the logical framework. The conceptual
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    39
  axiomatization of the constant \<open>\<equiv> :: \<alpha> \<Rightarrow> \<alpha> \<Rightarrow> prop\<close> is given in
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    40
  \figref{fig:pure-equality}. The inference kernel presents slightly different
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    41
  equality rules, which may be understood as derived rules from this minimal
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    42
  axiomatization. The Pure theory also provides some theorems that express the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    43
  same reasoning schemes as theorems that can be composed like object-level
50085
24ef81a22ee9 updated basic equality rules;
wenzelm
parents: 48985
diff changeset
    44
  rules as explained in \secref{sec:obj-rules}.
24ef81a22ee9 updated basic equality rules;
wenzelm
parents: 48985
diff changeset
    45
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 63680
diff changeset
    46
  For example, \<^ML>\<open>Thm.symmetric\<close> as Pure inference is an ML function that
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    47
  maps a theorem \<open>th\<close> stating \<open>t \<equiv> u\<close> to one stating \<open>u \<equiv> t\<close>. In contrast,
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    48
  @{thm [source] Pure.symmetric} as Pure theorem expresses the same reasoning
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    49
  in declarative form. If used like \<open>th [THEN Pure.symmetric]\<close> in Isar source
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    50
  notation, it achieves a similar effect as the ML inference function,
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 63680
diff changeset
    51
  although the rule attribute @{attribute THEN} or ML operator \<^ML>\<open>op RS\<close>
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    52
  involve the full machinery of higher-order unification (modulo
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    53
  \<open>\<beta>\<eta>\<close>-conversion) and lifting of \<open>\<And>/\<Longrightarrow>\<close> contexts.
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    54
\<close>
50085
24ef81a22ee9 updated basic equality rules;
wenzelm
parents: 48985
diff changeset
    55
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    56
text %mlref \<open>
50085
24ef81a22ee9 updated basic equality rules;
wenzelm
parents: 48985
diff changeset
    57
  \begin{mldecls}
24ef81a22ee9 updated basic equality rules;
wenzelm
parents: 48985
diff changeset
    58
  @{index_ML Thm.reflexive: "cterm -> thm"} \\
24ef81a22ee9 updated basic equality rules;
wenzelm
parents: 48985
diff changeset
    59
  @{index_ML Thm.symmetric: "thm -> thm"} \\
24ef81a22ee9 updated basic equality rules;
wenzelm
parents: 48985
diff changeset
    60
  @{index_ML Thm.transitive: "thm -> thm -> thm"} \\
24ef81a22ee9 updated basic equality rules;
wenzelm
parents: 48985
diff changeset
    61
  @{index_ML Thm.abstract_rule: "string -> cterm -> thm -> thm"} \\
24ef81a22ee9 updated basic equality rules;
wenzelm
parents: 48985
diff changeset
    62
  @{index_ML Thm.combination: "thm -> thm -> thm"} \\[0.5ex]
24ef81a22ee9 updated basic equality rules;
wenzelm
parents: 48985
diff changeset
    63
  @{index_ML Thm.equal_intr: "thm -> thm -> thm"} \\
24ef81a22ee9 updated basic equality rules;
wenzelm
parents: 48985
diff changeset
    64
  @{index_ML Thm.equal_elim: "thm -> thm -> thm"} \\
24ef81a22ee9 updated basic equality rules;
wenzelm
parents: 48985
diff changeset
    65
  \end{mldecls}
24ef81a22ee9 updated basic equality rules;
wenzelm
parents: 48985
diff changeset
    66
63680
6e1e8b5abbfa more symbols;
wenzelm
parents: 61854
diff changeset
    67
  See also \<^file>\<open>~~/src/Pure/thm.ML\<close> for further description of these inference
6e1e8b5abbfa more symbols;
wenzelm
parents: 61854
diff changeset
    68
  rules, and a few more for primitive \<open>\<beta>\<close> and \<open>\<eta>\<close> conversions. Note that \<open>\<alpha>\<close>
6e1e8b5abbfa more symbols;
wenzelm
parents: 61854
diff changeset
    69
  conversion is implicit due to the representation of terms with de-Bruijn
6e1e8b5abbfa more symbols;
wenzelm
parents: 61854
diff changeset
    70
  indices (\secref{sec:terms}).
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    71
\<close>
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    72
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    73
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    74
section \<open>Conversions \label{sec:conv}\<close>
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    75
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    76
text \<open>
52422
wenzelm
parents: 50122
diff changeset
    77
  %FIXME
50122
7ae7efef5ad8 more refs;
wenzelm
parents: 50085
diff changeset
    78
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    79
  The classic article that introduces the concept of conversion (for Cambridge
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    80
  LCF) is @{cite "paulson:1983"}.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    81
\<close>
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    82
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    83
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    84
section \<open>Rewriting \label{sec:rewriting}\<close>
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    85
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    86
text \<open>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    87
  Rewriting normalizes a given term (theorem or goal) by replacing instances
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    88
  of given equalities \<open>t \<equiv> u\<close> in subterms. Rewriting continues until no
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    89
  rewrites are applicable to any subterm. This may be used to unfold simple
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    90
  definitions of the form \<open>f x\<^sub>1 \<dots> x\<^sub>n \<equiv> u\<close>, but is slightly more general than
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
    91
  that. \<close>
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    92
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    93
text %mlref \<open>
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
    94
  \begin{mldecls}
54742
7a86358a3c0b proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents: 53982
diff changeset
    95
  @{index_ML rewrite_rule: "Proof.context -> thm list -> thm -> thm"} \\
7a86358a3c0b proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents: 53982
diff changeset
    96
  @{index_ML rewrite_goals_rule: "Proof.context -> thm list -> thm -> thm"} \\
7a86358a3c0b proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents: 53982
diff changeset
    97
  @{index_ML rewrite_goal_tac: "Proof.context -> thm list -> int -> tactic"} \\
7a86358a3c0b proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents: 53982
diff changeset
    98
  @{index_ML rewrite_goals_tac: "Proof.context -> thm list -> tactic"} \\
7a86358a3c0b proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents: 53982
diff changeset
    99
  @{index_ML fold_goals_tac: "Proof.context -> thm list -> tactic"} \\
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
   100
  \end{mldecls}
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
   101
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 63680
diff changeset
   102
  \<^descr> \<^ML>\<open>rewrite_rule\<close>~\<open>ctxt rules thm\<close> rewrites the whole theorem by the
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
   103
  given rules.
46486
4a607979290d updated rewrite_goals_rule, rewrite_rule;
wenzelm
parents: 46295
diff changeset
   104
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 63680
diff changeset
   105
  \<^descr> \<^ML>\<open>rewrite_goals_rule\<close>~\<open>ctxt rules thm\<close> rewrites the outer premises of
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
   106
  the given theorem. Interpreting the same as a goal state
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
   107
  (\secref{sec:tactical-goals}) it means to rewrite all subgoals (in the same
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 63680
diff changeset
   108
  manner as \<^ML>\<open>rewrite_goals_tac\<close>).
46486
4a607979290d updated rewrite_goals_rule, rewrite_rule;
wenzelm
parents: 46295
diff changeset
   109
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 63680
diff changeset
   110
  \<^descr> \<^ML>\<open>rewrite_goal_tac\<close>~\<open>ctxt rules i\<close> rewrites subgoal \<open>i\<close> by the given
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
   111
  rewrite rules.
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
   112
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 63680
diff changeset
   113
  \<^descr> \<^ML>\<open>rewrite_goals_tac\<close>~\<open>ctxt rules\<close> rewrites all subgoals by the given
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
   114
  rewrite rules.
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
   115
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 63680
diff changeset
   116
  \<^descr> \<^ML>\<open>fold_goals_tac\<close>~\<open>ctxt rules\<close> essentially uses \<^ML>\<open>rewrite_goals_tac\<close>
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
   117
  with the symmetric form of each member of \<open>rules\<close>, re-ordered to fold longer
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
   118
  expression first. This supports to idea to fold primitive definitions that
38b049cd3aad tuned whitespace;
wenzelm
parents: 61656
diff changeset
   119
  appear in expended form in the proof state.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   120
\<close>
46295
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
   121
2548a85b0e02 basic setup for equational reasoning;
wenzelm
parents:
diff changeset
   122
end