doc-src/IsarImplementation/Thy/document/proof.tex
changeset 20471 ffafbd4103c0
parent 20460 351c63bb2704
child 20472 e993073eda4c
equal deleted inserted replaced
20470:c839b38a1f32 20471:ffafbd4103c0
    26 \isamarkupsection{Variables%
    26 \isamarkupsection{Variables%
    27 }
    27 }
    28 \isamarkuptrue%
    28 \isamarkuptrue%
    29 %
    29 %
    30 \begin{isamarkuptext}%
    30 \begin{isamarkuptext}%
    31 FIXME%
    31 Any variable that is not explicitly bound by \isa{{\isasymlambda}}-abstraction
       
    32   is considered as ``free''.  Logically, free variables act like
       
    33   outermost universal quantification (at the sequent level): \isa{A\isactrlisub {\isadigit{1}}{\isacharparenleft}x{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ A\isactrlisub n{\isacharparenleft}x{\isacharparenright}\ {\isasymturnstile}\ B{\isacharparenleft}x{\isacharparenright}} means that the result
       
    34   holds \emph{for all} values of \isa{x}.  Free variables for
       
    35   terms (not types) can be fully internalized into the logic: \isa{{\isasymturnstile}\ B{\isacharparenleft}x{\isacharparenright}} and \isa{{\isasymturnstile}\ {\isasymAnd}x{\isachardot}\ B{\isacharparenleft}x{\isacharparenright}} are interchangeable provided that
       
    36   \isa{x} does not occur elsewhere in the context.  Inspecting
       
    37   \isa{{\isasymturnstile}\ {\isasymAnd}x{\isachardot}\ B{\isacharparenleft}x{\isacharparenright}} more closely, we see that inside the
       
    38   quantifier, \isa{x} is essentially ``arbitrary, but fixed'',
       
    39   while from outside it appears as a place-holder for instantiation
       
    40   (thanks to \isa{{\isasymAnd}}-elimination).
       
    41 
       
    42   The Pure logic represents the notion of variables being either
       
    43   inside or outside the current scope by providing separate syntactic
       
    44   categories for \emph{fixed variables} (e.g.\ \isa{x}) vs.\
       
    45   \emph{schematic variables} (e.g.\ \isa{{\isacharquery}x}).  Incidently, a
       
    46   universal result \isa{{\isasymturnstile}\ {\isasymAnd}x{\isachardot}\ B{\isacharparenleft}x{\isacharparenright}} has the canonical form \isa{{\isasymturnstile}\ B{\isacharparenleft}{\isacharquery}x{\isacharparenright}}, which represents its generality nicely without requiring
       
    47   an explicit quantifier.  The same principle works for type variables
       
    48   as well: \isa{{\isasymturnstile}\ B{\isacharparenleft}{\isacharquery}{\isasymalpha}{\isacharparenright}} expresses the idea of ``\isa{{\isasymturnstile}\ {\isasymforall}{\isasymalpha}{\isachardot}\ B{\isacharparenleft}{\isasymalpha}{\isacharparenright}}'' without demanding a truly polymorphic framework.
       
    49 
       
    50   \medskip Additional care is required to treat type variables in a
       
    51   way that facilitates type-inference.  In principle, term variables
       
    52   depend on type variables, which means that type variables would have
       
    53   to be declared first.  For example, a raw type-theoretic framework
       
    54   would demand the context to be constructed in stages as follows:
       
    55   \isa{{\isasymGamma}\ {\isacharequal}\ {\isasymalpha}{\isacharcolon}\ type{\isacharcomma}\ x{\isacharcolon}\ {\isasymalpha}{\isacharcomma}\ a{\isacharcolon}\ A{\isacharparenleft}x\isactrlisub {\isasymalpha}{\isacharparenright}}.
       
    56 
       
    57   We allow a slightly less formalistic mode of operation: term
       
    58   variables \isa{x} are fixed without specifying a type yet
       
    59   (essentially \emph{all} potential occurrences of some instance
       
    60   \isa{x\isactrlisub {\isasymtau}} will be fixed); the first occurrence of \isa{x} within a specific term assigns its most general type, which is
       
    61   then maintained consistently in the context.  The above example
       
    62   becomes \isa{{\isasymGamma}\ {\isacharequal}\ x{\isacharcolon}\ term{\isacharcomma}\ {\isasymalpha}{\isacharcolon}\ type{\isacharcomma}\ A{\isacharparenleft}x\isactrlisub {\isasymalpha}{\isacharparenright}}, where type
       
    63   \isa{{\isasymalpha}} is fixed \emph{after} term \isa{x}, and the
       
    64   constraint \isa{x{\isacharcolon}\ {\isasymalpha}} is an implicit consequence of the
       
    65   occurrence of \isa{x\isactrlisub {\isasymalpha}} in the subsequent proposition.
       
    66 
       
    67   This twist of dependencies is also accommodated by the reverse
       
    68   operation of exporting results from a context: a type variable
       
    69   \isa{{\isasymalpha}} is considered fixed as long as it occurs in some fixed
       
    70   term variable of the context.  For example, exporting \isa{x{\isacharcolon}\ term{\isacharcomma}\ {\isasymalpha}{\isacharcolon}\ type\ {\isasymturnstile}\ x\isactrlisub {\isasymalpha}\ {\isacharequal}\ x\isactrlisub {\isasymalpha}} produces \isa{x{\isacharcolon}\ term\ {\isasymturnstile}\ x\isactrlisub {\isasymalpha}\ {\isacharequal}\ x\isactrlisub {\isasymalpha}} for fixed \isa{{\isasymalpha}} in the first step,
       
    71   and \isa{{\isasymturnstile}\ {\isacharquery}x\isactrlisub {\isacharquery}\isactrlisub {\isasymalpha}\ {\isacharequal}\ {\isacharquery}x\isactrlisub {\isacharquery}\isactrlisub {\isasymalpha}} for
       
    72   schematic \isa{{\isacharquery}x} and \isa{{\isacharquery}{\isasymalpha}} only in the second step.
       
    73 
       
    74   \medskip The Isabelle/Isar proof context manages the gory details of
       
    75   term vs.\ type variables, with high-level principles for moving the
       
    76   frontier between fixed and schematic variables.  By observing a
       
    77   simple discipline of fixing variables and declaring terms
       
    78   explicitly, the fine points are treated by the \isa{export}
       
    79   operation.
       
    80 
       
    81   There is also a separate \isa{import} operation makes a
       
    82   generalized fact a genuine part of the context, by inventing fixed
       
    83   variables for the schematic ones.  The effect can be reversed by
       
    84   using \isa{export} later, with a potentially extended context,
       
    85   but the result will be only equivalent modulo renaming of schematic
       
    86   variables.
       
    87 
       
    88   The \isa{focus} operation provides a variant of \isa{import}
       
    89   for nested propositions (with explicit quantification): \isa{{\isasymAnd}x{\isachardot}\ B{\isacharparenleft}x{\isacharparenright}} is decomposed by inventing a fixed variable \isa{x}
       
    90   and for the body \isa{B{\isacharparenleft}x{\isacharparenright}}.%
    32 \end{isamarkuptext}%
    91 \end{isamarkuptext}%
    33 \isamarkuptrue%
    92 \isamarkuptrue%
    34 %
    93 %
    35 \isadelimmlref
    94 \isadelimmlref
    36 %
    95 %
    38 %
    97 %
    39 \isatagmlref
    98 \isatagmlref
    40 %
    99 %
    41 \begin{isamarkuptext}%
   100 \begin{isamarkuptext}%
    42 \begin{mldecls}
   101 \begin{mldecls}
       
   102   \indexml{Variable.add-fixes}\verb|Variable.add_fixes: string list -> Proof.context -> string list * Proof.context| \\
       
   103   \indexml{Variable.invent-fixes}\verb|Variable.invent_fixes: string list -> Proof.context -> string list * Proof.context| \\
    43   \indexml{Variable.declare-term}\verb|Variable.declare_term: term -> Proof.context -> Proof.context| \\
   104   \indexml{Variable.declare-term}\verb|Variable.declare_term: term -> Proof.context -> Proof.context| \\
    44   \indexml{Variable.add-fixes}\verb|Variable.add_fixes: string list -> Proof.context -> string list * Proof.context| \\
   105   \indexml{Variable.declare-constraints}\verb|Variable.declare_constraints: term -> Proof.context -> Proof.context| \\
       
   106   \indexml{Variable.export}\verb|Variable.export: Proof.context -> Proof.context -> thm list -> thm list| \\
       
   107   \indexml{Variable.polymorphic}\verb|Variable.polymorphic: Proof.context -> term list -> term list| \\
    45   \indexml{Variable.import}\verb|Variable.import: bool ->|\isasep\isanewline%
   108   \indexml{Variable.import}\verb|Variable.import: bool ->|\isasep\isanewline%
    46 \verb|  thm list -> Proof.context -> ((ctyp list * cterm list) * thm list) * Proof.context| \\
   109 \verb|  thm list -> Proof.context -> ((ctyp list * cterm list) * thm list) * Proof.context| \\
    47   \indexml{Variable.export}\verb|Variable.export: Proof.context -> Proof.context -> thm list -> thm list| \\
   110   \indexml{Variable.focus}\verb|Variable.focus: cterm -> Proof.context -> (cterm list * cterm) * Proof.context| \\
    48   \indexml{Variable.polymorphic}\verb|Variable.polymorphic: Proof.context -> term list -> term list| \\
       
    49   \end{mldecls}
   111   \end{mldecls}
    50 
   112 
    51   \begin{description}
   113   \begin{description}
    52 
   114 
       
   115   \item \verb|Variable.add_fixes|~\isa{xs\ ctxt} fixes term
       
   116   variables \isa{xs}, returning the resulting internal names.  By
       
   117   default, the internal representation coincides with the external
       
   118   one, which also means that the given variables must not have been
       
   119   fixed already.  Within a local proof body, the given names are just
       
   120   hints for newly invented Skolem variables.
       
   121 
       
   122   \item \verb|Variable.invent_fixes| is similar to \verb|Variable.add_fixes|, but always produces fresh variants of the given
       
   123   hints.
       
   124 
    53   \item \verb|Variable.declare_term|~\isa{t\ ctxt} declares term
   125   \item \verb|Variable.declare_term|~\isa{t\ ctxt} declares term
    54   \isa{t} to belong to the context.  This fixes free type
   126   \isa{t} to belong to the context.  This automatically fixes new
    55   variables, but not term variables.  Constraints for type and term
   127   type variables, but not term variables.  Syntactic constraints for
    56   variables are declared uniformly.
   128   type and term variables are declared uniformly.
    57 
   129 
    58   \item \verb|Variable.add_fixes|~\isa{xs\ ctxt} fixes term
   130   \item \verb|Variable.declare_constraints|~\isa{t\ ctxt} derives
    59   variables \isa{xs} and returns the internal names of the
   131   type-inference information from term \isa{t}, without making it
    60   resulting Skolem constants.  Note that term fixes refer to
   132   part of the context yet.
    61   \emph{all} type instances that may occur in the future.
   133 
    62 
   134   \item \verb|Variable.export|~\isa{inner\ outer\ thms} generalizes
    63   \item \verb|Variable.invent_fixes| is similar to \verb|Variable.add_fixes|, but the given names merely act as hints for
   135   fixed type and term variables in \isa{thms} according to the
    64   internal fixes produced here.
   136   difference of the \isa{inner} and \isa{outer} context,
    65 
   137   following the principles sketched above.
    66   \item \verb|Variable.import|~\isa{open\ ths\ ctxt} augments the
   138 
       
   139   \item \verb|Variable.polymorphic|~\isa{ctxt\ ts} generalizes type
       
   140   variables in \isa{ts} as far as possible, even those occurring
       
   141   in fixed term variables.  The default policy of type-inference is to
       
   142   fix newly introduced type variables; this is essentially reversed
       
   143   with \verb|Variable.polymorphic|, the given terms are detached from
       
   144   the context as far as possible.
       
   145 
       
   146   \item \verb|Variable.import|~\isa{open\ thms\ ctxt} augments the
    67   context by new fixes for the schematic type and term variables
   147   context by new fixes for the schematic type and term variables
    68   occurring in \isa{ths}.  The \isa{open} flag indicates
   148   occurring in \isa{thms}.  The \isa{open} flag indicates
    69   whether the fixed names should be accessible to the user, otherwise
   149   whether the fixed names should be accessible to the user, otherwise
    70   internal names are chosen.
   150   internal names are chosen.
    71 
   151 
    72   \item \verb|Variable.export|~\isa{inner\ outer\ ths} generalizes
   152   \verb|Variable.export| essentially reverses the effect of \verb|Variable.import|, modulo renaming of schematic variables.
    73   fixed type and term variables in \isa{ths} according to the
   153 
    74   difference of the \isa{inner} and \isa{outer} context.  Note
   154   \item \verb|Variable.focus|~\isa{{\isasymAnd}x\isactrlisub {\isadigit{1}}\ {\isasymdots}\ x\isactrlisub n{\isachardot}\ B{\isacharparenleft}x\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlisub n{\isacharparenright}} invents fixed variables
    75   that type variables occurring in term variables are still fixed.
   155   for \isa{x\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlisub n} and replaces these in the
    76 
   156   body.
    77   \verb|Variable.export| essentially reverses the effect of \verb|Variable.import| (up to renaming of schematic variables.
       
    78 
       
    79   \item \verb|Variable.polymorphic|~\isa{ctxt\ ts} generalizes type
       
    80   variables in \isa{ts} as far as possible, even those occurring
       
    81   in fixed term variables.  This operation essentially reverses the
       
    82   default policy of type-inference to introduce local polymorphism as
       
    83   fixed types.
       
    84 
   157 
    85   \end{description}%
   158   \end{description}%
    86 \end{isamarkuptext}%
   159 \end{isamarkuptext}%
    87 \isamarkuptrue%
   160 \isamarkuptrue%
    88 %
   161 %