src/Doc/Implementation/Isar.thy
author haftmann
Mon, 06 Feb 2017 20:56:34 +0100
changeset 64990 c6a7de505796
parent 62969 9f394a16c557
child 69597 ff784d5a5bfb
permissions -rw-r--r--
more explicit errors in pathological cases
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61656
cfabbc083977 more uniform jEdit properties;
wenzelm
parents: 61572
diff changeset
     1
(*:maxLineLen=78:*)
cfabbc083977 more uniform jEdit properties;
wenzelm
parents: 61572
diff changeset
     2
29755
d66b34e46bdf observe usual theory naming conventions;
wenzelm
parents: 20520
diff changeset
     3
theory Isar
d66b34e46bdf observe usual theory naming conventions;
wenzelm
parents: 20520
diff changeset
     4
imports Base
d66b34e46bdf observe usual theory naming conventions;
wenzelm
parents: 20520
diff changeset
     5
begin
20472
wenzelm
parents:
diff changeset
     6
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
     7
chapter \<open>Isar language elements\<close>
29759
bcb79ddf57da removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
     8
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
     9
text \<open>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    10
  The Isar proof language (see also @{cite \<open>\S2\<close> "isabelle-isar-ref"})
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    11
  consists of three main categories of language elements:
29759
bcb79ddf57da removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
    12
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    13
  \<^enum> Proof \<^emph>\<open>commands\<close> define the primary language of transactions of the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    14
  underlying Isar/VM interpreter. Typical examples are @{command "fix"},
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    15
  @{command "assume"}, @{command "show"}, @{command "proof"}, and @{command
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    16
  "qed"}.
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    17
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    18
  Composing proof commands according to the rules of the Isar/VM leads to
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    19
  expressions of structured proof text, such that both the machine and the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    20
  human reader can give it a meaning as formal reasoning.
20472
wenzelm
parents:
diff changeset
    21
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    22
  \<^enum> Proof \<^emph>\<open>methods\<close> define a secondary language of mixed forward-backward
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    23
  refinement steps involving facts and goals. Typical examples are @{method
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    24
  rule}, @{method unfold}, and @{method simp}.
29759
bcb79ddf57da removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
    25
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    26
  Methods can occur in certain well-defined parts of the Isar proof language,
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    27
  say as arguments to @{command "proof"}, @{command "qed"}, or @{command
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    28
  "by"}.
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    29
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    30
  \<^enum> \<^emph>\<open>Attributes\<close> define a tertiary language of small annotations to theorems
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    31
  being defined or referenced. Attributes can modify both the context and the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    32
  theorem.
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    33
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    34
  Typical examples are @{attribute intro} (which affects the context), and
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    35
  @{attribute symmetric} (which affects the theorem).
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    36
\<close>
29759
bcb79ddf57da removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
    37
bcb79ddf57da removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
    38
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    39
section \<open>Proof commands\<close>
20520
wenzelm
parents: 20472
diff changeset
    40
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    41
text \<open>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    42
  A \<^emph>\<open>proof command\<close> is state transition of the Isar/VM proof interpreter.
39849
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
    43
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    44
  In principle, Isar proof commands could be defined in user-space as well.
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    45
  The system is built like that in the first place: one part of the commands
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    46
  are primitive, the other part is defined as derived elements. Adding to the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    47
  genuine structured proof language requires profound understanding of the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    48
  Isar/VM machinery, though, so this is beyond the scope of this manual.
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    49
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    50
  What can be done realistically is to define some diagnostic commands that
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    51
  inspect the general state of the Isar/VM, and report some feedback to the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    52
  user. Typically this involves checking of the linguistic \<^emph>\<open>mode\<close> of a proof
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    53
  state, or peeking at the pending goals (if available).
39845
50f42116ebdb more on Proof.theorem;
wenzelm
parents: 39844
diff changeset
    54
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    55
  Another common application is to define a toplevel command that poses a
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    56
  problem to the user as Isar proof state and processes the final result
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    57
  relatively to the context. Thus a proof can be incorporated into the context
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    58
  of some user-space tool, without modifying the Isar proof language itself.
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    59
\<close>
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    60
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
    61
text %mlref \<open>
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    62
  \begin{mldecls}
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    63
  @{index_ML_type Proof.state} \\
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    64
  @{index_ML Proof.assert_forward: "Proof.state -> Proof.state"} \\
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    65
  @{index_ML Proof.assert_chain: "Proof.state -> Proof.state"} \\
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    66
  @{index_ML Proof.assert_backward: "Proof.state -> Proof.state"} \\
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    67
  @{index_ML Proof.simple_goal: "Proof.state -> {context: Proof.context, goal: thm}"} \\
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    68
  @{index_ML Proof.goal: "Proof.state ->
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    69
  {context: Proof.context, facts: thm list, goal: thm}"} \\
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    70
  @{index_ML Proof.raw_goal: "Proof.state ->
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    71
  {context: Proof.context, facts: thm list, goal: thm}"} \\
39845
50f42116ebdb more on Proof.theorem;
wenzelm
parents: 39844
diff changeset
    72
  @{index_ML Proof.theorem: "Method.text option ->
50f42116ebdb more on Proof.theorem;
wenzelm
parents: 39844
diff changeset
    73
  (thm list list -> Proof.context -> Proof.context) ->
50f42116ebdb more on Proof.theorem;
wenzelm
parents: 39844
diff changeset
    74
  (term * term list) list list -> Proof.context -> Proof.state"} \\
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    75
  \end{mldecls}
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    76
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    77
  \<^descr> Type @{ML_type Proof.state} represents Isar proof states. This is a
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    78
  block-structured configuration with proof context, linguistic mode, and
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    79
  optional goal. The latter consists of goal context, goal facts
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    80
  (``\<open>using\<close>''), and tactical goal state (see \secref{sec:tactical-goals}).
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    81
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    82
  The general idea is that the facts shall contribute to the refinement of
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    83
  some parts of the tactical goal --- how exactly is defined by the proof
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    84
  method that is applied in that situation.
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    85
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61416
diff changeset
    86
  \<^descr> @{ML Proof.assert_forward}, @{ML Proof.assert_chain}, @{ML
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    87
  Proof.assert_backward} are partial identity functions that fail unless a
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    88
  certain linguistic mode is active, namely ``\<open>proof(state)\<close>'',
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    89
  ``\<open>proof(chain)\<close>'', ``\<open>proof(prove)\<close>'', respectively (using the terminology
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    90
  of @{cite "isabelle-isar-ref"}).
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    91
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    92
  It is advisable study the implementations of existing proof commands for
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    93
  suitable modes to be asserted.
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    94
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    95
  \<^descr> @{ML Proof.simple_goal}~\<open>state\<close> returns the structured Isar goal (if
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    96
  available) in the form seen by ``simple'' methods (like @{method simp} or
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    97
  @{method blast}). The Isar goal facts are already inserted as premises into
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
    98
  the subgoals, which are presented individually as in @{ML Proof.goal}.
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
    99
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   100
  \<^descr> @{ML Proof.goal}~\<open>state\<close> returns the structured Isar goal (if available)
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   101
  in the form seen by regular methods (like @{method rule}). The auxiliary
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   102
  internal encoding of Pure conjunctions is split into individual subgoals as
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   103
  usual.
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
   104
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   105
  \<^descr> @{ML Proof.raw_goal}~\<open>state\<close> returns the structured Isar goal (if
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   106
  available) in the raw internal form seen by ``raw'' methods (like @{method
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   107
  induct}). This form is rarely appropriate for diagnostic tools; @{ML
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   108
  Proof.simple_goal} or @{ML Proof.goal} should be used in most situations.
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
   109
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   110
  \<^descr> @{ML Proof.theorem}~\<open>before_qed after_qed statement ctxt\<close> initializes a
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   111
  toplevel Isar proof state within a given context.
39845
50f42116ebdb more on Proof.theorem;
wenzelm
parents: 39844
diff changeset
   112
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   113
  The optional \<open>before_qed\<close> method is applied at the end of the proof, just
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   114
  before extracting the result (this feature is rarely used).
39845
50f42116ebdb more on Proof.theorem;
wenzelm
parents: 39844
diff changeset
   115
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   116
  The \<open>after_qed\<close> continuation receives the extracted result in order to apply
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   117
  it to the final context in a suitable way (e.g.\ storing named facts). Note
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   118
  that at this generic level the target context is specified as @{ML_type
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   119
  Proof.context}, but the usual wrapping of toplevel proofs into command
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   120
  transactions will provide a @{ML_type local_theory} here
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   121
  (\chref{ch:local-theory}). This affects the way how results are stored.
39845
50f42116ebdb more on Proof.theorem;
wenzelm
parents: 39844
diff changeset
   122
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   123
  The \<open>statement\<close> is given as a nested list of terms, each associated with
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   124
  optional @{keyword "is"} patterns as usual in the Isar source language. The
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   125
  original nested list structure over terms is turned into one over theorems
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   126
  when \<open>after_qed\<close> is invoked.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   127
\<close>
39842
7205191afde4 more on "Isar language elements";
wenzelm
parents: 30272
diff changeset
   128
20520
wenzelm
parents: 20472
diff changeset
   129
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   130
text %mlantiq \<open>
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   131
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   132
  @{ML_antiquotation_def "Isar.goal"} & : & \<open>ML_antiquotation\<close> \\
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   133
  \end{matharray}
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   134
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   135
  \<^descr> \<open>@{Isar.goal}\<close> refers to the regular goal state (if available) of the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   136
  current proof state managed by the Isar toplevel --- as abstract value.
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   137
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   138
  This only works for diagnostic ML commands, such as @{command ML_val} or
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   139
  @{command ML_command}.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   140
\<close>
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   141
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   142
text %mlex \<open>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   143
  The following example peeks at a certain goal configuration.
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   144
\<close>
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   145
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   146
notepad
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   147
begin
39846
cb6634eb8926 examples in Isabelle/HOL;
wenzelm
parents: 39845
diff changeset
   148
  have A and B and C
58728
42398b610f86 tuned spacing;
wenzelm
parents: 58618
diff changeset
   149
    ML_val
42398b610f86 tuned spacing;
wenzelm
parents: 58618
diff changeset
   150
     \<open>val n = Thm.nprems_of (#goal @{Isar.goal});
42398b610f86 tuned spacing;
wenzelm
parents: 58618
diff changeset
   151
      @{assert} (n = 3);\<close>
58801
f420225a22d6 'notepad' requires proper nesting of begin/end;
wenzelm
parents: 58728
diff changeset
   152
    sorry
f420225a22d6 'notepad' requires proper nesting of begin/end;
wenzelm
parents: 58728
diff changeset
   153
end
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   154
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   155
text \<open>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   156
  Here we see 3 individual subgoals in the same way as regular proof methods
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   157
  would do.
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   158
\<close>
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   159
20520
wenzelm
parents: 20472
diff changeset
   160
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   161
section \<open>Proof methods\<close>
20472
wenzelm
parents:
diff changeset
   162
61841
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   163
text \<open>
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   164
  A \<open>method\<close> is a function \<open>thm\<^sup>* \<rightarrow> context * goal \<rightarrow> (context \<times> goal)\<^sup>*\<^sup>*\<close>
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   165
  that operates on the full Isar goal configuration with context, goal facts,
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   166
  and tactical goal state and enumerates possible follow-up goal states. Under
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   167
  normal circumstances, the goal context remains unchanged, but it is also
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   168
  possible to declare named extensions of the proof context (\<^emph>\<open>cases\<close>).
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   169
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   170
  This means a proof method is like a structurally enhanced tactic (cf.\
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   171
  \secref{sec:tactics}). The well-formedness conditions for tactics need to
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   172
  hold for methods accordingly, with the following additions.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   173
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   174
  \<^item> Goal addressing is further limited either to operate uniformly on \<^emph>\<open>all\<close>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   175
  subgoals, or specifically on the \<^emph>\<open>first\<close> subgoal.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   176
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   177
  Exception: old-style tactic emulations that are embedded into the method
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   178
  space, e.g.\ @{method rule_tac}.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   179
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   180
  \<^item> A non-trivial method always needs to make progress: an identical follow-up
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   181
  goal state has to be avoided.\<^footnote>\<open>This enables the user to write method
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   182
  expressions like \<open>meth\<^sup>+\<close> without looping, while the trivial do-nothing case
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   183
  can be recovered via \<open>meth\<^sup>?\<close>.\<close>
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   184
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   185
  Exception: trivial stuttering steps, such as ``@{method -}'' or @{method
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   186
  succeed}.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   187
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   188
  \<^item> Goal facts passed to the method must not be ignored. If there is no
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   189
  sensible use of facts outside the goal state, facts should be inserted into
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   190
  the subgoals that are addressed by the method.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   191
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   192
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   193
  \<^medskip>
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   194
  Syntactically, the language of proof methods appears as arguments to Isar
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   195
  commands like @{command "by"} or @{command apply}. User-space additions are
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   196
  reasonably easy by plugging suitable method-valued parser functions into the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   197
  framework, using the @{command method_setup} command, for example.
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   198
39844
wenzelm
parents: 39843
diff changeset
   199
  To get a better idea about the range of possibilities, consider the
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   200
  following Isar proof schemes. This is the general form of structured proof
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   201
  text:
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   202
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   203
  \<^medskip>
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   204
  \begin{tabular}{l}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   205
  @{command from}~\<open>facts\<^sub>1\<close>~@{command have}~\<open>props\<close>~@{command using}~\<open>facts\<^sub>2\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   206
  @{command proof}~\<open>(initial_method)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   207
  \quad\<open>body\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   208
  @{command qed}~\<open>(terminal_method)\<close> \\
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   209
  \end{tabular}
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   210
  \<^medskip>
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   211
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   212
  The goal configuration consists of \<open>facts\<^sub>1\<close> and \<open>facts\<^sub>2\<close> appended in that
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   213
  order, and various \<open>props\<close> being claimed. The \<open>initial_method\<close> is invoked
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   214
  with facts and goals together and refines the problem to something that is
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   215
  handled recursively in the proof \<open>body\<close>. The \<open>terminal_method\<close> has another
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   216
  chance to finish any remaining subgoals, but it does not see the facts of
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   217
  the initial step.
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   218
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   219
  \<^medskip>
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   220
  This pattern illustrates unstructured proof scripts:
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   221
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   222
  \<^medskip>
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   223
  \begin{tabular}{l}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   224
  @{command have}~\<open>props\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   225
  \quad@{command using}~\<open>facts\<^sub>1\<close>~@{command apply}~\<open>method\<^sub>1\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   226
  \quad@{command apply}~\<open>method\<^sub>2\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   227
  \quad@{command using}~\<open>facts\<^sub>3\<close>~@{command apply}~\<open>method\<^sub>3\<close> \\
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   228
  \quad@{command done} \\
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   229
  \end{tabular}
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   230
  \<^medskip>
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   231
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   232
  The \<open>method\<^sub>1\<close> operates on the original claim while using \<open>facts\<^sub>1\<close>. Since
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   233
  the @{command apply} command structurally resets the facts, the \<open>method\<^sub>2\<close>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   234
  will operate on the remaining goal state without facts. The \<open>method\<^sub>3\<close> will
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   235
  see again a collection of \<open>facts\<^sub>3\<close> that has been inserted into the script
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   236
  explicitly.
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   237
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   238
  \<^medskip>
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   239
  Empirically, any Isar proof method can be categorized as follows.
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   240
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   241
    \<^enum> \<^emph>\<open>Special method with cases\<close> with named context additions associated
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   242
    with the follow-up goal state.
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   243
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   244
    Example: @{method "induct"}, which is also a ``raw'' method since it
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   245
    operates on the internal representation of simultaneous claims as Pure
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   246
    conjunction (\secref{sec:logic-aux}), instead of separate subgoals
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   247
    (\secref{sec:tactical-goals}).
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   248
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   249
    \<^enum> \<^emph>\<open>Structured method\<close> with strong emphasis on facts outside the goal
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   250
    state.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   251
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   252
    Example: @{method "rule"}, which captures the key ideas behind structured
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   253
    reasoning in Isar in its purest form.
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   254
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   255
    \<^enum> \<^emph>\<open>Simple method\<close> with weaker emphasis on facts, which are inserted into
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   256
    subgoals to emulate old-style tactical ``premises''.
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   257
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   258
    Examples: @{method "simp"}, @{method "blast"}, @{method "auto"}.
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   259
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   260
    \<^enum> \<^emph>\<open>Old-style tactic emulation\<close> with detailed numeric goal addressing and
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   261
    explicit references to entities of the internal goal state (which are
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   262
    otherwise invisible from proper Isar proof text). The naming convention
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   263
    \<open>foo_tac\<close> makes this special non-standard status clear.
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   264
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   265
    Example: @{method "rule_tac"}.
39843
21d189bfdfd1 more examples;
wenzelm
parents: 39842
diff changeset
   266
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   267
  When implementing proof methods, it is advisable to study existing
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   268
  implementations carefully and imitate the typical ``boiler plate'' for
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   269
  context-sensitive parsing and further combinators to wrap-up tactic
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   270
  expressions as methods.\<^footnote>\<open>Aliases or abbreviations of the standard method
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   271
  combinators should be avoided. Note that from Isabelle99 until Isabelle2009
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   272
  the system did provide various odd combinations of method syntax wrappers
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   273
  that made applications more complicated than necessary.\<close>
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   274
\<close>
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   275
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   276
text %mlref \<open>
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   277
  \begin{mldecls}
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   278
  @{index_ML_type Proof.method} \\
61841
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   279
  @{index_ML CONTEXT_METHOD: "(thm list -> context_tactic) -> Proof.method"} \\
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   280
  @{index_ML METHOD: "(thm list -> tactic) -> Proof.method"} \\
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   281
  @{index_ML SIMPLE_METHOD: "tactic -> Proof.method"} \\
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   282
  @{index_ML SIMPLE_METHOD': "(int -> tactic) -> Proof.method"} \\
61841
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   283
  @{index_ML Method.insert_tac: "Proof.context -> thm list -> int -> tactic"} \\
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   284
  @{index_ML Method.setup: "binding -> (Proof.context -> Proof.method) context_parser ->
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   285
  string -> theory -> theory"} \\
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   286
  \end{mldecls}
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   287
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   288
  \<^descr> Type @{ML_type Proof.method} represents proof methods as abstract type.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   289
61841
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   290
  \<^descr> @{ML CONTEXT_METHOD}~\<open>(fn facts => context_tactic)\<close> wraps \<open>context_tactic\<close>
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   291
  depending on goal facts as a general proof method that may change the proof
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   292
  context dynamically. A typical operation is @{ML
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   293
  Proof_Context.update_cases}, which is wrapped up as combinator @{index_ML
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   294
  CONTEXT_CASES} for convenience.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   295
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   296
  \<^descr> @{ML METHOD}~\<open>(fn facts => tactic)\<close> wraps \<open>tactic\<close> depending on goal facts
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   297
  as regular proof method; the goal context is passed via method syntax.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   298
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   299
  \<^descr> @{ML SIMPLE_METHOD}~\<open>tactic\<close> wraps a tactic that addresses all subgoals
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   300
  uniformly as simple proof method. Goal facts are already inserted into all
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   301
  subgoals before \<open>tactic\<close> is applied.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   302
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   303
  \<^descr> @{ML SIMPLE_METHOD'}~\<open>tactic\<close> wraps a tactic that addresses a specific
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   304
  subgoal as simple proof method that operates on subgoal 1. Goal facts are
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   305
  inserted into the subgoal then the \<open>tactic\<close> is applied.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   306
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   307
  \<^descr> @{ML Method.insert_tac}~\<open>ctxt facts i\<close> inserts \<open>facts\<close> into subgoal \<open>i\<close>.
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   308
  This is convenient to reproduce part of the @{ML SIMPLE_METHOD} or @{ML
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   309
  SIMPLE_METHOD'} wrapping within regular @{ML METHOD}, for example.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   310
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   311
  \<^descr> @{ML Method.setup}~\<open>name parser description\<close> provides the functionality of
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   312
  the Isar command @{command method_setup} as ML function.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   313
\<close>
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   314
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   315
text %mlex \<open>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   316
  See also @{command method_setup} in @{cite "isabelle-isar-ref"} which
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   317
  includes some abstract examples.
39851
7219a771ab63 more examples;
wenzelm
parents: 39849
diff changeset
   318
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   319
  \<^medskip>
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   320
  The following toy examples illustrate how the goal facts and state are
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   321
  passed to proof methods. The predefined proof method called ``@{method
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   322
  tactic}'' wraps ML source of type @{ML_type tactic} (abstracted over
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   323
  @{ML_text facts}). This allows immediate experimentation without parsing of
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   324
  concrete syntax.
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   325
\<close>
20472
wenzelm
parents:
diff changeset
   326
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   327
notepad
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   328
begin
57340
wenzelm
parents: 56579
diff changeset
   329
  fix A B :: bool
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   330
  assume a: A and b: B
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   331
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   332
  have "A \<and> B"
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 59498
diff changeset
   333
    apply (tactic \<open>resolve_tac @{context} @{thms conjI} 1\<close>)
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 58801
diff changeset
   334
    using a apply (tactic \<open>resolve_tac @{context} facts 1\<close>)
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 58801
diff changeset
   335
    using b apply (tactic \<open>resolve_tac @{context} facts 1\<close>)
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   336
    done
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   337
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   338
  have "A \<and> B"
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   339
    using a and b
57340
wenzelm
parents: 56579
diff changeset
   340
    ML_val \<open>@{Isar.goal}\<close>
61841
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 61656
diff changeset
   341
    apply (tactic \<open>Method.insert_tac @{context} facts 1\<close>)
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 59498
diff changeset
   342
    apply (tactic \<open>(resolve_tac @{context} @{thms conjI} THEN_ALL_NEW assume_tac @{context}) 1\<close>)
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   343
    done
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   344
end
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   345
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   346
text \<open>
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   347
  \<^medskip>
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   348
  The next example implements a method that simplifies the first subgoal by
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   349
  rewrite rules that are given as arguments.
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   350
\<close>
39848
fc88b943e1b2 misc tuning and clarification;
wenzelm
parents: 39847
diff changeset
   351
57340
wenzelm
parents: 56579
diff changeset
   352
method_setup my_simp =
wenzelm
parents: 56579
diff changeset
   353
  \<open>Attrib.thms >> (fn thms => fn ctxt =>
39848
fc88b943e1b2 misc tuning and clarification;
wenzelm
parents: 39847
diff changeset
   354
    SIMPLE_METHOD' (fn i =>
fc88b943e1b2 misc tuning and clarification;
wenzelm
parents: 39847
diff changeset
   355
      CHANGED (asm_full_simp_tac
57340
wenzelm
parents: 56579
diff changeset
   356
        (put_simpset HOL_basic_ss ctxt addsimps thms) i)))\<close>
wenzelm
parents: 56579
diff changeset
   357
  "rewrite subgoal by given rules"
39848
fc88b943e1b2 misc tuning and clarification;
wenzelm
parents: 39847
diff changeset
   358
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   359
text \<open>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   360
  The concrete syntax wrapping of @{command method_setup} always
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   361
  passes-through the proof context at the end of parsing, but it is not used
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   362
  in this example.
39848
fc88b943e1b2 misc tuning and clarification;
wenzelm
parents: 39847
diff changeset
   363
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   364
  The @{ML Attrib.thms} parser produces a list of theorems from the usual Isar
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   365
  syntax involving attribute expressions etc.\ (syntax category @{syntax
62969
9f394a16c557 eliminated "xname" and variants;
wenzelm
parents: 61854
diff changeset
   366
  thms}) @{cite "isabelle-isar-ref"}. The resulting @{ML_text thms} are
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   367
  added to @{ML HOL_basic_ss} which already contains the basic Simplifier
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   368
  setup for HOL.
39848
fc88b943e1b2 misc tuning and clarification;
wenzelm
parents: 39847
diff changeset
   369
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   370
  The tactic @{ML asm_full_simp_tac} is the one that is also used in method
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   371
  @{method simp} by default. The extra wrapping by the @{ML CHANGED} tactical
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   372
  ensures progress of simplification: identical goal states are filtered out
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   373
  explicitly to make the raw tactic conform to standard Isar method behaviour.
39848
fc88b943e1b2 misc tuning and clarification;
wenzelm
parents: 39847
diff changeset
   374
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   375
  \<^medskip>
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   376
  Method @{method my_simp} can be used in Isar proofs like this:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   377
\<close>
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   378
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   379
notepad
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   380
begin
57340
wenzelm
parents: 56579
diff changeset
   381
  fix a b c :: 'a
39851
7219a771ab63 more examples;
wenzelm
parents: 39849
diff changeset
   382
  assume a: "a = b"
7219a771ab63 more examples;
wenzelm
parents: 39849
diff changeset
   383
  assume b: "b = c"
7219a771ab63 more examples;
wenzelm
parents: 39849
diff changeset
   384
  have "a = c" by (my_simp a b)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   385
end
39851
7219a771ab63 more examples;
wenzelm
parents: 39849
diff changeset
   386
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   387
text \<open>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   388
  Here is a similar method that operates on all subgoals, instead of just the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   389
  first one.\<close>
39851
7219a771ab63 more examples;
wenzelm
parents: 39849
diff changeset
   390
57340
wenzelm
parents: 56579
diff changeset
   391
method_setup my_simp_all =
wenzelm
parents: 56579
diff changeset
   392
  \<open>Attrib.thms >> (fn thms => fn ctxt =>
39851
7219a771ab63 more examples;
wenzelm
parents: 39849
diff changeset
   393
    SIMPLE_METHOD
7219a771ab63 more examples;
wenzelm
parents: 39849
diff changeset
   394
      (CHANGED
7219a771ab63 more examples;
wenzelm
parents: 39849
diff changeset
   395
        (ALLGOALS (asm_full_simp_tac
57340
wenzelm
parents: 56579
diff changeset
   396
          (put_simpset HOL_basic_ss ctxt addsimps thms)))))\<close>
wenzelm
parents: 56579
diff changeset
   397
  "rewrite all subgoals by given rules"
39851
7219a771ab63 more examples;
wenzelm
parents: 39849
diff changeset
   398
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   399
notepad
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   400
begin
57340
wenzelm
parents: 56579
diff changeset
   401
  fix a b c :: 'a
39851
7219a771ab63 more examples;
wenzelm
parents: 39849
diff changeset
   402
  assume a: "a = b"
7219a771ab63 more examples;
wenzelm
parents: 39849
diff changeset
   403
  assume b: "b = c"
7219a771ab63 more examples;
wenzelm
parents: 39849
diff changeset
   404
  have "a = c" and "c = b" by (my_simp_all a b)
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   405
end
39848
fc88b943e1b2 misc tuning and clarification;
wenzelm
parents: 39847
diff changeset
   406
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   407
text \<open>
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   408
  \<^medskip>
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   409
  Apart from explicit arguments, common proof methods typically work with a
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   410
  default configuration provided by the context. As a shortcut to rule
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   411
  management we use a cheap solution via the @{command named_theorems} command
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   412
  to declare a dynamic fact in the context.
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   413
\<close>
39848
fc88b943e1b2 misc tuning and clarification;
wenzelm
parents: 39847
diff changeset
   414
57946
6a26aa5fa65e updated documentation concerning 'named_theorems';
wenzelm
parents: 57342
diff changeset
   415
named_theorems my_simp
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   416
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   417
text \<open>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   418
  The proof method is now defined as before, but we append the explicit
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   419
  arguments and the rules from the context.
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   420
\<close>
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   421
57340
wenzelm
parents: 56579
diff changeset
   422
method_setup my_simp' =
wenzelm
parents: 56579
diff changeset
   423
  \<open>Attrib.thms >> (fn thms => fn ctxt =>
57946
6a26aa5fa65e updated documentation concerning 'named_theorems';
wenzelm
parents: 57342
diff changeset
   424
    let
6a26aa5fa65e updated documentation concerning 'named_theorems';
wenzelm
parents: 57342
diff changeset
   425
      val my_simps = Named_Theorems.get ctxt @{named_theorems my_simp}
6a26aa5fa65e updated documentation concerning 'named_theorems';
wenzelm
parents: 57342
diff changeset
   426
    in
6a26aa5fa65e updated documentation concerning 'named_theorems';
wenzelm
parents: 57342
diff changeset
   427
      SIMPLE_METHOD' (fn i =>
6a26aa5fa65e updated documentation concerning 'named_theorems';
wenzelm
parents: 57342
diff changeset
   428
        CHANGED (asm_full_simp_tac
6a26aa5fa65e updated documentation concerning 'named_theorems';
wenzelm
parents: 57342
diff changeset
   429
          (put_simpset HOL_basic_ss ctxt
6a26aa5fa65e updated documentation concerning 'named_theorems';
wenzelm
parents: 57342
diff changeset
   430
            addsimps (thms @ my_simps)) i))
6a26aa5fa65e updated documentation concerning 'named_theorems';
wenzelm
parents: 57342
diff changeset
   431
    end)\<close>
57340
wenzelm
parents: 56579
diff changeset
   432
  "rewrite subgoal by given rules and my_simp rules from the context"
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   433
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   434
text \<open>
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   435
  \<^medskip>
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   436
  Method @{method my_simp'} can be used in Isar proofs like this:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   437
\<close>
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   438
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   439
notepad
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   440
begin
57342
wenzelm
parents: 57340
diff changeset
   441
  fix a b c :: 'a
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   442
  assume [my_simp]: "a \<equiv> b"
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   443
  assume [my_simp]: "b \<equiv> c"
39848
fc88b943e1b2 misc tuning and clarification;
wenzelm
parents: 39847
diff changeset
   444
  have "a \<equiv> c" by my_simp'
40964
482a8334ee9e prefer 'notepad' over 'example_proof';
wenzelm
parents: 40800
diff changeset
   445
end
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   446
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   447
text \<open>
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   448
  \<^medskip>
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   449
  The @{method my_simp} variants defined above are ``simple'' methods, i.e.\
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   450
  the goal facts are merely inserted as goal premises by the @{ML
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   451
  SIMPLE_METHOD'} or @{ML SIMPLE_METHOD} wrapper. For proof methods that are
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   452
  similar to the standard collection of @{method simp}, @{method blast},
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   453
  @{method fast}, @{method auto} there is little more that can be done.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   454
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   455
  Note that using the primary goal facts in the same manner as the method
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   456
  arguments obtained via concrete syntax or the context does not meet the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   457
  requirement of ``strong emphasis on facts'' of regular proof methods,
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   458
  because rewrite rules as used above can be easily ignored. A proof text
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   459
  ``@{command using}~\<open>foo\<close>~@{command "by"}~\<open>my_simp\<close>'' where \<open>foo\<close> is not used
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   460
  would deceive the reader.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   461
61416
b9a3324e4e62 more symbols;
wenzelm
parents: 60754
diff changeset
   462
  \<^medskip>
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   463
  The technical treatment of rules from the context requires further
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   464
  attention. Above we rebuild a fresh @{ML_type simpset} from the arguments
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   465
  and \<^emph>\<open>all\<close> rules retrieved from the context on every invocation of the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   466
  method. This does not scale to really large collections of rules, which
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   467
  easily emerges in the context of a big theory library, for example.
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   468
39848
fc88b943e1b2 misc tuning and clarification;
wenzelm
parents: 39847
diff changeset
   469
  This is an inherent limitation of the simplistic rule management via
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   470
  @{command named_theorems}, because it lacks tool-specific storage and
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   471
  retrieval. More realistic applications require efficient index-structures
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   472
  that organize theorems in a customized manner, such as a discrimination net
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   473
  that is indexed by the left-hand sides of rewrite rules. For variations on
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   474
  the Simplifier, re-use of the existing type @{ML_type simpset} is adequate,
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   475
  but scalability would require it be maintained statically within the context
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   476
  data, not dynamically on each tool invocation.
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   477
\<close>
39847
da8c3fc5e314 more on "Proof methods";
wenzelm
parents: 39846
diff changeset
   478
29759
bcb79ddf57da removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
   479
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   480
section \<open>Attributes \label{sec:attributes}\<close>
20472
wenzelm
parents:
diff changeset
   481
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   482
text \<open>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   483
  An \<^emph>\<open>attribute\<close> is a function \<open>context \<times> thm \<rightarrow> context \<times> thm\<close>, which means
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   484
  both a (generic) context and a theorem can be modified simultaneously. In
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   485
  practice this mixed form is very rare, instead attributes are presented
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   486
  either as \<^emph>\<open>declaration attribute:\<close> \<open>thm \<rightarrow> context \<rightarrow> context\<close> or \<^emph>\<open>rule
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   487
  attribute:\<close> \<open>context \<rightarrow> thm \<rightarrow> thm\<close>.
39849
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   488
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   489
  Attributes can have additional arguments via concrete syntax. There is a
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   490
  collection of context-sensitive parsers for various logical entities (types,
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   491
  terms, theorems). These already take care of applying morphisms to the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   492
  arguments when attribute expressions are moved into a different context (see
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   493
  also \secref{sec:morphisms}).
39849
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   494
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   495
  When implementing declaration attributes, it is important to operate exactly
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   496
  on the variant of the generic context that is provided by the system, which
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   497
  is either global theory context or local proof context. In particular, the
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   498
  background theory of a local context must not be modified in this
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   499
  situation!
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   500
\<close>
39849
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   501
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   502
text %mlref \<open>
39849
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   503
  \begin{mldecls}
45414
8ca612982014 updated functor Named_Thms;
wenzelm
parents: 40964
diff changeset
   504
  @{index_ML_type attribute} \\
61853
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   505
  @{index_ML Thm.rule_attribute: "thm list ->
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   506
  (Context.generic -> thm -> thm) -> attribute"} \\
39849
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   507
  @{index_ML Thm.declaration_attribute: "
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   508
  (thm -> Context.generic -> Context.generic) -> attribute"} \\
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   509
  @{index_ML Attrib.setup: "binding -> attribute context_parser ->
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   510
  string -> theory -> theory"} \\
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   511
  \end{mldecls}
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   512
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   513
  \<^descr> Type @{ML_type attribute} represents attributes as concrete type alias.
39849
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   514
61853
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   515
  \<^descr> @{ML Thm.rule_attribute}~\<open>thms (fn context => rule)\<close> wraps a
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   516
  context-dependent rule (mapping on @{ML_type thm}) as attribute.
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   517
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   518
  The \<open>thms\<close> are additional parameters: when forming an abstract closure, the
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   519
  system may provide dummy facts that are propagated according to strict
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   520
  evaluation discipline. In that case, \<open>rule\<close> is bypassed.
39849
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   521
61853
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   522
  \<^descr> @{ML Thm.declaration_attribute}~\<open>(fn thm => decl)\<close> wraps a
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   523
  theorem-dependent declaration (mapping on @{ML_type Context.generic}) as
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   524
  attribute.
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   525
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   526
  When forming an abstract closure, the system may provide a dummy fact as
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61841
diff changeset
   527
  \<open>thm\<close>. In that case, \<open>decl\<close> is bypassed.
39849
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   528
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   529
  \<^descr> @{ML Attrib.setup}~\<open>name parser description\<close> provides the functionality of
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   530
  the Isar command @{command attribute_setup} as ML function.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   531
\<close>
39849
b7b1a9e8f7c2 more on "Attributes";
wenzelm
parents: 39848
diff changeset
   532
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   533
text %mlantiq \<open>
45592
8baa0b7f3f66 added ML antiquotation @{attributes};
wenzelm
parents: 45414
diff changeset
   534
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   535
  @{ML_antiquotation_def attributes} & : & \<open>ML_antiquotation\<close> \\
45592
8baa0b7f3f66 added ML antiquotation @{attributes};
wenzelm
parents: 45414
diff changeset
   536
  \end{matharray}
8baa0b7f3f66 added ML antiquotation @{attributes};
wenzelm
parents: 45414
diff changeset
   537
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 51717
diff changeset
   538
  @{rail \<open>
45592
8baa0b7f3f66 added ML antiquotation @{attributes};
wenzelm
parents: 45414
diff changeset
   539
  @@{ML_antiquotation attributes} attributes
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 51717
diff changeset
   540
  \<close>}
45592
8baa0b7f3f66 added ML antiquotation @{attributes};
wenzelm
parents: 45414
diff changeset
   541
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   542
  \<^descr> \<open>@{attributes [\<dots>]}\<close> embeds attribute source representation into the ML
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   543
  text, which is particularly useful with declarations like @{ML
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   544
  Local_Theory.note}. Attribute names are internalized at compile time, but
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   545
  the source is unevaluated. This means attributes with formal arguments
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   546
  (types, terms, theorems) may be subject to odd effects of dynamic scoping!
58618
782f0b662cae more cartouches;
wenzelm
parents: 58555
diff changeset
   547
\<close>
45592
8baa0b7f3f66 added ML antiquotation @{attributes};
wenzelm
parents: 45414
diff changeset
   548
61854
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   549
text %mlex \<open>
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   550
  See also @{command attribute_setup} in @{cite "isabelle-isar-ref"} which
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   551
  includes some abstract examples.
38b049cd3aad tuned whitespace;
wenzelm
parents: 61853
diff changeset
   552
\<close>
30272
2d612824e642 regenerated document;
wenzelm
parents: 30270
diff changeset
   553
20472
wenzelm
parents:
diff changeset
   554
end