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