doc-src/IsarImplementation/Thy/proof.thy
author wenzelm
Mon, 04 Sep 2006 17:06:45 +0200
changeset 20472 e993073eda4c
parent 20470 c839b38a1f32
child 20474 af069653f1d7
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     1
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     2
(* $Id$ *)
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     3
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     4
theory "proof" imports base begin
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     5
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20218
diff changeset
     6
chapter {* Structured proofs *}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     7
20460
wenzelm
parents: 20459
diff changeset
     8
section {* Variables *}
20026
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
     9
20470
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    10
text {*
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    11
  Any variable that is not explicitly bound by @{text "\<lambda>"}-abstraction
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    12
  is considered as ``free''.  Logically, free variables act like
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    13
  outermost universal quantification (at the sequent level): @{text
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    14
  "A\<^isub>1(x), \<dots>, A\<^isub>n(x) \<turnstile> B(x)"} means that the result
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    15
  holds \emph{for all} values of @{text "x"}.  Free variables for
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    16
  terms (not types) can be fully internalized into the logic: @{text
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    17
  "\<turnstile> B(x)"} and @{text "\<turnstile> \<And>x. B(x)"} are interchangeable provided that
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    18
  @{text "x"} does not occur elsewhere in the context.  Inspecting
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    19
  @{text "\<turnstile> \<And>x. B(x)"} more closely, we see that inside the
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    20
  quantifier, @{text "x"} is essentially ``arbitrary, but fixed'',
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    21
  while from outside it appears as a place-holder for instantiation
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    22
  (thanks to @{text "\<And>"}-elimination).
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    23
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    24
  The Pure logic represents the notion of variables being either
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    25
  inside or outside the current scope by providing separate syntactic
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    26
  categories for \emph{fixed variables} (e.g.\ @{text "x"}) vs.\
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    27
  \emph{schematic variables} (e.g.\ @{text "?x"}).  Incidently, a
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    28
  universal result @{text "\<turnstile> \<And>x. B(x)"} has the canonical form @{text
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    29
  "\<turnstile> B(?x)"}, which represents its generality nicely without requiring
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    30
  an explicit quantifier.  The same principle works for type variables
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    31
  as well: @{text "\<turnstile> B(?\<alpha>)"} expresses the idea of ``@{text "\<turnstile>
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    32
  \<forall>\<alpha>. B(\<alpha>)"}'' without demanding a truly polymorphic framework.
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    33
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    34
  \medskip Additional care is required to treat type variables in a
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    35
  way that facilitates type-inference.  In principle, term variables
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    36
  depend on type variables, which means that type variables would have
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    37
  to be declared first.  For example, a raw type-theoretic framework
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    38
  would demand the context to be constructed in stages as follows:
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    39
  @{text "\<Gamma> = \<alpha>: type, x: \<alpha>, a: A(x\<^isub>\<alpha>)"}.
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    40
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    41
  We allow a slightly less formalistic mode of operation: term
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    42
  variables @{text "x"} are fixed without specifying a type yet
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    43
  (essentially \emph{all} potential occurrences of some instance
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    44
  @{text "x\<^isub>\<tau>"} will be fixed); the first occurrence of @{text
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    45
  "x"} within a specific term assigns its most general type, which is
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    46
  then maintained consistently in the context.  The above example
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    47
  becomes @{text "\<Gamma> = x: term, \<alpha>: type, A(x\<^isub>\<alpha>)"}, where type
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    48
  @{text "\<alpha>"} is fixed \emph{after} term @{text "x"}, and the
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    49
  constraint @{text "x: \<alpha>"} is an implicit consequence of the
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    50
  occurrence of @{text "x\<^isub>\<alpha>"} in the subsequent proposition.
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    51
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    52
  This twist of dependencies is also accommodated by the reverse
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    53
  operation of exporting results from a context: a type variable
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    54
  @{text "\<alpha>"} is considered fixed as long as it occurs in some fixed
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    55
  term variable of the context.  For example, exporting @{text "x:
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    56
  term, \<alpha>: type \<turnstile> x\<^isub>\<alpha> = x\<^isub>\<alpha>"} produces @{text "x: term \<turnstile>
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    57
  x\<^isub>\<alpha> = x\<^isub>\<alpha>"} for fixed @{text "\<alpha>"} in the first step,
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    58
  and @{text "\<turnstile> ?x\<^isub>?\<^isub>\<alpha> = ?x\<^isub>?\<^isub>\<alpha>"} for
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    59
  schematic @{text "?x"} and @{text "?\<alpha>"} only in the second step.
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    60
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    61
  \medskip The Isabelle/Isar proof context manages the gory details of
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    62
  term vs.\ type variables, with high-level principles for moving the
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    63
  frontier between fixed and schematic variables.  By observing a
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    64
  simple discipline of fixing variables and declaring terms
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    65
  explicitly, the fine points are treated by the @{text "export"}
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    66
  operation.
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    67
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    68
  There is also a separate @{text "import"} operation makes a
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    69
  generalized fact a genuine part of the context, by inventing fixed
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    70
  variables for the schematic ones.  The effect can be reversed by
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    71
  using @{text "export"} later, with a potentially extended context,
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    72
  but the result will be only equivalent modulo renaming of schematic
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    73
  variables.
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    74
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    75
  The @{text "focus"} operation provides a variant of @{text "import"}
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    76
  for nested propositions (with explicit quantification): @{text
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    77
  "\<And>x. B(x)"} is decomposed by inventing a fixed variable @{text "x"}
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    78
  and for the body @{text "B(x)"}.
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    79
*}
20064
wenzelm
parents: 20041
diff changeset
    80
20026
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
    81
text %mlref {*
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
    82
  \begin{mldecls}
20470
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    83
  @{index_ML Variable.add_fixes: "string list -> Proof.context -> string list * Proof.context"} \\
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    84
  @{index_ML Variable.invent_fixes: "string list -> Proof.context -> string list * Proof.context"} \\
20026
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
    85
  @{index_ML Variable.declare_term: "term -> Proof.context -> Proof.context"} \\
20470
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    86
  @{index_ML Variable.declare_constraints: "term -> Proof.context -> Proof.context"} \\
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    87
  @{index_ML Variable.export: "Proof.context -> Proof.context -> thm list -> thm list"} \\
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    88
  @{index_ML Variable.polymorphic: "Proof.context -> term list -> term list"} \\
20459
wenzelm
parents: 20458
diff changeset
    89
  @{index_ML Variable.import: "bool ->
wenzelm
parents: 20458
diff changeset
    90
  thm list -> Proof.context -> ((ctyp list * cterm list) * thm list) * Proof.context"} \\
20470
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    91
  @{index_ML Variable.focus: "cterm -> Proof.context -> (cterm list * cterm) * Proof.context"} \\
20026
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
    92
  \end{mldecls}
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
    93
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
    94
  \begin{description}
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
    95
20064
wenzelm
parents: 20041
diff changeset
    96
  \item @{ML Variable.add_fixes}~@{text "xs ctxt"} fixes term
20470
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    97
  variables @{text "xs"}, returning the resulting internal names.  By
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    98
  default, the internal representation coincides with the external
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
    99
  one, which also means that the given variables must not have been
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   100
  fixed already.  Within a local proof body, the given names are just
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   101
  hints for newly invented Skolem variables.
20064
wenzelm
parents: 20041
diff changeset
   102
wenzelm
parents: 20041
diff changeset
   103
  \item @{ML Variable.invent_fixes} is similar to @{ML
20470
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   104
  Variable.add_fixes}, but always produces fresh variants of the given
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   105
  hints.
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   106
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   107
  \item @{ML Variable.declare_term}~@{text "t ctxt"} declares term
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   108
  @{text "t"} to belong to the context.  This automatically fixes new
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   109
  type variables, but not term variables.  Syntactic constraints for
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   110
  type and term variables are declared uniformly.
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   111
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   112
  \item @{ML Variable.declare_constraints}~@{text "t ctxt"} derives
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   113
  type-inference information from term @{text "t"}, without making it
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   114
  part of the context yet.
20026
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
   115
20470
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   116
  \item @{ML Variable.export}~@{text "inner outer thms"} generalizes
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   117
  fixed type and term variables in @{text "thms"} according to the
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   118
  difference of the @{text "inner"} and @{text "outer"} context,
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   119
  following the principles sketched above.
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   120
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   121
  \item @{ML Variable.polymorphic}~@{text "ctxt ts"} generalizes type
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   122
  variables in @{text "ts"} as far as possible, even those occurring
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   123
  in fixed term variables.  The default policy of type-inference is to
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   124
  fix newly introduced type variables; this is essentially reversed
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   125
  with @{ML Variable.polymorphic}, the given terms are detached from
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   126
  the context as far as possible.
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   127
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   128
  \item @{ML Variable.import}~@{text "open thms ctxt"} augments the
20064
wenzelm
parents: 20041
diff changeset
   129
  context by new fixes for the schematic type and term variables
20470
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   130
  occurring in @{text "thms"}.  The @{text "open"} flag indicates
20064
wenzelm
parents: 20041
diff changeset
   131
  whether the fixed names should be accessible to the user, otherwise
wenzelm
parents: 20041
diff changeset
   132
  internal names are chosen.
20026
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
   133
20470
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   134
  @{ML Variable.export} essentially reverses the effect of @{ML
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   135
  Variable.import}, modulo renaming of schematic variables.
20064
wenzelm
parents: 20041
diff changeset
   136
20470
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   137
  \item @{ML Variable.focus}~@{text "\<And>x\<^isub>1 \<dots>
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   138
  x\<^isub>n. B(x\<^isub>1, \<dots>, x\<^isub>n)"} invents fixed variables
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   139
  for @{text "x\<^isub>1, \<dots>, x\<^isub>n"} and replaces these in the
c839b38a1f32 more on variables;
wenzelm
parents: 20460
diff changeset
   140
  body.
20026
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
   141
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
   142
  \end{description}
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
   143
*}
3469df62fe21 Local variables;
wenzelm
parents: 18537
diff changeset
   144
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   145
text FIXME
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   146
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20218
diff changeset
   147
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20218
diff changeset
   148
section {* Assumptions *}
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20218
diff changeset
   149
20458
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   150
text {*
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   151
  An \emph{assumption} is a proposition that it is postulated in the
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   152
  current context.  Local conclusions may use assumptions as
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   153
  additional facts, but this imposes implicit hypotheses that weaken
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   154
  the overall statement.
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   155
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   156
  Assumptions are restricted to fixed non-schematic statements, all
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   157
  generality needs to be expressed by explicit quantifiers.
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   158
  Nevertheless, the result will be in HHF normal form with outermost
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   159
  quantifiers stripped.  For example, by assuming @{text "\<And>x :: \<alpha>. P
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   160
  x"} we get @{text "\<And>x :: \<alpha>. P x \<turnstile> P ?x"} for arbitrary @{text "?x"}
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   161
  of the fixed type @{text "\<alpha>"}.  Local derivations accumulate more
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   162
  and more explicit references to hypotheses: @{text "A\<^isub>1, \<dots>,
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   163
  A\<^isub>n \<turnstile> B"} where @{text "A\<^isub>1, \<dots>, A\<^isub>n"} needs to
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   164
  be covered by the assumptions of the current context.
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   165
20459
wenzelm
parents: 20458
diff changeset
   166
  \medskip The @{text "add_assms"} operation augments the context by
wenzelm
parents: 20458
diff changeset
   167
  local assumptions, which are parameterized by an arbitrary @{text
wenzelm
parents: 20458
diff changeset
   168
  "export"} rule (see below).
20458
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   169
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   170
  The @{text "export"} operation moves facts from a (larger) inner
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   171
  context into a (smaller) outer context, by discharging the
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   172
  difference of the assumptions as specified by the associated export
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   173
  rules.  Note that the discharged portion is determined by the
20459
wenzelm
parents: 20458
diff changeset
   174
  difference contexts, not the facts being exported!  There is a
wenzelm
parents: 20458
diff changeset
   175
  separate flag to indicate a goal context, where the result is meant
wenzelm
parents: 20458
diff changeset
   176
  to refine an enclosing sub-goal of a structured proof state (cf.\
wenzelm
parents: 20458
diff changeset
   177
  \secref{sec:isar-proof-state}).
20458
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   178
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   179
  \medskip The most basic export rule discharges assumptions directly
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   180
  by means of the @{text "\<Longrightarrow>"} introduction rule:
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   181
  \[
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   182
  \infer[(@{text "\<Longrightarrow>_intro"})]{@{text "\<Gamma> \\ A \<turnstile> A \<Longrightarrow> B"}}{@{text "\<Gamma> \<turnstile> B"}}
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   183
  \]
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   184
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   185
  The variant for goal refinements marks the newly introduced
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   186
  premises, which causes the builtin goal refinement scheme of Isar to
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   187
  enforce unification with local premises within the goal:
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   188
  \[
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   189
  \infer[(@{text "#\<Longrightarrow>_intro"})]{@{text "\<Gamma> \\ A \<turnstile> #A \<Longrightarrow> B"}}{@{text "\<Gamma> \<turnstile> B"}}
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   190
  \]
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   191
20459
wenzelm
parents: 20458
diff changeset
   192
  \medskip Alternative assumptions may perform arbitrary
wenzelm
parents: 20458
diff changeset
   193
  transformations on export, as long as a particular portion of
wenzelm
parents: 20458
diff changeset
   194
  hypotheses is removed from the given facts.  For example, a local
wenzelm
parents: 20458
diff changeset
   195
  definition works by fixing @{text "x"} and assuming @{text "x \<equiv> t"},
wenzelm
parents: 20458
diff changeset
   196
  with the following export rule to reverse the effect:
20458
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   197
  \[
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   198
  \infer{@{text "\<Gamma> \\ x \<equiv> t \<turnstile> B t"}}{@{text "\<Gamma> \<turnstile> B x"}}
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   199
  \]
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   200
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   201
  \medskip The general concept supports block-structured reasoning
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   202
  nicely, with arbitrary mechanisms for introducing local assumptions.
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   203
  The common reasoning pattern is as follows:
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   204
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   205
  \medskip
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   206
  \begin{tabular}{l}
20459
wenzelm
parents: 20458
diff changeset
   207
  @{text "add_assms e\<^isub>1 A\<^isub>1"} \\
20458
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   208
  @{text "\<dots>"} \\
20459
wenzelm
parents: 20458
diff changeset
   209
  @{text "add_assms e\<^isub>n A\<^isub>n"} \\
20458
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   210
  @{text "export"} \\
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   211
  \end{tabular}
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   212
  \medskip
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   213
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   214
  \noindent The final @{text "export"} will turn any fact @{text
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   215
  "A\<^isub>1, \<dots>, A\<^isub>n \<turnstile> B"} into some @{text "\<turnstile> B'"}, by
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   216
  applying the export rules @{text "e\<^isub>1, \<dots>, e\<^isub>n"}
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   217
  inside-out.
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   218
*}
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   219
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   220
text %mlref {*
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   221
  \begin{mldecls}
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   222
  @{index_ML_type Assumption.export} \\
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   223
  @{index_ML Assumption.assume: "cterm -> thm"} \\
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   224
  @{index_ML Assumption.add_assms:
20459
wenzelm
parents: 20458
diff changeset
   225
    "Assumption.export ->
wenzelm
parents: 20458
diff changeset
   226
  cterm list -> Proof.context -> thm list * Proof.context"} \\
wenzelm
parents: 20458
diff changeset
   227
  @{index_ML Assumption.add_assumes: "
wenzelm
parents: 20458
diff changeset
   228
  cterm list -> Proof.context -> thm list * Proof.context"} \\
20458
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   229
  @{index_ML Assumption.export: "bool -> Proof.context -> Proof.context -> thm -> thm"} \\
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   230
  \end{mldecls}
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   231
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   232
  \begin{description}
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   233
20459
wenzelm
parents: 20458
diff changeset
   234
  \item @{ML_type Assumption.export} represents arbitrary export
wenzelm
parents: 20458
diff changeset
   235
  rules, which is any function of type @{ML_type "bool -> cterm list -> thm -> thm"},
wenzelm
parents: 20458
diff changeset
   236
  where the @{ML_type "bool"} indicates goal mode, and the @{ML_type
wenzelm
parents: 20458
diff changeset
   237
  "cterm list"} the collection of assumptions to be discharged
wenzelm
parents: 20458
diff changeset
   238
  simultaneously.
20458
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   239
20459
wenzelm
parents: 20458
diff changeset
   240
  \item @{ML Assumption.assume}~@{text "A"} turns proposition @{text
wenzelm
parents: 20458
diff changeset
   241
  "A"} into a raw assumption @{text "A \<turnstile> A'"}, where the conclusion
wenzelm
parents: 20458
diff changeset
   242
  @{text "A'"} is in HHF normal form.
20458
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   243
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   244
  \item @{ML Assumption.add_assms}~@{text "e As"} augments the context
20459
wenzelm
parents: 20458
diff changeset
   245
  by assumptions @{text "As"} with export rule @{text "e"}.  The
wenzelm
parents: 20458
diff changeset
   246
  resulting facts are hypothetical theorems as produced by @{ML
wenzelm
parents: 20458
diff changeset
   247
  Assumption.assume}.
wenzelm
parents: 20458
diff changeset
   248
wenzelm
parents: 20458
diff changeset
   249
  \item @{ML Assumption.add_assumes}~@{text "As"} is a special case of
wenzelm
parents: 20458
diff changeset
   250
  @{ML Assumption.add_assms} where the export rule performs @{text
wenzelm
parents: 20458
diff changeset
   251
  "\<Longrightarrow>_intro"} or @{text "#\<Longrightarrow>_intro"}, depending on goal mode.
20458
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   252
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   253
  \item @{ML Assumption.export}~@{text "is_goal inner outer th"}
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   254
  exports result @{text "th"} from the the @{text "inner"} context
20459
wenzelm
parents: 20458
diff changeset
   255
  back into the @{text "outer"} one; @{text "is_goal = true"} means
wenzelm
parents: 20458
diff changeset
   256
  this is a goal context.  The result is in HHF normal form.  Note
wenzelm
parents: 20458
diff changeset
   257
  that @{ML "ProofContext.export"} combines @{ML "Variable.export"}
wenzelm
parents: 20458
diff changeset
   258
  and @{ML "Assumption.export"} in the canonical way.
20458
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   259
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   260
  \end{description}
ab1d60e1ee31 explain assumptions;
wenzelm
parents: 20452
diff changeset
   261
*}
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20218
diff changeset
   262
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20218
diff changeset
   263
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20218
diff changeset
   264
section {* Conclusions *}
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20218
diff changeset
   265
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   266
text {*
20472
wenzelm
parents: 20470
diff changeset
   267
  Local results are established by monotonic reasoning from facts
wenzelm
parents: 20470
diff changeset
   268
  within a context.  This admits arbitrary combination of theorems,
wenzelm
parents: 20470
diff changeset
   269
  e.g.\ using @{text "\<And>/\<Longrightarrow>"} elimination, resolution rules, or
wenzelm
parents: 20470
diff changeset
   270
  equational reasoning.  Unaccounted context manipulations should be
wenzelm
parents: 20470
diff changeset
   271
  ruled out, such as raw @{text "\<And>/\<Longrightarrow>"} introduction or ad-hoc
wenzelm
parents: 20470
diff changeset
   272
  references to free variables or assumptions not present in the proof
wenzelm
parents: 20470
diff changeset
   273
  context.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   274
20472
wenzelm
parents: 20470
diff changeset
   275
  \medskip The @{text "prove"} operation provides a separate interface
wenzelm
parents: 20470
diff changeset
   276
  for structured backwards reasoning under program control, with some
wenzelm
parents: 20470
diff changeset
   277
  explicit sanity checks of the result.  The goal context can be
wenzelm
parents: 20470
diff changeset
   278
  augmented locally by given fixed variables and assumptions, which
wenzelm
parents: 20470
diff changeset
   279
  will be available as local facts during the proof and discharged
wenzelm
parents: 20470
diff changeset
   280
  into implications in the result.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   281
20472
wenzelm
parents: 20470
diff changeset
   282
  The @{text "prove_multi"} operation handles several simultaneous
wenzelm
parents: 20470
diff changeset
   283
  claims within a single goal statement, by using meta-level
wenzelm
parents: 20470
diff changeset
   284
  conjunction internally.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   285
20472
wenzelm
parents: 20470
diff changeset
   286
  \medskip The tactical proof of a local claim may be structured
wenzelm
parents: 20470
diff changeset
   287
  further by decomposing a sub-goal: @{text "(\<And>x. A(x) \<Longrightarrow> B(x)) \<Longrightarrow> \<dots>"}
wenzelm
parents: 20470
diff changeset
   288
  is turned into @{text "B(x) \<Longrightarrow> \<dots>"} after fixing @{text "x"} and
wenzelm
parents: 20470
diff changeset
   289
  assuming @{text "A(x)"}.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   290
*}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   291
20472
wenzelm
parents: 20470
diff changeset
   292
text %mlref {*
wenzelm
parents: 20470
diff changeset
   293
  \begin{mldecls}
wenzelm
parents: 20470
diff changeset
   294
  @{index_ML Goal.prove: "Proof.context -> string list -> term list -> term ->
wenzelm
parents: 20470
diff changeset
   295
  ({prems: thm list, context: Proof.context} -> tactic) -> thm"} \\
wenzelm
parents: 20470
diff changeset
   296
  @{index_ML Goal.prove_multi: "Proof.context -> string list -> term list -> term list ->
wenzelm
parents: 20470
diff changeset
   297
  ({prems: thm list, context: Proof.context} -> tactic) -> thm list"} \\
wenzelm
parents: 20470
diff changeset
   298
  @{index_ML SUBPROOF:
wenzelm
parents: 20470
diff changeset
   299
  "({context: Proof.context, schematics: ctyp list * cterm list,
wenzelm
parents: 20470
diff changeset
   300
    params: cterm list, asms: cterm list, concl: cterm,
wenzelm
parents: 20470
diff changeset
   301
    prems: thm list} -> tactic) -> Proof.context -> int -> tactic"}
wenzelm
parents: 20470
diff changeset
   302
  \end{mldecls}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   303
20472
wenzelm
parents: 20470
diff changeset
   304
  \begin{description}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   305
20472
wenzelm
parents: 20470
diff changeset
   306
  \item @{ML Goal.prove}~@{text "ctxt xs As C tac"} states goal @{text
wenzelm
parents: 20470
diff changeset
   307
  "C"} in the context of fixed variables @{text "xs"} and assumptions
wenzelm
parents: 20470
diff changeset
   308
  @{text "As"} and applies tactic @{text "tac"} to solve it.  The
wenzelm
parents: 20470
diff changeset
   309
  latter may depend on the local assumptions being presented as facts.
wenzelm
parents: 20470
diff changeset
   310
  The result is essentially @{text "\<And>xs. As \<Longrightarrow> C"}, but is normalized
wenzelm
parents: 20470
diff changeset
   311
  by pulling @{text "\<And>"} before @{text "\<Longrightarrow>"} (the conclusion @{text
wenzelm
parents: 20470
diff changeset
   312
  "C"} itself may be a rule statement), turning the quantifier prefix
wenzelm
parents: 20470
diff changeset
   313
  into schematic variables, and generalizing implicit type-variables.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   314
20472
wenzelm
parents: 20470
diff changeset
   315
  \item @{ML Goal.prove_multi} is simular to @{ML Goal.prove}, but
wenzelm
parents: 20470
diff changeset
   316
  states several conclusions simultaneously.  @{ML
wenzelm
parents: 20470
diff changeset
   317
  Tactic.conjunction_tac} may be used to split these into individual
wenzelm
parents: 20470
diff changeset
   318
  subgoals before commencing the actual proof.
wenzelm
parents: 20470
diff changeset
   319
wenzelm
parents: 20470
diff changeset
   320
  \item @{ML SUBPROOF}~@{text "tac"} decomposes the structure of a
wenzelm
parents: 20470
diff changeset
   321
  particular sub-goal, producing an extended context and a reduced
wenzelm
parents: 20470
diff changeset
   322
  goal, which needs to be solved by the given tactic.  All schematic
wenzelm
parents: 20470
diff changeset
   323
  parameters of the goal are imported into the context as fixed ones,
wenzelm
parents: 20470
diff changeset
   324
  which may not be instantiated in the sub-proof.
wenzelm
parents: 20470
diff changeset
   325
wenzelm
parents: 20470
diff changeset
   326
  \end{description}
wenzelm
parents: 20470
diff changeset
   327
*}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   328
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   329
end