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