src/Doc/Isar_Ref/Proof_Script.thy
author wenzelm
Sat, 19 Dec 2015 15:20:38 +0100
changeset 61866 6fa60a4f7e48
parent 61657 5b878bc6ae98
child 62269 c56cff1c0e73
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61656
cfabbc083977 more uniform jEdit properties;
wenzelm
parents: 61503
diff changeset
     1
(*:maxLineLen=78:*)
cfabbc083977 more uniform jEdit properties;
wenzelm
parents: 61503
diff changeset
     2
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
     3
theory Proof_Script
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
     4
imports Base Main
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
     5
begin
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
     6
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
     7
chapter \<open>Proof scripts\<close>
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
     8
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
     9
text \<open>
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    10
  Interactive theorem proving is traditionally associated with ``proof
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61458
diff changeset
    11
  scripts'', but Isabelle/Isar is centered around structured \<^emph>\<open>proof
e467ae7aa808 more control symbols;
wenzelm
parents: 61458
diff changeset
    12
  documents\<close> instead (see also \chref{ch:proofs}).
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    13
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    14
  Nonetheless, it is possible to emulate proof scripts by sequential
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    15
  refinements of a proof state in backwards mode, notably with the @{command
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    16
  apply} command (see \secref{sec:tactic-commands}). There are also various
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    17
  proof methods that allow to refer to implicit goal state information that is
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    18
  normally not accessible to structured Isar proofs (see
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    19
  \secref{sec:tactics}).
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    20
\<close>
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    21
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    22
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    23
section \<open>Commands for step-wise refinement \label{sec:tactic-commands}\<close>
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    24
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    25
text \<open>
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    26
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    27
    @{command_def "supply"}\<open>\<^sup>*\<close> & : & \<open>proof(prove) \<rightarrow> proof(prove)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    28
    @{command_def "apply"}\<open>\<^sup>*\<close> & : & \<open>proof(prove) \<rightarrow> proof(prove)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    29
    @{command_def "apply_end"}\<open>\<^sup>*\<close> & : & \<open>proof(state) \<rightarrow> proof(state)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    30
    @{command_def "done"}\<open>\<^sup>*\<close> & : & \<open>proof(prove) \<rightarrow> proof(state) | local_theory | theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    31
    @{command_def "defer"}\<open>\<^sup>*\<close> & : & \<open>proof \<rightarrow> proof\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    32
    @{command_def "prefer"}\<open>\<^sup>*\<close> & : & \<open>proof \<rightarrow> proof\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    33
    @{command_def "back"}\<open>\<^sup>*\<close> & : & \<open>proof \<rightarrow> proof\<close> \\
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    34
  \end{matharray}
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    35
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    36
  @{rail \<open>
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    37
    @@{command supply} (@{syntax thmdef}? @{syntax thmrefs} + @'and')
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    38
    ;
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    39
    ( @@{command apply} | @@{command apply_end} ) @{syntax method}
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    40
    ;
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    41
    @@{command defer} @{syntax nat}?
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    42
    ;
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    43
    @@{command prefer} @{syntax nat}
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    44
  \<close>}
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    45
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    46
  \<^descr> @{command "supply"} supports fact definitions during goal refinement: it
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    47
  is similar to @{command "note"}, but it operates in backwards mode and does
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    48
  not have any impact on chained facts.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    49
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    50
  \<^descr> @{command "apply"}~\<open>m\<close> applies proof method \<open>m\<close> in initial position, but
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    51
  unlike @{command "proof"} it retains ``\<open>proof(prove)\<close>'' mode. Thus
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    52
  consecutive method applications may be given just as in tactic scripts.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    53
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    54
  Facts are passed to \<open>m\<close> as indicated by the goal's forward-chain mode, and
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    55
  are \<^emph>\<open>consumed\<close> afterwards. Thus any further @{command "apply"} command
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    56
  would always work in a purely backward manner.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    57
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    58
  \<^descr> @{command "apply_end"}~\<open>m\<close> applies proof method \<open>m\<close> as if in terminal
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    59
  position. Basically, this simulates a multi-step tactic script for @{command
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    60
  "qed"}, but may be given anywhere within the proof body.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    61
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    62
  No facts are passed to \<open>m\<close> here. Furthermore, the static context is that of
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    63
  the enclosing goal (as for actual @{command "qed"}). Thus the proof method
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    64
  may not refer to any assumptions introduced in the current body, for
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    65
  example.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    66
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    67
  \<^descr> @{command "done"} completes a proof script, provided that the current goal
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    68
  state is solved completely. Note that actual structured proof commands
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    69
  (e.g.\ ``@{command "."}'' or @{command "sorry"}) may be used to conclude
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    70
  proof scripts as well.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    71
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    72
  \<^descr> @{command "defer"}~\<open>n\<close> and @{command "prefer"}~\<open>n\<close> shuffle the list of
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    73
  pending goals: @{command "defer"} puts off sub-goal \<open>n\<close> to the end of the
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    74
  list (\<open>n = 1\<close> by default), while @{command "prefer"} brings sub-goal \<open>n\<close> to
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    75
  the front.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    76
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    77
  \<^descr> @{command "back"} does back-tracking over the result sequence of the
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    78
  latest proof command. Any proof command may return multiple results, and
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    79
  this command explores the possibilities step-by-step. It is mainly useful
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    80
  for experimentation and interactive exploration, and should be avoided in
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
    81
  finished proofs.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    82
\<close>
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    83
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
    84
60631
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    85
section \<open>Explicit subgoal structure\<close>
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    86
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    87
text \<open>
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    88
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    89
    @{command_def "subgoal"}\<open>\<^sup>*\<close> & : & \<open>proof \<rightarrow> proof\<close> \\
60631
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    90
  \end{matharray}
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    91
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    92
  @{rail \<open>
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    93
    @@{command subgoal} @{syntax thmbind}? prems? params?
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    94
    ;
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    95
    prems: @'premises' @{syntax thmbind}?
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    96
    ;
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    97
    params: @'for' '\<dots>'? (('_' | @{syntax name})+)
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    98
  \<close>}
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
    99
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 60631
diff changeset
   100
  \<^descr> @{command "subgoal"} allows to impose some structure on backward
60631
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   101
  refinements, to avoid proof scripts degenerating into long of @{command
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   102
  apply} sequences.
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   103
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   104
  The current goal state, which is essentially a hidden part of the Isar/VM
61866
wenzelm
parents: 61657
diff changeset
   105
  configuration, is turned into a proof context and remaining conclusion.
wenzelm
parents: 61657
diff changeset
   106
  This corresponds to @{command fix}~/ @{command assume}~/ @{command show} in
60631
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   107
  structured proofs, but the text of the parameters, premises and conclusion
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   108
  is not given explicitly.
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   109
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   110
  Goal parameters may be specified separately, in order to allow referring to
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   111
  them in the proof body: ``@{command subgoal}~@{keyword "for"}~\<open>x y z\<close>''
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   112
  names a \<^emph>\<open>prefix\<close>, and ``@{command subgoal}~@{keyword "for"}~\<open>\<dots> x y z\<close>''
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   113
  names a \<^emph>\<open>suffix\<close> of goal parameters. The latter uses a literal \<^verbatim>\<open>\<dots>\<close> symbol
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   114
  as notation. Parameter positions may be skipped via dummies (underscore).
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   115
  Unspecified names remain internal, and thus inaccessible in the proof text.
60631
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   116
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   117
  ``@{command subgoal}~@{keyword "premises"}~\<open>prems\<close>'' indicates that goal
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   118
  premises should be turned into assumptions of the context (otherwise the
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   119
  remaining conclusion is a Pure implication). The fact name and attributes
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   120
  are optional; the particular name ``\<open>prems\<close>'' is a common convention for the
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   121
  premises of an arbitrary goal context in proof scripts.
60631
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   122
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   123
  ``@{command subgoal}~\<open>result\<close>'' indicates a fact name for the result of a
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   124
  proven subgoal. Thus it may be re-used in further reasoning, similar to the
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   125
  result of @{command show} in structured Isar proofs.
60631
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   126
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   127
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   128
  Here are some abstract examples:
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   129
\<close>
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   130
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   131
lemma "\<And>x y z. A x \<Longrightarrow> B y \<Longrightarrow> C z"
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   132
  and "\<And>u v. X u \<Longrightarrow> Y v"
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   133
  subgoal sorry
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   134
  subgoal sorry
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   135
  done
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   136
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   137
lemma "\<And>x y z. A x \<Longrightarrow> B y \<Longrightarrow> C z"
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   138
  and "\<And>u v. X u \<Longrightarrow> Y v"
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   139
  subgoal for x y z sorry
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   140
  subgoal for u v sorry
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   141
  done
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   142
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   143
lemma "\<And>x y z. A x \<Longrightarrow> B y \<Longrightarrow> C z"
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   144
  and "\<And>u v. X u \<Longrightarrow> Y v"
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   145
  subgoal premises for x y z
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   146
    using \<open>A x\<close> \<open>B y\<close>
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   147
    sorry
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   148
  subgoal premises for u v
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   149
    using \<open>X u\<close>
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   150
    sorry
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   151
  done
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   152
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   153
lemma "\<And>x y z. A x \<Longrightarrow> B y \<Longrightarrow> C z"
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   154
  and "\<And>u v. X u \<Longrightarrow> Y v"
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   155
  subgoal r premises prems for x y z
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   156
  proof -
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   157
    have "A x" by (fact prems)
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   158
    moreover have "B y" by (fact prems)
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   159
    ultimately show ?thesis sorry
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   160
  qed
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   161
  subgoal premises prems for u v
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   162
  proof -
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   163
    have "\<And>x y z. A x \<Longrightarrow> B y \<Longrightarrow> C z" by (fact r)
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   164
    moreover
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   165
    have "X u" by (fact prems)
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   166
    ultimately show ?thesis sorry
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   167
  qed
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   168
  done
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   169
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   170
lemma "\<And>x y z. A x \<Longrightarrow> B y \<Longrightarrow> C z"
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   171
  subgoal premises prems for \<dots> z
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   172
  proof -
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   173
    from prems show "C z" sorry
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   174
  qed
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   175
  done
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   176
441fdbfbb2d3 documentation for 'subgoal' command;
wenzelm
parents: 60484
diff changeset
   177
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   178
section \<open>Tactics: improper proof methods \label{sec:tactics}\<close>
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   179
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   180
text \<open>
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   181
  The following improper proof methods emulate traditional tactics. These
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   182
  admit direct access to the goal state, which is normally considered harmful!
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   183
  In particular, this may involve both numbered goal addressing (default 1),
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   184
  and dynamic instantiation within the scope of some subgoal.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   185
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   186
  \begin{warn}
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   187
    Dynamic instantiations refer to universally quantified parameters of a
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   188
    subgoal (the dynamic context) rather than fixed variables and term
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   189
    abbreviations of a (static) Isar context.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   190
  \end{warn}
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   191
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   192
  Tactic emulation methods, unlike their ML counterparts, admit simultaneous
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   193
  instantiation from both dynamic and static contexts. If names occur in both
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   194
  contexts goal parameters hide locally fixed variables. Likewise, schematic
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   195
  variables refer to term abbreviations, if present in the static context.
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   196
  Otherwise the schematic variable is interpreted as a schematic variable and
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   197
  left to be solved by unification with certain parts of the subgoal.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   198
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   199
  Note that the tactic emulation proof methods in Isabelle/Isar are
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   200
  consistently named \<open>foo_tac\<close>. Note also that variable names occurring on
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   201
  left hand sides of instantiations must be preceded by a question mark if
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   202
  they coincide with a keyword or contain dots. This is consistent with the
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   203
  attribute @{attribute "where"} (see \secref{sec:pure-meth-att}).
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   204
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   205
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   206
    @{method_def rule_tac}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   207
    @{method_def erule_tac}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   208
    @{method_def drule_tac}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   209
    @{method_def frule_tac}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   210
    @{method_def cut_tac}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   211
    @{method_def thin_tac}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   212
    @{method_def subgoal_tac}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   213
    @{method_def rename_tac}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   214
    @{method_def rotate_tac}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   215
    @{method_def tactic}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   216
    @{method_def raw_tactic}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   217
  \end{matharray}
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   218
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   219
  @{rail \<open>
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   220
    (@@{method rule_tac} | @@{method erule_tac} | @@{method drule_tac} |
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   221
      @@{method frule_tac} | @@{method cut_tac}) @{syntax goal_spec}? \<newline>
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   222
    (@{syntax named_insts} @{syntax for_fixes} @'in' @{syntax thmref} | @{syntax thmrefs} )
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   223
    ;
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   224
    @@{method thin_tac} @{syntax goal_spec}? @{syntax prop} @{syntax for_fixes}
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   225
    ;
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   226
    @@{method subgoal_tac} @{syntax goal_spec}? (@{syntax prop} +) @{syntax for_fixes}
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   227
    ;
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   228
    @@{method rename_tac} @{syntax goal_spec}? (@{syntax name} +)
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   229
    ;
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   230
    @@{method rotate_tac} @{syntax goal_spec}? @{syntax int}?
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   231
    ;
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   232
    (@@{method tactic} | @@{method raw_tactic}) @{syntax text}
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   233
  \<close>}
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   234
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 60631
diff changeset
   235
  \<^descr> @{method rule_tac} etc. do resolution of rules with explicit
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   236
  instantiation. This works the same way as the ML tactics @{ML
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   237
  Rule_Insts.res_inst_tac} etc.\ (see @{cite "isabelle-implementation"}).
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   238
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   239
  Multiple rules may be only given if there is no instantiation; then @{method
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   240
  rule_tac} is the same as @{ML resolve_tac} in ML (see @{cite
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   241
  "isabelle-implementation"}).
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   242
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   243
  \<^descr> @{method cut_tac} inserts facts into the proof state as assumption of a
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   244
  subgoal; instantiations may be given as well. Note that the scope of
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   245
  schematic variables is spread over the main goal statement and rule premises
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   246
  are turned into new subgoals. This is in contrast to the regular method
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   247
  @{method insert} which inserts closed rule statements.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   248
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   249
  \<^descr> @{method thin_tac}~\<open>\<phi>\<close> deletes the specified premise from a subgoal. Note
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   250
  that \<open>\<phi>\<close> may contain schematic variables, to abbreviate the intended
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   251
  proposition; the first matching subgoal premise will be deleted. Removing
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   252
  useless premises from a subgoal increases its readability and can make
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   253
  search tactics run faster.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   254
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   255
  \<^descr> @{method subgoal_tac}~\<open>\<phi>\<^sub>1 \<dots> \<phi>\<^sub>n\<close> adds the propositions \<open>\<phi>\<^sub>1 \<dots> \<phi>\<^sub>n\<close> as
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   256
  local premises to a subgoal, and poses the same as new subgoals (in the
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   257
  original context).
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   258
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   259
  \<^descr> @{method rename_tac}~\<open>x\<^sub>1 \<dots> x\<^sub>n\<close> renames parameters of a goal according to
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   260
  the list \<open>x\<^sub>1, \<dots>, x\<^sub>n\<close>, which refers to the \<^emph>\<open>suffix\<close> of variables.
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   261
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   262
  \<^descr> @{method rotate_tac}~\<open>n\<close> rotates the premises of a subgoal by \<open>n\<close>
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   263
  positions: from right to left if \<open>n\<close> is positive, and from left to right if
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   264
  \<open>n\<close> is negative; the default value is 1.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   265
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   266
  \<^descr> @{method tactic}~\<open>text\<close> produces a proof method from any ML text of type
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   267
  @{ML_type tactic}. Apart from the usual ML environment and the current proof
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   268
  context, the ML code may refer to the locally bound values @{ML_text facts},
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   269
  which indicates any current facts used for forward-chaining.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   270
61657
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   271
  \<^descr> @{method raw_tactic} is similar to @{method tactic}, but presents the goal
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   272
  state in its raw internal form, where simultaneous subgoals appear as
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   273
  conjunction of the logical framework instead of the usual split into several
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   274
  subgoals. While feature this is useful for debugging of complex method
5b878bc6ae98 tuned whitespace;
wenzelm
parents: 61656
diff changeset
   275
  definitions, it should not never appear in production theories.
60484
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   276
\<close>
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   277
98ee86354354 moved sections;
wenzelm
parents:
diff changeset
   278
end