src/Doc/Nitpick/document/root.tex
changeset 53809 2c0e45bb2f05
parent 53808 b3e2022530e3
child 53812 369537953d05
equal deleted inserted replaced
53808:b3e2022530e3 53809:2c0e45bb2f05
   957 \label{coinductive-datatypes}
   957 \label{coinductive-datatypes}
   958 
   958 
   959 A coinductive datatype is similar to an inductive datatype but
   959 A coinductive datatype is similar to an inductive datatype but
   960 allows infinite objects. Thus, the infinite lists $\textit{ps}$ $=$ $[a, a, a,
   960 allows infinite objects. Thus, the infinite lists $\textit{ps}$ $=$ $[a, a, a,
   961 \ldots]$, $\textit{qs}$ $=$ $[a, b, a, b, \ldots]$, and $\textit{rs}$ $=$ $[0,
   961 \ldots]$, $\textit{qs}$ $=$ $[a, b, a, b, \ldots]$, and $\textit{rs}$ $=$ $[0,
   962 1, 2, 3, \ldots]$ can be defined as lazy lists using the
   962 1, 2, 3, \ldots]$ can be defined as coinductive lists, or ``lazy lists,'' using the
   963 $\textit{LNil}\mathbin{\Colon}{'}a~\textit{llist}$ and
   963 $\textit{LNil}\mathbin{\Colon}{'}a~\textit{llist}$ and
   964 $\textit{LCons}\mathbin{\Colon}{'}a \mathbin{\Rightarrow} {'}a~\textit{llist}
   964 $\textit{LCons}\mathbin{\Colon}{'}a \mathbin{\Rightarrow} {'}a~\textit{llist}
   965 \mathbin{\Rightarrow} {'}a~\textit{llist}$ constructors.
   965 \mathbin{\Rightarrow} {'}a~\textit{llist}$ constructors.
   966 
   966 
   967 Although it is otherwise no friend of infinity, Nitpick can find counterexamples
   967 Although it is otherwise no friend of infinity, Nitpick can find counterexamples
  2726 \label{standard-ml-interface}
  2726 \label{standard-ml-interface}
  2727 
  2727 
  2728 Nitpick provides a rich Standard ML interface used mainly for internal purposes
  2728 Nitpick provides a rich Standard ML interface used mainly for internal purposes
  2729 and debugging. Among the most interesting functions exported by Nitpick are
  2729 and debugging. Among the most interesting functions exported by Nitpick are
  2730 those that let you invoke the tool programmatically and those that let you
  2730 those that let you invoke the tool programmatically and those that let you
  2731 register and unregister custom coinductive datatypes as well as term
  2731 register and unregister custom term postprocessors as well as coinductive
  2732 postprocessors.
  2732 datatypes.
  2733 
  2733 
  2734 \subsection{Invocation of Nitpick}
  2734 \subsection{Invoking Nitpick}
  2735 \label{invocation-of-nitpick}
  2735 \label{invoking-nitpick}
  2736 
  2736 
  2737 The \textit{Nitpick} structure offers the following functions for invoking your
  2737 The \textit{Nitpick} structure offers the following functions for invoking your
  2738 favorite counterexample generator:
  2738 favorite counterexample generator:
  2739 
  2739 
  2740 \prew
  2740 \prew
  2768 $\hbox{}\quad\textit{Nitpick.pick\_nits\_in\_subgoal}~\textit{state}~\textit{params}~\textit{Nitpick.Normal}~\textit{i}~\textit{n}$
  2768 $\hbox{}\quad\textit{Nitpick.pick\_nits\_in\_subgoal}~\textit{state}~\textit{params}~\textit{Nitpick.Normal}~\textit{i}~\textit{n}$
  2769 \postw
  2769 \postw
  2770 
  2770 
  2771 \let\antiq=\textrm
  2771 \let\antiq=\textrm
  2772 
  2772 
  2773 \subsection{Registration of Coinductive Datatypes}
  2773 \subsection{Registering Term Postprocessors}
  2774 \label{registration-of-coinductive-datatypes}
  2774 \label{registering-term-postprocessors}
  2775 
       
  2776 If you have defined a custom coinductive datatype, you can tell Nitpick about
       
  2777 it, so that it can use an efficient Kodkod axiomatization similar to the one it
       
  2778 uses for lazy lists. The interface for registering and unregistering coinductive
       
  2779 datatypes consists of the following pair of functions defined in the
       
  2780 \textit{Nitpick\_HOL} structure:
       
  2781 
       
  2782 \prew
       
  2783 $\textbf{val}\,~\textit{register\_codatatype\/} : {}$ \\
       
  2784 $\hbox{}\quad\textit{morphism} \rightarrow \textit{typ} \rightarrow \textit{string} \rightarrow (\textit{string} \times \textit{typ})\;\textit{list} \rightarrow \textit{Context.generic} {}$ \\
       
  2785 $\hbox{}\quad{\rightarrow}\; \textit{Context.generic}$ \\
       
  2786 $\textbf{val}\,~\textit{unregister\_codatatype\/} : {}$ \\
       
  2787 $\hbox{}\quad\textit{morphism} \rightarrow \textit{typ} \rightarrow \textit{Context.generic} \rightarrow \textit{Context.generic} {}$
       
  2788 \postw
       
  2789 
       
  2790 The type $'a~\textit{llist}$ of lazy lists is already registered; had it
       
  2791 not been, you could have told Nitpick about it by adding the following line
       
  2792 to your theory file:
       
  2793 
       
  2794 \prew
       
  2795 $\textbf{declaration}~\,\{{*}$ \\
       
  2796 $\hbox{}\quad\textit{Nitpick\_HOL.register\_codatatype}~@\{\antiq{typ}~``\kern1pt'a~\textit{llist\/}\textrm{''}\}$ \\
       
  2797 $\hbox{}\qquad\quad @\{\antiq{const\_name}~ \textit{llist\_case}\}$ \\
       
  2798 $\hbox{}\qquad\quad (\textit{map}~\textit{dest\_Const}~[@\{\antiq{term}~\textit{LNil}\},\, @\{\antiq{term}~\textit{LCons}\}])$ \\
       
  2799 ${*}\}$
       
  2800 \postw
       
  2801 
       
  2802 The \textit{register\_codatatype} function takes a coinductive datatype, its
       
  2803 case function, and the list of its constructors (in addition to the current
       
  2804 morphism and generic proof context). The case function must take its arguments
       
  2805 in the order that the constructors are listed. If no case function with the
       
  2806 correct signature is available, simply pass the empty string.
       
  2807 
       
  2808 On the other hand, if your goal is to cripple Nitpick, add the following line to
       
  2809 your theory file and try to check a few conjectures about lazy lists:
       
  2810 
       
  2811 \prew
       
  2812 $\textbf{declaration}~\,\{{*}$ \\
       
  2813 $\hbox{}\quad\textit{Nitpick\_HOL.unregister\_codatatype}~@\{\antiq{typ}~``\kern1pt'a~\textit{llist\/}\textrm{''}\}$ \\
       
  2814 ${*}\}$
       
  2815 \postw
       
  2816 
       
  2817 Inductive datatypes can be registered as coinductive datatypes, given
       
  2818 appropriate coinductive constructors. However, doing so precludes
       
  2819 the use of the inductive constructors---Nitpick will generate an error if they
       
  2820 are needed.
       
  2821 
       
  2822 \subsection{Registration of Term Postprocessors}
       
  2823 \label{registration-of-term-postprocessors}
       
  2824 
  2775 
  2825 It is possible to change the output of any term that Nitpick considers a
  2776 It is possible to change the output of any term that Nitpick considers a
  2826 datatype by registering a term postprocessor. The interface for registering and
  2777 datatype by registering a term postprocessor. The interface for registering and
  2827 unregistering postprocessors consists of the following pair of functions defined
  2778 unregistering postprocessors consists of the following pair of functions defined
  2828 in the \textit{Nitpick\_Model} structure:
  2779 in the \textit{Nitpick\_Model} structure:
  2837 $\hbox{}\quad\textit{typ} \rightarrow \textit{morphism} \rightarrow \textit{Context.generic} \rightarrow \textit{Context.generic}$
  2788 $\hbox{}\quad\textit{typ} \rightarrow \textit{morphism} \rightarrow \textit{Context.generic} \rightarrow \textit{Context.generic}$
  2838 \postw
  2789 \postw
  2839 
  2790 
  2840 \S\ref{typedefs-quotient-types-records-rationals-and-reals} and
  2791 \S\ref{typedefs-quotient-types-records-rationals-and-reals} and
  2841 \texttt{src/HOL/Library/Multiset.thy} illustrate this feature in context.
  2792 \texttt{src/HOL/Library/Multiset.thy} illustrate this feature in context.
       
  2793 
       
  2794 \subsection{Registering Coinductive Datatypes}
       
  2795 \label{registering-coinductive-datatypes}
       
  2796 
       
  2797 If you have defined a custom coinductive datatype, you can tell Nitpick about
       
  2798 it, so that it can use an efficient Kodkod axiomatization similar to the one it
       
  2799 uses for lazy lists. The interface for registering and unregistering coinductive
       
  2800 datatypes consists of the following pair of functions defined in the
       
  2801 \textit{Nitpick\_HOL} structure:
       
  2802 
       
  2803 \prew
       
  2804 $\textbf{val}\,~\textit{register\_codatatype\/} : {}$ \\
       
  2805 $\hbox{}\quad\textit{morphism} \rightarrow \textit{typ} \rightarrow \textit{string} \rightarrow (\textit{string} \times \textit{typ})\;\textit{list} \rightarrow \textit{Context.generic} {}$ \\
       
  2806 $\hbox{}\quad{\rightarrow}\; \textit{Context.generic}$ \\
       
  2807 $\textbf{val}\,~\textit{unregister\_codatatype\/} : {}$ \\
       
  2808 $\hbox{}\quad\textit{morphism} \rightarrow \textit{typ} \rightarrow \textit{Context.generic} \rightarrow \textit{Context.generic} {}$
       
  2809 \postw
       
  2810 
       
  2811 The type $'a~\textit{llist}$ of lazy lists is already registered; had it
       
  2812 not been, you could have told Nitpick about it by adding the following line
       
  2813 to your theory file:
       
  2814 
       
  2815 \prew
       
  2816 $\textbf{declaration}~\,\{{*}$ \\
       
  2817 $\hbox{}\quad\textit{Nitpick\_HOL.register\_codatatype}~@\{\antiq{typ}~``\kern1pt'a~\textit{llist\/}\textrm{''}\}$ \\
       
  2818 $\hbox{}\qquad\quad @\{\antiq{const\_name}~ \textit{llist\_case}\}$ \\
       
  2819 $\hbox{}\qquad\quad (\textit{map}~\textit{dest\_Const}~[@\{\antiq{term}~\textit{LNil}\},\, @\{\antiq{term}~\textit{LCons}\}])$ \\
       
  2820 ${*}\}$
       
  2821 \postw
       
  2822 
       
  2823 The \textit{register\_codatatype} function takes a coinductive datatype, its
       
  2824 case function, and the list of its constructors (in addition to the current
       
  2825 morphism and generic proof context). The case function must take its arguments
       
  2826 in the order that the constructors are listed. If no case function with the
       
  2827 correct signature is available, simply pass the empty string.
       
  2828 
       
  2829 On the other hand, if your goal is to cripple Nitpick, add the following line to
       
  2830 your theory file and try to check a few conjectures about lazy lists:
       
  2831 
       
  2832 \prew
       
  2833 $\textbf{declaration}~\,\{{*}$ \\
       
  2834 $\hbox{}\quad\textit{Nitpick\_HOL.unregister\_codatatype}~@\{\antiq{typ}~``\kern1pt'a~\textit{llist\/}\textrm{''}\}$ \\
       
  2835 ${*}\}$
       
  2836 \postw
       
  2837 
       
  2838 Inductive datatypes can be registered as coinductive datatypes, given
       
  2839 appropriate coinductive constructors. However, doing so precludes
       
  2840 the use of the inductive constructors---Nitpick will generate an error if they
       
  2841 are needed.
  2842 
  2842 
  2843 \section{Known Bugs and Limitations}
  2843 \section{Known Bugs and Limitations}
  2844 \label{known-bugs-and-limitations}
  2844 \label{known-bugs-and-limitations}
  2845 
  2845 
  2846 Here are the known bugs and limitations in Nitpick at the time of writing:
  2846 Here are the known bugs and limitations in Nitpick at the time of writing: