src/Doc/IsarRef/HOL_Specific.thy
changeset 52895 a806aa7a5370
parent 52637 1501ebe39711
child 53015 a1119cf551e8
equal deleted inserted replaced
52894:cebaf814ca6e 52895:a806aa7a5370
     1 theory HOL_Specific
     1 theory HOL_Specific
     2 imports Base Main "~~/src/HOL/Library/Old_Recdef"
     2 imports Base Main "~~/src/HOL/Library/Old_Recdef" "~~/src/Tools/Adhoc_Overloading"
     3 begin
     3 begin
     4 
     4 
     5 chapter {* Higher-Order Logic *}
     5 chapter {* Higher-Order Logic *}
     6 
     6 
     7 text {* Isabelle/HOL is based on Higher-Order Logic, a polymorphic
     7 text {* Isabelle/HOL is based on Higher-Order Logic, a polymorphic
   586   Thus, the specification consists of a single function described by a
   586   Thus, the specification consists of a single function described by a
   587   single recursive equation.
   587   single recursive equation.
   588 
   588 
   589   There are no fixed syntactic restrictions on the body of the
   589   There are no fixed syntactic restrictions on the body of the
   590   function, but the induced functional must be provably monotonic
   590   function, but the induced functional must be provably monotonic
   591   wrt.\ the underlying order.  The monotonicitity proof is performed
   591   wrt.\ the underlying order.  The monotonicity proof is performed
   592   internally, and the definition is rejected when it fails. The proof
   592   internally, and the definition is rejected when it fails. The proof
   593   can be influenced by declaring hints using the
   593   can be influenced by declaring hints using the
   594   @{attribute (HOL) partial_function_mono} attribute.
   594   @{attribute (HOL) partial_function_mono} attribute.
   595 
   595 
   596   The mandatory @{text mode} argument specifies the mode of operation
   596   The mandatory @{text mode} argument specifies the mode of operation
   620 
   620 
   621   Experienced users may define new modes by instantiating the locale
   621   Experienced users may define new modes by instantiating the locale
   622   @{const "partial_function_definitions"} appropriately.
   622   @{const "partial_function_definitions"} appropriately.
   623 
   623 
   624   \item @{attribute (HOL) partial_function_mono} declares rules for
   624   \item @{attribute (HOL) partial_function_mono} declares rules for
   625   use in the internal monononicity proofs of partial function
   625   use in the internal monotonicity proofs of partial function
   626   definitions.
   626   definitions.
   627 
   627 
   628   \end{description}
   628   \end{description}
   629 
   629 
   630 *}
   630 *}
  1286   injection from a quotient type to a raw type is called @{text
  1286   injection from a quotient type to a raw type is called @{text
  1287   rep_t}, its inverse @{text abs_t} unless explicit @{keyword (HOL)
  1287   rep_t}, its inverse @{text abs_t} unless explicit @{keyword (HOL)
  1288   "morphisms"} specification provides alternative names. @{command
  1288   "morphisms"} specification provides alternative names. @{command
  1289   (HOL) "quotient_type"} requires the user to prove that the relation
  1289   (HOL) "quotient_type"} requires the user to prove that the relation
  1290   is an equivalence relation (predicate @{text equivp}), unless the
  1290   is an equivalence relation (predicate @{text equivp}), unless the
  1291   user specifies explicitely @{text partial} in which case the
  1291   user specifies explicitly @{text partial} in which case the
  1292   obligation is @{text part_equivp}.  A quotient defined with @{text
  1292   obligation is @{text part_equivp}.  A quotient defined with @{text
  1293   partial} is weaker in the sense that less things can be proved
  1293   partial} is weaker in the sense that less things can be proved
  1294   automatically.
  1294   automatically.
  1295 
  1295 
  1296   \item @{command (HOL) "quotient_definition"} defines a constant on
  1296   \item @{command (HOL) "quotient_definition"} defines a constant on
  1316     "descending_setup"} try to guess a raw statement that would lift
  1316     "descending_setup"} try to guess a raw statement that would lift
  1317     to the current subgoal. Such statement is assumed as a new subgoal
  1317     to the current subgoal. Such statement is assumed as a new subgoal
  1318     and @{method (HOL) "descending"} continues in the same way as
  1318     and @{method (HOL) "descending"} continues in the same way as
  1319     @{method (HOL) "lifting"} does. @{method (HOL) "descending"} tries
  1319     @{method (HOL) "lifting"} does. @{method (HOL) "descending"} tries
  1320     to solve the arising regularization, injection and cleaning
  1320     to solve the arising regularization, injection and cleaning
  1321     subgoals with the analoguous method @{method (HOL)
  1321     subgoals with the analogous method @{method (HOL)
  1322     "descending_setup"} which leaves the four unsolved subgoals.
  1322     "descending_setup"} which leaves the four unsolved subgoals.
  1323 
  1323 
  1324   \item @{method (HOL) "partiality_descending"} finds the regularized
  1324   \item @{method (HOL) "partiality_descending"} finds the regularized
  1325     theorem that would lift to the current subgoal, lifts it and
  1325     theorem that would lift to the current subgoal, lifts it and
  1326     leaves as a subgoal. This method can be used with partial
  1326     leaves as a subgoal. This method can be used with partial
  1414   properties using @{command (HOL) "specification"}, one can prove
  1414   properties using @{command (HOL) "specification"}, one can prove
  1415   that the two constants are, in fact, equal.  If this might be a
  1415   that the two constants are, in fact, equal.  If this might be a
  1416   problem, one should use @{command (HOL) "ax_specification"}.
  1416   problem, one should use @{command (HOL) "ax_specification"}.
  1417 *}
  1417 *}
  1418 
  1418 
       
  1419 section {* Adhoc overloading of constants *}
       
  1420 
       
  1421 text {*
       
  1422   \begin{tabular}{rcll}
       
  1423   @{command_def "adhoc_overloading"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
       
  1424   @{command_def "no_adhoc_overloading"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
       
  1425   @{attribute_def "show_variants"} & : & @{text "attribute"} & default @{text false} \\
       
  1426   \end{tabular}
       
  1427 
       
  1428   \medskip
       
  1429 
       
  1430   Adhoc overloading allows to overload a constant depending on
       
  1431   its type. Typically this involves the introduction of an
       
  1432   uninterpreted constant (used for input and output) and the addition
       
  1433   of some variants (used internally). For examples see
       
  1434   @{file "~~/src/HOL/ex/Adhoc_Overloading_Examples.thy"} and
       
  1435   @{file "~~/src/HOL/Library/Monad_Syntax.thy"}.
       
  1436 
       
  1437   @{rail "
       
  1438     (@@{command adhoc_overloading} | @@{command no_adhoc_overloading})
       
  1439     (@{syntax nameref} (@{syntax term} + ) + @'and')
       
  1440   "}
       
  1441 
       
  1442   \begin{description}
       
  1443 
       
  1444   \item @{command "adhoc_overloading"}~@{text "c v\<^isub>1 ... v\<^isub>n"}
       
  1445   associates variants with an existing constant.
       
  1446 
       
  1447   \item @{command "no_adhoc_overloading"} is similar to
       
  1448   @{command "adhoc_overloading"}, but removes the specified variants
       
  1449   from the present context.
       
  1450   
       
  1451   \item @{attribute "show_variants"} controls printing of variants
       
  1452   of overloaded constants. If enabled, the internally used variants
       
  1453   are printed instead of their respective overloaded constants. This
       
  1454   is occasionally useful to check whether the system agrees with a
       
  1455   user's expectations about derived variants.
       
  1456 
       
  1457   \end{description}
       
  1458 *}
  1419 
  1459 
  1420 chapter {* Proof tools *}
  1460 chapter {* Proof tools *}
  1421 
  1461 
  1422 section {* Adhoc tuples *}
  1462 section {* Adhoc tuples *}
  1423 
  1463 
  1551     generator. This allows @{command (HOL) "lift_definition"} to
  1591     generator. This allows @{command (HOL) "lift_definition"} to
  1552     register (generated) code certificate theorems as abstract code
  1592     register (generated) code certificate theorems as abstract code
  1553     equations in the code generator.  The option @{text "no_code"}
  1593     equations in the code generator.  The option @{text "no_code"}
  1554     of the command @{command (HOL) "setup_lifting"} can turn off that
  1594     of the command @{command (HOL) "setup_lifting"} can turn off that
  1555     behavior and causes that code certificate theorems generated by
  1595     behavior and causes that code certificate theorems generated by
  1556     @{command (HOL) "lift_definition"} are not registred as abstract
  1596     @{command (HOL) "lift_definition"} are not registered as abstract
  1557     code equations.
  1597     code equations.
  1558 
  1598 
  1559   \item @{command (HOL) "lift_definition"} @{text "f :: \<tau> is t"}
  1599   \item @{command (HOL) "lift_definition"} @{text "f :: \<tau> is t"}
  1560     Defines a new function @{text f} with an abstract type @{text \<tau>}
  1600     Defines a new function @{text f} with an abstract type @{text \<tau>}
  1561     in terms of a corresponding operation @{text t} on a
  1601     in terms of a corresponding operation @{text t} on a
  1605     respectfulness theorem. For examples see @{file
  1645     respectfulness theorem. For examples see @{file
  1606     "~~/src/HOL/Library/Quotient_List.thy"} or other Quotient_*.thy
  1646     "~~/src/HOL/Library/Quotient_List.thy"} or other Quotient_*.thy
  1607     files.
  1647     files.
  1608 
  1648 
  1609   \item @{attribute (HOL) reflexivity_rule} registers a theorem that shows
  1649   \item @{attribute (HOL) reflexivity_rule} registers a theorem that shows
  1610     that a relator respects reflexivity and left-totality. For exampless 
  1650     that a relator respects reflexivity and left-totality. For examples 
  1611     see @{file "~~/src/HOL/Library/Quotient_List.thy"} or other Quotient_*.thy
  1651     see @{file "~~/src/HOL/Library/Quotient_List.thy"} or other Quotient_*.thy
  1612     The property is used in generation of abstraction function equations.
  1652     The property is used in generation of abstraction function equations.
  1613 
  1653 
  1614   \item @{attribute (HOL) quot_del} deletes a corresponding Quotient theorem
  1654   \item @{attribute (HOL) quot_del} deletes a corresponding Quotient theorem
  1615     from the Lifting infrastructure and thus de-register the corresponding quotient. 
  1655     from the Lifting infrastructure and thus de-register the corresponding quotient. 
  2007 
  2047 
  2008   \item @{command (HOL) "quickcheck"} tests the current goal for
  2048   \item @{command (HOL) "quickcheck"} tests the current goal for
  2009   counterexamples using a series of assignments for its free
  2049   counterexamples using a series of assignments for its free
  2010   variables; by default the first subgoal is tested, an other can be
  2050   variables; by default the first subgoal is tested, an other can be
  2011   selected explicitly using an optional goal index.  Assignments can
  2051   selected explicitly using an optional goal index.  Assignments can
  2012   be chosen exhausting the search space upto a given size, or using a
  2052   be chosen exhausting the search space up to a given size, or using a
  2013   fixed number of random assignments in the search space, or exploring
  2053   fixed number of random assignments in the search space, or exploring
  2014   the search space symbolically using narrowing.  By default,
  2054   the search space symbolically using narrowing.  By default,
  2015   quickcheck uses exhaustive testing.  A number of configuration
  2055   quickcheck uses exhaustive testing.  A number of configuration
  2016   options are supported for @{command (HOL) "quickcheck"}, notably:
  2056   options are supported for @{command (HOL) "quickcheck"}, notably:
  2017 
  2057 
  2371   of constants in the specified target language(s).  If no
  2411   of constants in the specified target language(s).  If no
  2372   serialization instruction is given, only abstract code is generated
  2412   serialization instruction is given, only abstract code is generated
  2373   internally.
  2413   internally.
  2374 
  2414 
  2375   Constants may be specified by giving them literally, referring to
  2415   Constants may be specified by giving them literally, referring to
  2376   all executable contants within a certain theory by giving @{text
  2416   all executable constants within a certain theory by giving @{text
  2377   "name.*"}, or referring to \emph{all} executable constants currently
  2417   "name.*"}, or referring to \emph{all} executable constants currently
  2378   available by giving @{text "*"}.
  2418   available by giving @{text "*"}.
  2379 
  2419 
  2380   By default, for each involved theory one corresponding name space
  2420   By default, for each involved theory one corresponding name space
  2381   module is generated.  Alternativly, a module name may be specified
  2421   module is generated.  Alternatively, a module name may be specified
  2382   after the @{keyword "module_name"} keyword; then \emph{all} code is
  2422   after the @{keyword "module_name"} keyword; then \emph{all} code is
  2383   placed in this module.
  2423   placed in this module.
  2384 
  2424 
  2385   For \emph{SML}, \emph{OCaml} and \emph{Scala} the file specification
  2425   For \emph{SML}, \emph{OCaml} and \emph{Scala} the file specification
  2386   refers to a single file; for \emph{Haskell}, it refers to a whole
  2426   refers to a single file; for \emph{Haskell}, it refers to a whole