doc-src/Nitpick/nitpick.tex
changeset 46105 9abb756352a6
parent 46074 3ab55dfd2400
child 46110 22294c79cea6
equal deleted inserted replaced
46104:eb85282db54e 46105:9abb756352a6
    25 %\def\rbrakk{\mathclose{\rbrack\mkern-3.255mu\rbrack}}
    25 %\def\rbrakk{\mathclose{\rbrack\mkern-3.255mu\rbrack}}
    26 \def\lparr{\mathopen{(\mkern-4mu\mid}}
    26 \def\lparr{\mathopen{(\mkern-4mu\mid}}
    27 \def\rparr{\mathclose{\mid\mkern-4mu)}}
    27 \def\rparr{\mathclose{\mid\mkern-4mu)}}
    28 
    28 
    29 \def\unk{{?}}
    29 \def\unk{{?}}
    30 \def\undef{(\lambda x.\; \unk)}
    30 \def\unkef{(\lambda x.\; \unk)}
       
    31 \def\undef{(\lambda x.\; \_)}
    31 %\def\unr{\textit{others}}
    32 %\def\unr{\textit{others}}
    32 \def\unr{\ldots}
    33 \def\unr{\ldots}
    33 \def\Abs#1{\hbox{\rm{\flqq}}{\,#1\,}\hbox{\rm{\frqq}}}
    34 \def\Abs#1{\hbox{\rm{\flqq}}{\,#1\,}\hbox{\rm{\frqq}}}
    34 \def\Q{{\smash{\lower.2ex\hbox{$\scriptstyle?$}}}}
    35 \def\Q{{\smash{\lower.2ex\hbox{$\scriptstyle?$}}}}
    35 
    36 
   105 Another common use of Nitpick is to find out whether the axioms of a locale are
   106 Another common use of Nitpick is to find out whether the axioms of a locale are
   106 satisfiable, while the locale is being developed. To check this, it suffices to
   107 satisfiable, while the locale is being developed. To check this, it suffices to
   107 write
   108 write
   108 
   109 
   109 \prew
   110 \prew
   110 \textbf{lemma}~``$\textit{False}$'' \\
   111 \textbf{lemma}~``$\textit{False\/}$'' \\
   111 \textbf{nitpick}~[\textit{show\_all}]
   112 \textbf{nitpick}~[\textit{show\_all}]
   112 \postw
   113 \postw
   113 
   114 
   114 after the locale's \textbf{begin} keyword. To falsify \textit{False}, Nitpick
   115 after the locale's \textbf{begin} keyword. To falsify \textit{False}, Nitpick
   115 must find a model for the axioms. If it finds no model, we have an indication
   116 must find a model for the axioms. If it finds no model, we have an indication
   239 
   240 
   240 If you are left unimpressed by the previous example, don't worry. The next
   241 If you are left unimpressed by the previous example, don't worry. The next
   241 one is more mind- and computer-boggling:
   242 one is more mind- and computer-boggling:
   242 
   243 
   243 \prew
   244 \prew
   244 \textbf{lemma} ``$P~x\,\Longrightarrow\, P~(\textrm{THE}~y.\;P~y)$''
   245 \textbf{lemma} ``$x \in A\,\Longrightarrow\, (\textrm{THE}~y.\;y \in A) \in A$''
   245 \postw
   246 \postw
   246 \pagebreak[2] %% TYPESETTING
   247 \pagebreak[2] %% TYPESETTING
   247 
   248 
   248 The putative lemma involves the definite description operator, {THE}, presented
   249 The putative lemma involves the definite description operator, {THE}, presented
   249 in section 5.10.1 of the Isabelle tutorial \cite{isa-tutorial}. The
   250 in section 5.10.1 of the Isabelle tutorial \cite{isa-tutorial}. The
   264 \hbox{}\qquad \textit{card}~$'a$~= 2; \\
   265 \hbox{}\qquad \textit{card}~$'a$~= 2; \\
   265 \hbox{}\qquad $\qquad\vdots$ \\[.5\smallskipamount]
   266 \hbox{}\qquad $\qquad\vdots$ \\[.5\smallskipamount]
   266 \hbox{}\qquad \textit{card}~$'a$~= 10. \\[2\smallskipamount]
   267 \hbox{}\qquad \textit{card}~$'a$~= 10. \\[2\smallskipamount]
   267 Nitpick found a counterexample for \textit{card} $'a$~= 3: \\[2\smallskipamount]
   268 Nitpick found a counterexample for \textit{card} $'a$~= 3: \\[2\smallskipamount]
   268 \hbox{}\qquad Free variables: \nopagebreak \\
   269 \hbox{}\qquad Free variables: \nopagebreak \\
   269 \hbox{}\qquad\qquad $P = \{a_2,\, a_3\}$ \\
   270 \hbox{}\qquad\qquad $A = \{a_2,\, a_3\}$ \\
   270 \hbox{}\qquad\qquad $x = a_3$ \\[2\smallskipamount]
   271 \hbox{}\qquad\qquad $x = a_3$ \\[2\smallskipamount]
   271 Total time: 0.76 s.
   272 Total time: 963 ms.
   272 \postw
   273 \postw
   273 
   274 
   274 Nitpick found a counterexample in which $'a$ has cardinality 3. (For
   275 Nitpick found a counterexample in which $'a$ has cardinality 3. (For
   275 cardinalities 1 and 2, the formula holds.) In the counterexample, the three
   276 cardinalities 1 and 2, the formula holds.) In the counterexample, the three
   276 values of type $'a$ are written $a_1$, $a_2$, and $a_3$.
   277 values of type $'a$ are written $a_1$, $a_2$, and $a_3$.
   293 counterexample in \S\ref{type-variables} is genuine. Let's invoke Nitpick again,
   294 counterexample in \S\ref{type-variables} is genuine. Let's invoke Nitpick again,
   294 this time telling it to show the values of the constants that occur in the
   295 this time telling it to show the values of the constants that occur in the
   295 formula:
   296 formula:
   296 
   297 
   297 \prew
   298 \prew
   298 \textbf{lemma}~``$P~x\,\Longrightarrow\, P~(\textrm{THE}~y.\;P~y)$'' \\
   299 \textbf{lemma} ``$x \in A\,\Longrightarrow\, (\textrm{THE}~y.\;y \in A) \in A$'' \\
   299 \textbf{nitpick}~[\textit{show\_consts}] \\[2\smallskipamount]
   300 \textbf{nitpick}~[\textit{show\_consts}] \\[2\smallskipamount]
   300 \slshape
   301 \slshape
   301 Nitpick found a counterexample for \textit{card} $'a$~= 3: \\[2\smallskipamount]
   302 Nitpick found a counterexample for \textit{card} $'a$~= 3: \\[2\smallskipamount]
   302 \hbox{}\qquad Free variables: \nopagebreak \\
   303 \hbox{}\qquad Free variables: \nopagebreak \\
   303 \hbox{}\qquad\qquad $P = \{a_2,\, a_3\}$ \\
   304 \hbox{}\qquad\qquad $A = \{a_2,\, a_3\}$ \\
   304 \hbox{}\qquad\qquad $x = a_3$ \\
   305 \hbox{}\qquad\qquad $x = a_3$ \\
   305 \hbox{}\qquad Constant: \nopagebreak \\
   306 \hbox{}\qquad Constant: \nopagebreak \\
   306 \hbox{}\qquad\qquad $\hbox{\slshape THE}~y.\;P~y = a_1$
   307 \hbox{}\qquad\qquad $\hbox{\slshape THE}~y.\;y \in A = a_1$
   307 \postw
   308 \postw
   308 
   309 
   309 As the result of an optimization, Nitpick directly assigned a value to the
   310 As the result of an optimization, Nitpick directly assigned a value to the
   310 subterm $\textrm{THE}~y.\;P~y$, rather than to the \textit{The} constant. If we
   311 subterm $\textrm{THE}~y.\;y \in A$, rather than to the \textit{The} constant. We
   311 disable this optimization by using the command
   312 can disable this optimization by using the command
   312 
   313 
   313 \prew
   314 \prew
   314 \textbf{nitpick}~[\textit{dont\_specialize},\, \textit{show\_consts}]
   315 \textbf{nitpick}~[\textit{dont\_specialize},\, \textit{show\_consts}]
   315 \postw
   316 \postw
   316 
       
   317 we get \textit{The}:
       
   318 
       
   319 \prew
       
   320 \slshape Constant: \nopagebreak \\
       
   321 \hbox{}\qquad $\mathit{The} = \undef{}
       
   322     (\!\begin{aligned}[t]%
       
   323     & \{a_1, a_2, a_3\} := a_3,\> \{a_1, a_2\} := a_3,\> \{a_1, a_3\} := a_3, \\[-2pt] %% TYPESETTING
       
   324     & \{a_1\} := a_1,\> \{a_2, a_3\} := a_1,\> \{a_2\} := a_2, \\[-2pt]
       
   325     & \{a_3\} := a_3,\> \{\} := a_3)\end{aligned}$
       
   326 \postw
       
   327 
       
   328 Notice that $\textit{The}~(\lambda y.\;P~y) = \textit{The}~\{a_2, a_3\} = a_1$,
       
   329 just like before.\footnote{The Isabelle/HOL notation $f(x :=
       
   330 y)$ denotes the function that maps $x$ to $y$ and that otherwise behaves like
       
   331 $f$.}
       
   332 
   317 
   333 Our misadventures with THE suggest adding `$\exists!x{.}$' (``there exists a
   318 Our misadventures with THE suggest adding `$\exists!x{.}$' (``there exists a
   334 unique $x$ such that'') at the front of our putative lemma's assumption:
   319 unique $x$ such that'') at the front of our putative lemma's assumption:
   335 
   320 
   336 \prew
   321 \prew
   337 \textbf{lemma}~``$\exists {!}x.\; P~x\,\Longrightarrow\, P~(\textrm{THE}~y.\;P~y)$''
   322 \textbf{lemma} ``$\exists {!}x.\; x \in A\,\Longrightarrow\, (\textrm{THE}~y.\;y \in A) \in A$''
   338 \postw
   323 \postw
   339 
   324 
   340 The fix appears to work:
   325 The fix appears to work:
   341 
   326 
   342 \prew
   327 \prew
   356 
   341 
   357 Let's see if Sledgehammer can find a proof:
   342 Let's see if Sledgehammer can find a proof:
   358 
   343 
   359 \prew
   344 \prew
   360 \textbf{sledgehammer} \\[2\smallskipamount]
   345 \textbf{sledgehammer} \\[2\smallskipamount]
   361 {\slshape Sledgehammer: ``$e$'' on goal: \\
   346 {\slshape Sledgehammer: ``$e$'' on goal \\
   362 $\exists{!}x.\; P~x\,\Longrightarrow\, P~(\hbox{\slshape THE}~y.\; P~y)$ \\
   347 Try this: \textrm{by}~(\textit{metis~theI}) (42 ms).} \\[2\smallskipamount]
   363 Try this: \textrm{apply}~(\textit{metis~theI}) (21 ms).} \\[2\smallskipamount]
   348 \textbf{by}~(\textit{metis~theI\/})
   364 \textbf{by}~(\textit{metis~theI\/}) \nopagebreak \\[2\smallskipamount]
       
   365 {\slshape No subgoals!}% \\[2\smallskipamount]
       
   366 %\textbf{done}
       
   367 \postw
   349 \postw
   368 
   350 
   369 This must be our lucky day.
   351 This must be our lucky day.
   370 
   352 
   371 \subsection{Skolemization}
   353 \subsection{Skolemization}
   384 \hbox{}\qquad Skolem constants: \nopagebreak \\
   366 \hbox{}\qquad Skolem constants: \nopagebreak \\
   385 \hbox{}\qquad\qquad $g = \undef{}(a_1 := b_1,\> a_2 := b_1)$ \\
   367 \hbox{}\qquad\qquad $g = \undef{}(a_1 := b_1,\> a_2 := b_1)$ \\
   386 \hbox{}\qquad\qquad $y = a_2$
   368 \hbox{}\qquad\qquad $y = a_2$
   387 \postw
   369 \postw
   388 
   370 
       
   371 (The Isabelle/HOL notation $f(x := y)$ denotes the function that maps $x$ to $y$
       
   372 and that otherwise behaves like $f$.)
   389 Although $f$ is the only free variable occurring in the formula, Nitpick also
   373 Although $f$ is the only free variable occurring in the formula, Nitpick also
   390 displays values for the bound variables $g$ and $y$. These values are available
   374 displays values for the bound variables $g$ and $y$. These values are available
   391 to Nitpick because it performs skolemization as a preprocessing step.
   375 to Nitpick because it performs skolemization as a preprocessing step.
   392 
   376 
   393 In the previous example, skolemization only affected the outermost quantifiers.
   377 In the previous example, skolemization only affected the outermost quantifiers.
   422 \hbox{}\qquad Skolem constants: \nopagebreak \\
   406 \hbox{}\qquad Skolem constants: \nopagebreak \\
   423 \hbox{}\qquad\qquad $\mathit{sym}.x = a_2$ \\
   407 \hbox{}\qquad\qquad $\mathit{sym}.x = a_2$ \\
   424 \hbox{}\qquad\qquad $\mathit{sym}.y = a_1$
   408 \hbox{}\qquad\qquad $\mathit{sym}.y = a_1$
   425 \postw
   409 \postw
   426 
   410 
   427 What happened here is that Nitpick expanded the \textit{sym} constant to its
   411 What happened here is that Nitpick expanded \textit{sym} to its definition:
   428 definition:
       
   429 
   412 
   430 \prew
   413 \prew
   431 $\mathit{sym}~r \,\equiv\,
   414 $\mathit{sym}~r \,\equiv\,
   432  \forall x\> y.\,\> (x, y) \in r \longrightarrow (y, x) \in r.$
   415  \forall x\> y.\,\> (x, y) \in r \longrightarrow (y, x) \in r.$
   433 \postw
   416 \postw
   490 You might wonder why the counterexample is first reported as potentially
   473 You might wonder why the counterexample is first reported as potentially
   491 spurious. The root of the problem is that the bound variable in $\forall n.\;
   474 spurious. The root of the problem is that the bound variable in $\forall n.\;
   492 \textit{Suc}~n \mathbin{\not=} n$ ranges over an infinite type. If Nitpick finds
   475 \textit{Suc}~n \mathbin{\not=} n$ ranges over an infinite type. If Nitpick finds
   493 an $n$ such that $\textit{Suc}~n \mathbin{=} n$, it evaluates the assumption to
   476 an $n$ such that $\textit{Suc}~n \mathbin{=} n$, it evaluates the assumption to
   494 \textit{False}; but otherwise, it does not know anything about values of $n \ge
   477 \textit{False}; but otherwise, it does not know anything about values of $n \ge
   495 \textit{card~nat}$ and must therefore evaluate the assumption to $\unk$, not
   478 \textit{card~nat}$ and must therefore evaluate the assumption to~$\unk$, not
   496 \textit{True}. Since the assumption can never be satisfied, the putative lemma
   479 \textit{True}. Since the assumption can never be satisfied, the putative lemma
   497 can never be falsified.
   480 can never be falsified.
   498 
   481 
   499 Incidentally, if you distrust the so-called genuine counterexamples, you can
   482 Incidentally, if you distrust the so-called genuine counterexamples, you can
   500 enable \textit{check\_\allowbreak genuine} to verify them as well. However, be
   483 enable \textit{check\_\allowbreak genuine} to verify them as well. However, be
   503 
   486 
   504 Some conjectures involving elementary number theory make Nitpick look like a
   487 Some conjectures involving elementary number theory make Nitpick look like a
   505 giant with feet of clay:
   488 giant with feet of clay:
   506 
   489 
   507 \prew
   490 \prew
   508 \textbf{lemma} ``$P~\textit{Suc}$'' \\
   491 \textbf{lemma} ``$P~\textit{Suc\/}$'' \\
   509 \textbf{nitpick} \\[2\smallskipamount]
   492 \textbf{nitpick} \\[2\smallskipamount]
   510 \slshape
   493 \slshape
   511 Nitpick found no counterexample.
   494 Nitpick found no counterexample.
   512 \postw
   495 \postw
   513 
   496 
   521 \textbf{lemma} ``$P~(\textit{op}~{+}\Colon
   504 \textbf{lemma} ``$P~(\textit{op}~{+}\Colon
   522 \textit{nat}\mathbin{\Rightarrow}\textit{nat}\mathbin{\Rightarrow}\textit{nat})$'' \\
   505 \textit{nat}\mathbin{\Rightarrow}\textit{nat}\mathbin{\Rightarrow}\textit{nat})$'' \\
   523 \textbf{nitpick} [\textit{card nat} = 1] \\[2\smallskipamount]
   506 \textbf{nitpick} [\textit{card nat} = 1] \\[2\smallskipamount]
   524 {\slshape Nitpick found a counterexample:} \\[2\smallskipamount]
   507 {\slshape Nitpick found a counterexample:} \\[2\smallskipamount]
   525 \hbox{}\qquad Free variable: \nopagebreak \\
   508 \hbox{}\qquad Free variable: \nopagebreak \\
   526 \hbox{}\qquad\qquad $P = \{\}$ \\[2\smallskipamount]
   509 \hbox{}\qquad\qquad $P = \unkef(\unkef(0 := \unkef(0 := 0)) := \mathit{False})$ \\[2\smallskipamount]
   527 \textbf{nitpick} [\textit{card nat} = 2] \\[2\smallskipamount]
   510 \textbf{nitpick} [\textit{card nat} = 2] \\[2\smallskipamount]
   528 {\slshape Nitpick found no counterexample.}
   511 {\slshape Nitpick found no counterexample.}
   529 \postw
   512 \postw
   530 
   513 
   531 The problem here is that \textit{op}~+ is total when \textit{nat} is taken to be
   514 The problem here is that \textit{op}~+ is total when \textit{nat} is taken to be
   532 $\{0\}$ but becomes partial as soon as we add $1$, because $1 + 1 \notin \{0,
   515 $\{0\}$ but becomes partial as soon as we add $1$, because
   533 1\}$.
   516 $1 + 1 \notin \{0, 1\}$.
   534 
   517 
   535 Because numbers are infinite and are approximated using a three-valued logic,
   518 Because numbers are infinite and are approximated using a three-valued logic,
   536 there is usually no need to systematically enumerate domain sizes. If Nitpick
   519 there is usually no need to systematically enumerate domain sizes. If Nitpick
   537 cannot find a genuine counterexample for \textit{card~nat}~= $k$, it is very
   520 cannot find a genuine counterexample for \textit{card~nat}~= $k$, it is very
   538 unlikely that one could be found for smaller domains. (The $P~(\textit{op}~{+})$
   521 unlikely that one could be found for smaller domains. (The $P~(\textit{op}~{+})$
   552 
   535 
   553 Let's see with an example involving \textit{hd} (which returns the first element
   536 Let's see with an example involving \textit{hd} (which returns the first element
   554 of a list) and $@$ (which concatenates two lists):
   537 of a list) and $@$ (which concatenates two lists):
   555 
   538 
   556 \prew
   539 \prew
   557 \textbf{lemma} ``$\textit{hd}~(\textit{xs} \mathbin{@} [y, y]) = \textit{hd}~\textit{xs}$'' \\
   540 \textbf{lemma} ``$\textit{hd}~(\textit{xs} \mathbin{@} [y, y]) = \textit{hd}~\textit{xs\/}$'' \\
   558 \textbf{nitpick} \\[2\smallskipamount]
   541 \textbf{nitpick} \\[2\smallskipamount]
   559 \slshape Nitpick found a counterexample for \textit{card} $'a$~= 3: \\[2\smallskipamount]
   542 \slshape Nitpick found a counterexample for \textit{card} $'a$~= 3: \\[2\smallskipamount]
   560 \hbox{}\qquad Free variables: \nopagebreak \\
   543 \hbox{}\qquad Free variables: \nopagebreak \\
   561 \hbox{}\qquad\qquad $\textit{xs} = []$ \\
   544 \hbox{}\qquad\qquad $\textit{xs} = []$ \\
   562 \hbox{}\qquad\qquad $\textit{y} = a_1$
   545 \hbox{}\qquad\qquad $\textit{y} = a_1$
   567 
   550 
   568 \prew
   551 \prew
   569 {\slshape Datatype:} \\
   552 {\slshape Datatype:} \\
   570 \hbox{}\qquad $'a$~\textit{list}~= $\{[],\, [a_1],\, [a_1, a_1],\, \unr\}$ \\
   553 \hbox{}\qquad $'a$~\textit{list}~= $\{[],\, [a_1],\, [a_1, a_1],\, \unr\}$ \\
   571 {\slshape Constants:} \\
   554 {\slshape Constants:} \\
   572 \hbox{}\qquad $\lambda x_1.\; x_1 \mathbin{@} [y, y] = \undef([] := [a_1, a_1])$ \\
   555 \hbox{}\qquad $\lambda x_1.\; x_1 \mathbin{@} [y, y] = \unkef([] := [a_1, a_1])$ \\
   573 \hbox{}\qquad $\textit{hd} = \undef([] := a_2,\> [a_1] := a_1,\> [a_1, a_1] := a_1)$
   556 \hbox{}\qquad $\textit{hd} = \unkef([] := a_2,\> [a_1] := a_1,\> [a_1, a_1] := a_1)$
   574 \postw
   557 \postw
   575 
   558 
   576 Since $\mathit{hd}~[]$ is undefined in the logic, it may be given any value,
   559 Since $\mathit{hd}~[]$ is undefined in the logic, it may be given any value,
   577 including $a_2$.
   560 including $a_2$.
   578 
   561 
   615 
   598 
   616 Here's another m\"ochtegern-lemma that Nitpick can refute without a blink:
   599 Here's another m\"ochtegern-lemma that Nitpick can refute without a blink:
   617 
   600 
   618 \prew
   601 \prew
   619 \textbf{lemma} ``$\lbrakk \textit{length}~\textit{xs} = 1;\> \textit{length}~\textit{ys} = 1
   602 \textbf{lemma} ``$\lbrakk \textit{length}~\textit{xs} = 1;\> \textit{length}~\textit{ys} = 1
   620 \rbrakk \,\Longrightarrow\, \textit{xs} = \textit{ys}$''
   603 \rbrakk \,\Longrightarrow\, \textit{xs} = \textit{ys\/}$''
   621 \\
   604 \\
   622 \textbf{nitpick} [\textit{show\_datatypes}] \\[2\smallskipamount]
   605 \textbf{nitpick} [\textit{show\_datatypes}] \\[2\smallskipamount]
   623 \slshape Nitpick found a counterexample for \textit{card} $'a$~= 3: \\[2\smallskipamount]
   606 \slshape Nitpick found a counterexample for \textit{card} $'a$~= 3: \\[2\smallskipamount]
   624 \hbox{}\qquad Free variables: \nopagebreak \\
   607 \hbox{}\qquad Free variables: \nopagebreak \\
   625 \hbox{}\qquad\qquad $\textit{xs} = [a_1]$ \\
   608 \hbox{}\qquad\qquad $\textit{xs} = [a_2]$ \\
   626 \hbox{}\qquad\qquad $\textit{ys} = [a_2]$ \\
   609 \hbox{}\qquad\qquad $\textit{ys} = [a_1]$ \\
   627 \hbox{}\qquad Datatypes: \\
   610 \hbox{}\qquad Datatypes: \\
   628 \hbox{}\qquad\qquad $\textit{nat} = \{0,\, 1,\, 2,\, \unr\}$ \\
   611 \hbox{}\qquad\qquad $\textit{nat} = \{0,\, 1,\, 2,\, \unr\}$ \\
   629 \hbox{}\qquad\qquad $'a$~\textit{list} = $\{[],\, [a_1],\, [a_2],\, \unr\}$
   612 \hbox{}\qquad\qquad $'a$~\textit{list} = $\{[],\, [a_1],\, [a_2],\, \unr\}$
   630 \postw
   613 \postw
   631 
   614 
   645 \textbf{typedef}~\textit{three} = ``$\{0\Colon\textit{nat},\, 1,\, 2\}$'' \\
   628 \textbf{typedef}~\textit{three} = ``$\{0\Colon\textit{nat},\, 1,\, 2\}$'' \\
   646 \textbf{by}~\textit{blast} \\[2\smallskipamount]
   629 \textbf{by}~\textit{blast} \\[2\smallskipamount]
   647 \textbf{definition}~$A \mathbin{\Colon} \textit{three}$ \textbf{where} ``\kern-.1em$A \,\equiv\, \textit{Abs\_\allowbreak three}~0$'' \\
   630 \textbf{definition}~$A \mathbin{\Colon} \textit{three}$ \textbf{where} ``\kern-.1em$A \,\equiv\, \textit{Abs\_\allowbreak three}~0$'' \\
   648 \textbf{definition}~$B \mathbin{\Colon} \textit{three}$ \textbf{where} ``$B \,\equiv\, \textit{Abs\_three}~1$'' \\
   631 \textbf{definition}~$B \mathbin{\Colon} \textit{three}$ \textbf{where} ``$B \,\equiv\, \textit{Abs\_three}~1$'' \\
   649 \textbf{definition}~$C \mathbin{\Colon} \textit{three}$ \textbf{where} ``$C \,\equiv\, \textit{Abs\_three}~2$'' \\[2\smallskipamount]
   632 \textbf{definition}~$C \mathbin{\Colon} \textit{three}$ \textbf{where} ``$C \,\equiv\, \textit{Abs\_three}~2$'' \\[2\smallskipamount]
   650 \textbf{lemma} ``$\lbrakk P~A;\> P~B\rbrakk \,\Longrightarrow\, P~x$'' \\
   633 \textbf{lemma} ``$\lbrakk A \in X;\> B \in X\rbrakk \,\Longrightarrow\, c \in X$'' \\
   651 \textbf{nitpick} [\textit{show\_datatypes}] \\[2\smallskipamount]
   634 \textbf{nitpick} [\textit{show\_datatypes}] \\[2\smallskipamount]
   652 \slshape Nitpick found a counterexample: \\[2\smallskipamount]
   635 \slshape Nitpick found a counterexample: \\[2\smallskipamount]
   653 \hbox{}\qquad Free variables: \nopagebreak \\
   636 \hbox{}\qquad Free variables: \nopagebreak \\
   654 \hbox{}\qquad\qquad $P = \{\Abs{0},\, \Abs{1}\}$ \\
   637 \hbox{}\qquad\qquad $X = \{\Abs{0},\, \Abs{1}\}$ \\
   655 \hbox{}\qquad\qquad $x = \Abs{2}$ \\
   638 \hbox{}\qquad\qquad $c = \Abs{2}$ \\
   656 \hbox{}\qquad Datatypes: \\
   639 \hbox{}\qquad Datatypes: \\
   657 \hbox{}\qquad\qquad $\textit{nat} = \{0,\, 1,\, 2,\, \unr\}$ \\
   640 \hbox{}\qquad\qquad $\textit{nat} = \{0,\, 1,\, 2,\, \unr\}$ \\
   658 \hbox{}\qquad\qquad $\textit{three} = \{\Abs{0},\, \Abs{1},\, \Abs{2},\, \unr\}$
   641 \hbox{}\qquad\qquad $\textit{three} = \{\Abs{0},\, \Abs{1},\, \Abs{2},\, \unr\}$
   659 \postw
   642 \postw
   660 
   643 
   667 \prew
   650 \prew
   668 \textbf{fun} \textit{my\_int\_rel} \textbf{where} \\
   651 \textbf{fun} \textit{my\_int\_rel} \textbf{where} \\
   669 ``$\textit{my\_int\_rel}~(x,\, y)~(u,\, v) = (x + v = u + y)$'' \\[2\smallskipamount]
   652 ``$\textit{my\_int\_rel}~(x,\, y)~(u,\, v) = (x + v = u + y)$'' \\[2\smallskipamount]
   670 %
   653 %
   671 \textbf{quotient\_type}~\textit{my\_int} = ``$\textit{nat} \times \textit{nat\/}$''$\;{/}\;$\textit{my\_int\_rel} \\
   654 \textbf{quotient\_type}~\textit{my\_int} = ``$\textit{nat} \times \textit{nat\/}$''$\;{/}\;$\textit{my\_int\_rel} \\
   672 \textbf{by}~(\textit{auto simp add\/}:\ \textit{equivp\_def expand\_fun\_eq}) \\[2\smallskipamount]
   655 \textbf{by}~(\textit{auto simp add\/}:\ \textit{equivp\_def fun\_eq\_iff}) \\[2\smallskipamount]
   673 %
   656 %
   674 \textbf{definition}~\textit{add\_raw}~\textbf{where} \\
   657 \textbf{definition}~\textit{add\_raw}~\textbf{where} \\
   675 ``$\textit{add\_raw} \,\equiv\, \lambda(x,\, y)~(u,\, v).\; (x + (u\Colon\textit{nat}), y + (v\Colon\textit{nat}))$'' \\[2\smallskipamount]
   658 ``$\textit{add\_raw} \,\equiv\, \lambda(x,\, y)~(u,\, v).\; (x + (u\Colon\textit{nat}), y + (v\Colon\textit{nat}))$'' \\[2\smallskipamount]
   676 %
   659 %
   677 \textbf{quotient\_definition} ``$\textit{add\/}\Colon\textit{my\_int} \Rightarrow \textit{my\_int} \Rightarrow \textit{my\_int\/}$'' \textbf{is} \textit{add\_raw} \\[2\smallskipamount]
   660 \textbf{quotient\_definition} ``$\textit{add\/}\Colon\textit{my\_int} \Rightarrow \textit{my\_int} \Rightarrow \textit{my\_int\/}$'' \textbf{is} \textit{add\_raw} \\[2\smallskipamount]
   679 \textbf{lemma} ``$\textit{add}~x~y = \textit{add}~x~x$'' \\
   662 \textbf{lemma} ``$\textit{add}~x~y = \textit{add}~x~x$'' \\
   680 \textbf{nitpick} [\textit{show\_datatypes}] \\[2\smallskipamount]
   663 \textbf{nitpick} [\textit{show\_datatypes}] \\[2\smallskipamount]
   681 \slshape Nitpick found a counterexample: \\[2\smallskipamount]
   664 \slshape Nitpick found a counterexample: \\[2\smallskipamount]
   682 \hbox{}\qquad Free variables: \nopagebreak \\
   665 \hbox{}\qquad Free variables: \nopagebreak \\
   683 \hbox{}\qquad\qquad $x = \Abs{(0,\, 0)}$ \\
   666 \hbox{}\qquad\qquad $x = \Abs{(0,\, 0)}$ \\
   684 \hbox{}\qquad\qquad $y = \Abs{(1,\, 0)}$ \\
   667 \hbox{}\qquad\qquad $y = \Abs{(0,\, 1)}$ \\
   685 \hbox{}\qquad Datatypes: \\
   668 \hbox{}\qquad Datatypes: \\
   686 \hbox{}\qquad\qquad $\textit{nat} = \{0,\, 1,\, \unr\}$ \\
   669 \hbox{}\qquad\qquad $\textit{nat} = \{0,\, 1,\, \unr\}$ \\
   687 \hbox{}\qquad\qquad $\textit{nat} \times \textit{nat}~[\textsl{boxed\/}] = \{(0,\, 0),\> (1,\, 0),\> \unr\}$ \\
   670 \hbox{}\qquad\qquad $\textit{nat} \times \textit{nat}~[\textsl{boxed\/}] = \{(0,\, 0),\> (1,\, 0),\> \unr\}$ \\
   688 \hbox{}\qquad\qquad $\textit{my\_int} = \{\Abs{(0,\, 0)},\> \Abs{(1,\, 0)},\> \unr\}$
   671 \hbox{}\qquad\qquad $\textit{my\_int} = \{\Abs{(0,\, 0)},\> \Abs{(0,\, 1)},\> \unr\}$
   689 \postw
   672 \postw
   690 
   673 
   691 In the counterexample, $\Abs{(0,\, 0)}$ and $\Abs{(1,\, 0)}$ represent the
   674 The values $\Abs{(0,\, 0)}$ and $\Abs{(0,\, 1)}$ represent the
   692 integers $0$ and $1$, respectively. Other representants would have been
   675 integers $0$ and $-1$, respectively. Other representants would have been
   693 possible---e.g., $\Abs{(5,\, 5)}$ and $\Abs{(12,\, 11)}$. If we are going to
   676 possible---e.g., $\Abs{(5,\, 5)}$ and $\Abs{(11,\, 12)}$. If we are going to
   694 use \textit{my\_int} extensively, it pays off to install a term postprocessor
   677 use \textit{my\_int} extensively, it pays off to install a term postprocessor
   695 that converts the pair notation to the standard mathematical notation:
   678 that converts the pair notation to the standard mathematical notation:
   696 
   679 
   697 \prew
   680 \prew
   698 $\textbf{ML}~\,\{{*} \\
   681 $\textbf{ML}~\,\{{*} \\
   710   & @\{\textrm{typ}~\textit{my\_int}\} \\[-2pt]
   693   & @\{\textrm{typ}~\textit{my\_int}\} \\[-2pt]
   711   & \textit{my\_int\_postproc}\end{aligned} \\[-2pt]
   694   & \textit{my\_int\_postproc}\end{aligned} \\[-2pt]
   712 {*}\}\end{aligned}$
   695 {*}\}\end{aligned}$
   713 \postw
   696 \postw
   714 
   697 
   715 Records are also handled as datatypes with a single constructor:
   698 Records are handled as datatypes with a single constructor:
   716 
   699 
   717 \prew
   700 \prew
   718 \textbf{record} \textit{point} = \\
   701 \textbf{record} \textit{point} = \\
   719 \hbox{}\quad $\textit{Xcoord} \mathbin{\Colon} \textit{int}$ \\
   702 \hbox{}\quad $\textit{Xcoord} \mathbin{\Colon} \textit{int}$ \\
   720 \hbox{}\quad $\textit{Ycoord} \mathbin{\Colon} \textit{int}$ \\[2\smallskipamount]
   703 \hbox{}\quad $\textit{Ycoord} \mathbin{\Colon} \textit{int}$ \\[2\smallskipamount]
   741 \hbox{}\qquad Free variables: \nopagebreak \\
   724 \hbox{}\qquad Free variables: \nopagebreak \\
   742 \hbox{}\qquad\qquad $x = 1/2$ \\
   725 \hbox{}\qquad\qquad $x = 1/2$ \\
   743 \hbox{}\qquad\qquad $y = -1/2$ \\
   726 \hbox{}\qquad\qquad $y = -1/2$ \\
   744 \hbox{}\qquad Datatypes: \\
   727 \hbox{}\qquad Datatypes: \\
   745 \hbox{}\qquad\qquad $\textit{nat} = \{0,\, 1,\, 2,\, 3,\, 4,\, 5,\, 6,\, 7,\, \unr\}$ \\
   728 \hbox{}\qquad\qquad $\textit{nat} = \{0,\, 1,\, 2,\, 3,\, 4,\, 5,\, 6,\, 7,\, \unr\}$ \\
   746 \hbox{}\qquad\qquad $\textit{int} = \{0,\, 1,\, 2,\, 3,\, 4,\, -3,\, -2,\, -1,\, \unr\}$ \\
   729 \hbox{}\qquad\qquad $\textit{int} = \{-3,\, -2,\, -1,\, 0,\, 1,\, 2,\, 3,\, 4,\, \unr\}$ \\
   747 \hbox{}\qquad\qquad $\textit{real} = \{1,\, 0,\, 4,\, -3/2,\, 3,\, 2,\, 1/2,\, -1/2,\, \unr\}$
   730 \hbox{}\qquad\qquad $\textit{real} = \{-3/2,\, -1/2,\, 0,\, 1/2,\, 1,\, 2,\, 3,\, 4,\, \unr\}$
   748 \postw
   731 \postw
   749 
   732 
   750 \subsection{Inductive and Coinductive Predicates}
   733 \subsection{Inductive and Coinductive Predicates}
   751 \label{inductive-and-coinductive-predicates}
   734 \label{inductive-and-coinductive-predicates}
   752 
   735 
   800 \textbf{nitpick}~[\textit{card nat}~= 50, \textit{unary\_ints}, \textit{verbose}] \\[2\smallskipamount]
   783 \textbf{nitpick}~[\textit{card nat}~= 50, \textit{unary\_ints}, \textit{verbose}] \\[2\smallskipamount]
   801 \slshape The inductive predicate ``\textit{even}'' was proved well-founded.
   784 \slshape The inductive predicate ``\textit{even}'' was proved well-founded.
   802 Nitpick can compute it efficiently. \\[2\smallskipamount]
   785 Nitpick can compute it efficiently. \\[2\smallskipamount]
   803 Trying 1 scope: \\
   786 Trying 1 scope: \\
   804 \hbox{}\qquad \textit{card nat}~= 50. \\[2\smallskipamount]
   787 \hbox{}\qquad \textit{card nat}~= 50. \\[2\smallskipamount]
       
   788 Warning: The conjecture either trivially holds for the given scopes or lies outside Nitpick's supported fragment. Only
       
   789 potentially spurious counterexamples may be found. \\[2\smallskipamount]
   805 Nitpick found a potentially spurious counterexample for \textit{card nat}~= 50: \\[2\smallskipamount]
   790 Nitpick found a potentially spurious counterexample for \textit{card nat}~= 50: \\[2\smallskipamount]
   806 \hbox{}\qquad Empty assignment \\[2\smallskipamount]
   791 \hbox{}\qquad Empty assignment \\[2\smallskipamount]
   807 Nitpick could not find a better counterexample. \\[2\smallskipamount]
   792 Nitpick could not find a better counterexample. It checked 1 of 1 scope. \\[2\smallskipamount]
   808 Total time: 1.43 s.
   793 Total time: 1.62 s.
   809 \postw
   794 \postw
   810 
   795 
   811 No genuine counterexample is possible because Nitpick cannot rule out the
   796 No genuine counterexample is possible because Nitpick cannot rule out the
   812 existence of a natural number $n \ge 50$ such that both $\textit{even}~n$ and
   797 existence of a natural number $n \ge 50$ such that both $\textit{even}~n$ and
   813 $\textit{even}~(\textit{Suc}~n)$ are true. To help Nitpick, we can bound the
   798 $\textit{even}~(\textit{Suc}~n)$ are true. To help Nitpick, we can bound the
   852 \hbox{}\qquad \textit{card nat}~= 10 and \textit{iter} $\textit{even}'$~= 4; \\
   837 \hbox{}\qquad \textit{card nat}~= 10 and \textit{iter} $\textit{even}'$~= 4; \\
   853 \hbox{}\qquad \textit{card nat}~= 10 and \textit{iter} $\textit{even}'$~= 8; \\
   838 \hbox{}\qquad \textit{card nat}~= 10 and \textit{iter} $\textit{even}'$~= 8; \\
   854 \hbox{}\qquad \textit{card nat}~= 10 and \textit{iter} $\textit{even}'$~= 9. \\[2\smallskipamount]
   839 \hbox{}\qquad \textit{card nat}~= 10 and \textit{iter} $\textit{even}'$~= 9. \\[2\smallskipamount]
   855 Nitpick found a counterexample for \textit{card nat}~= 10 and \textit{iter} $\textit{even}'$~= 2: \\[2\smallskipamount]
   840 Nitpick found a counterexample for \textit{card nat}~= 10 and \textit{iter} $\textit{even}'$~= 2: \\[2\smallskipamount]
   856 \hbox{}\qquad Constant: \nopagebreak \\
   841 \hbox{}\qquad Constant: \nopagebreak \\
   857 \hbox{}\qquad\qquad $\lambda i.\; \textit{even}'$ = $\undef(\!\begin{aligned}[t]
   842 \hbox{}\qquad\qquad $\lambda i.\; \textit{even}'$ = $\unkef(\!\begin{aligned}[t]
   858 & 2 := \{0, 2, 4, 6, 8, 1^\Q, 3^\Q, 5^\Q, 7^\Q, 9^\Q\}, \\[-2pt]
   843 & 0 := \unkef(0 := \textit{True},\, 2 := \textit{True}),\, \\[-2pt]
   859 & 1 := \{0, 2, 4, 1^\Q, 3^\Q, 5^\Q, 6^\Q, 7^\Q, 8^\Q, 9^\Q\}, \\[-2pt]
   844 & 1 := \unkef(0 := \textit{True},\, 2 := \textit{True},\, 4 := \textit{True}),\, \\[-2pt]
   860 & 0 := \{0, 2, 1^\Q, 3^\Q, 4^\Q, 5^\Q, 6^\Q, 7^\Q, 8^\Q, 9^\Q\})\end{aligned}$ \\[2\smallskipamount]
   845 & 2 := \unkef(0 := \textit{True},\, 2 := \textit{True},\, 4 := \textit{True},\, \\[-2pt]
   861 Total time: 2.42 s.
   846 & \phantom{2 := \unkef(}6 := \textit{True},\, 8 := \textit{True}))\end{aligned}$ \\[2\smallskipamount]
       
   847 Total time: 1.87 s.
   862 \postw
   848 \postw
   863 
   849 
   864 Nitpick's output is very instructive. First, it tells us that the predicate is
   850 Nitpick's output is very instructive. First, it tells us that the predicate is
   865 unrolled, meaning that it is computed iteratively from the empty set. Then it
   851 unrolled, meaning that it is computed iteratively from the empty set. Then it
   866 lists six scopes specifying different bounds on the numbers of iterations:\ 0,
   852 lists six scopes specifying different bounds on the numbers of iterations:\ 0,
   870 notation $\lambda i.\; \textit{even}'$ indicates that the value of the
   856 notation $\lambda i.\; \textit{even}'$ indicates that the value of the
   871 predicate depends on an iteration counter. Iteration 0 provides the basis
   857 predicate depends on an iteration counter. Iteration 0 provides the basis
   872 elements, $0$ and $2$. Iteration 1 contributes $4$ ($= 2 + 2$). Iteration 2
   858 elements, $0$ and $2$. Iteration 1 contributes $4$ ($= 2 + 2$). Iteration 2
   873 throws $6$ ($= 2 + 4 = 4 + 2$) and $8$ ($= 4 + 4$) into the mix. Further
   859 throws $6$ ($= 2 + 4 = 4 + 2$) and $8$ ($= 4 + 4$) into the mix. Further
   874 iterations would not contribute any new elements.
   860 iterations would not contribute any new elements.
   875 
   861 The predicate $\textit{even}'$ evaluates to either \textit{True} or $\unk$,
   876 Some values are marked with superscripted question
   862 never \textit{False}.
   877 marks~(`\lower.2ex\hbox{$^\Q$}'). These are the elements for which the
   863 
   878 predicate evaluates to $\unk$. Thus, $\textit{even}'$ evaluates to either
   864 %Some values are marked with superscripted question
   879 \textit{True} or $\unk$, never \textit{False}.
   865 %marks~(`\lower.2ex\hbox{$^\Q$}'). These are the elements for which the
       
   866 %predicate evaluates to $\unk$.
   880 
   867 
   881 When unrolling a predicate, Nitpick tries 0, 1, 2, 4, 8, 12, 16, 20, 24, and 28
   868 When unrolling a predicate, Nitpick tries 0, 1, 2, 4, 8, 12, 16, 20, 24, and 28
   882 iterations. However, these numbers are bounded by the cardinality of the
   869 iterations. However, these numbers are bounded by the cardinality of the
   883 predicate's domain. With \textit{card~nat}~= 10, no more than 9 iterations are
   870 predicate's domain. With \textit{card~nat}~= 10, no more than 9 iterations are
   884 ever needed to compute the value of a \textit{nat} predicate. You can specify
   871 ever needed to compute the value of a \textit{nat} predicate. You can specify
   892 \textbf{nitpick} [\textit{card nat} = 10, \textit{show\_consts}] \\[2\smallskipamount]
   879 \textbf{nitpick} [\textit{card nat} = 10, \textit{show\_consts}] \\[2\smallskipamount]
   893 \slshape Nitpick found a counterexample: \\[2\smallskipamount]
   880 \slshape Nitpick found a counterexample: \\[2\smallskipamount]
   894 \hbox{}\qquad Free variable: \nopagebreak \\
   881 \hbox{}\qquad Free variable: \nopagebreak \\
   895 \hbox{}\qquad\qquad $n = 1$ \\
   882 \hbox{}\qquad\qquad $n = 1$ \\
   896 \hbox{}\qquad Constants: \nopagebreak \\
   883 \hbox{}\qquad Constants: \nopagebreak \\
   897 \hbox{}\qquad\qquad $\lambda i.\; \textit{even}'$ = $\undef(\!\begin{aligned}[t]
   884 \hbox{}\qquad\qquad $\lambda i.\; \textit{even}'$ = $\unkef(\!\begin{aligned}[t]
   898 & 0 := \{0, 2, 1^\Q, 3^\Q, 4^\Q, 5^\Q, 6^\Q, 7^\Q, 8^\Q, 9^\Q\})\end{aligned}$  \\
   885 & 0 := \unkef(0 := \mathit{True},\, 2 := \mathit{True}))\end{aligned}$  \\
   899 \hbox{}\qquad\qquad $\textit{even}' \subseteq \{0, 2, 4, 6, 8, \unr\}$
   886 \hbox{}\qquad\qquad $\textit{even}' \leq \unkef(\!\begin{aligned}[t]
   900 \postw
   887 & 0 := \mathit{True},\, 1 := \mathit{False},\, 2 := \mathit{True},\, \\[-2pt]
   901 
   888 & 4 := \mathit{True},\, 6 := \mathit{True},\, 8 := \mathit{True})\end{aligned}$
   902 Notice the special constraint $\textit{even}' \subseteq \{0,\, 2,\, 4,\, 6,\,
   889 \postw
   903 8,\, \unr\}$ in the output, whose right-hand side represents an arbitrary
   890 
   904 fixed point (not necessarily the least one). It is used to falsify
   891 Notice the special constraint $\textit{even}' \leq \ldots$ in the output, whose
   905 $\textit{even}'~n$. In contrast, the unrolled predicate is used to satisfy
   892 right-hand side represents an arbitrary fixed point (not necessarily the least
   906 $\textit{even}'~(n - 2)$.
   893 one). It is used to falsify $\textit{even}'~n$. In contrast, the unrolled
       
   894 predicate is used to satisfy $\textit{even}'~(n - 2)$.
   907 
   895 
   908 Coinductive predicates are handled dually. For example:
   896 Coinductive predicates are handled dually. For example:
   909 
   897 
   910 \prew
   898 \prew
   911 \textbf{coinductive} \textit{nats} \textbf{where} \\
   899 \textbf{coinductive} \textit{nats} \textbf{where} \\
   913 \textbf{lemma} ``$\textit{nats} = (\lambda n.\; n \mathbin\in \{0, 1, 2, 3, 4\})$'' \\
   901 \textbf{lemma} ``$\textit{nats} = (\lambda n.\; n \mathbin\in \{0, 1, 2, 3, 4\})$'' \\
   914 \textbf{nitpick}~[\textit{card nat} = 10,\, \textit{show\_consts}] \\[2\smallskipamount]
   902 \textbf{nitpick}~[\textit{card nat} = 10,\, \textit{show\_consts}] \\[2\smallskipamount]
   915 \slshape Nitpick found a counterexample:
   903 \slshape Nitpick found a counterexample:
   916 \\[2\smallskipamount]
   904 \\[2\smallskipamount]
   917 \hbox{}\qquad Constants: \nopagebreak \\
   905 \hbox{}\qquad Constants: \nopagebreak \\
   918 \hbox{}\qquad\qquad $\lambda i.\; \textit{nats} = \undef(0 := \{\!\begin{aligned}[t]
   906 \hbox{}\qquad\qquad $\lambda i.\; \textit{nats} = \unkef(0 := \unkef,\, 1 := \unkef,\, 2 := \unkef)$ \\
   919 & 0^\Q, 1^\Q, 2^\Q, 3^\Q, 4^\Q, 5^\Q, 6^\Q, 7^\Q, 8^\Q, 9^\Q, \\[-2pt]
   907 \hbox{}\qquad\qquad $\textit{nats} \geq \unkef(3 := \textit{True},\, 4 := \textit{False},\, 5 := \textit{True})$
   920 & \unr\})\end{aligned}$ \\
       
   921 \hbox{}\qquad\qquad $nats \supseteq \{9, 5^\Q, 6^\Q, 7^\Q, 8^\Q, \unr\}$
       
   922 \postw
   908 \postw
   923 
   909 
   924 As a special case, Nitpick uses Kodkod's transitive closure operator to encode
   910 As a special case, Nitpick uses Kodkod's transitive closure operator to encode
   925 negative occurrences of non-well-founded ``linear inductive predicates,'' i.e.,
   911 negative occurrences of non-well-founded ``linear inductive predicates,'' i.e.,
   926 inductive predicates for which each the predicate occurs in at most one
   912 inductive predicates for which each the predicate occurs in at most one
   929 \prew
   915 \prew
   930 \textbf{inductive} \textit{odd} \textbf{where} \\
   916 \textbf{inductive} \textit{odd} \textbf{where} \\
   931 ``$\textit{odd}~1$'' $\,\mid$ \\
   917 ``$\textit{odd}~1$'' $\,\mid$ \\
   932 ``$\lbrakk \textit{odd}~m;\>\, \textit{even}~n\rbrakk \,\Longrightarrow\, \textit{odd}~(m + n)$'' \\[2\smallskipamount]
   918 ``$\lbrakk \textit{odd}~m;\>\, \textit{even}~n\rbrakk \,\Longrightarrow\, \textit{odd}~(m + n)$'' \\[2\smallskipamount]
   933 \textbf{lemma}~``$\textit{odd}~n \,\Longrightarrow\, \textit{odd}~(n - 2)$'' \\
   919 \textbf{lemma}~``$\textit{odd}~n \,\Longrightarrow\, \textit{odd}~(n - 2)$'' \\
   934 \textbf{nitpick}~[\textit{card nat} = 10,\, \textit{show\_consts}] \\[2\smallskipamount]
   920 \textbf{nitpick}~[\textit{card nat} = 4,\, \textit{show\_consts}] \\[2\smallskipamount]
   935 \slshape Nitpick found a counterexample:
   921 \slshape Nitpick found a counterexample:
   936 \\[2\smallskipamount]
   922 \\[2\smallskipamount]
   937 \hbox{}\qquad Free variable: \nopagebreak \\
   923 \hbox{}\qquad Free variable: \nopagebreak \\
   938 \hbox{}\qquad\qquad $n = 1$ \\
   924 \hbox{}\qquad\qquad $n = 1$ \\
   939 \hbox{}\qquad Constants: \nopagebreak \\
   925 \hbox{}\qquad Constants: \nopagebreak \\
   940 \hbox{}\qquad\qquad $\textit{even} = \{0, 2, 4, 6, 8, \unr\}$ \\
   926 \hbox{}\qquad\qquad $\textit{even} = (λx. ?)(0 := True, 1 := False, 2 := True, 3 := False)$ \\
   941 \hbox{}\qquad\qquad $\textit{odd}_{\textsl{base}} = \{1, \unr\}$ \\
   927 \hbox{}\qquad\qquad $\textit{odd}_{\textsl{base}} = {}$ \\
   942 \hbox{}\qquad\qquad $\textit{odd}_{\textsl{step}} = \!
   928 \hbox{}\qquad\qquad\quad $\unkef(0 := \textit{False},\, 1 := \textit{True},\, 2 := \textit{False},\, 3 := \textit{False})$ \\
       
   929 \hbox{}\qquad\qquad $\textit{odd}_{\textsl{step}} = \unkef$\\
       
   930 \hbox{}\qquad\qquad\quad $(
   943 \!\begin{aligned}[t]
   931 \!\begin{aligned}[t]
   944   & \{(0, 0), (0, 2), (0, 4), (0, 6), (0, 8), (1, 1), (1, 3), (1, 5), \\[-2pt]
   932 & 0 := \unkef(0 := \textit{True},\, 1 := \textit{False},\, 2 := \textit{True},\, 3 := \textit{False}), \\[-2pt]
   945   & \phantom{\{} (1, 7), (1, 9), (2, 2), (2, 4), (2, 6), (2, 8), (3, 3),
   933 & 1 := \unkef(0 := \textit{False},\, 1 := \textit{True},\, 2 := \textit{False},\, 3 := \textit{True}), \\[-2pt]
   946        (3, 5), \\[-2pt]
   934 & 2 := \unkef(0 := \textit{False},\, 1 := \textit{False},\, 2 := \textit{True},\, 3 := \textit{False}), \\[-2pt]
   947   & \phantom{\{} (3, 7), (3, 9), (4, 4), (4, 6), (4, 8), (5, 5), (5, 7), (5, 9), \\[-2pt]
   935 & 3 := \unkef(0 := \textit{False},\, 1 := \textit{False},\, 2 := \textit{False},\, 3 := \textit{True}))
   948   & \phantom{\{} (6, 6), (6, 8), (7, 7), (7, 9), (8, 8), (9, 9), \unr\}\end{aligned}$ \\
   936 \end{aligned}$ \\
   949 \hbox{}\qquad\qquad $\textit{odd} \subseteq \{1, 3, 5, 7, 9, 8^\Q, \unr\}$
   937 \hbox{}\qquad\qquad $\textit{odd} \leq \unkef(0 := \textit{False},\, 1 := \textit{True},\, 2 := \textit{False},\, 3 := \textit{True})$
   950 \postw
   938 \postw
   951 
   939 
   952 \noindent
   940 \noindent
   953 In the output, $\textit{odd}_{\textrm{base}}$ represents the base elements and
   941 In the output, $\textit{odd}_{\textrm{base}}$ represents the base elements and
   954 $\textit{odd}_{\textrm{step}}$ is a transition relation that computes new
   942 $\textit{odd}_{\textrm{step}}$ is a transition relation that computes new
   955 elements from known ones. The set $\textit{odd}$ consists of all the values
   943 elements from known ones. The set $\textit{odd}$ consists of all the values
   956 reachable through the reflexive transitive closure of
   944 reachable through the reflexive transitive closure of
   957 $\textit{odd}_{\textrm{step}}$ starting with any element from
   945 $\textit{odd}_{\textrm{step}}$ starting with any element from
   958 $\textit{odd}_{\textrm{base}}$, namely 1, 3, 5, 7, and 9. Using Kodkod's
   946 $\textit{odd}_{\textrm{base}}$, namely 1 and 3. Using Kodkod's
   959 transitive closure to encode linear predicates is normally either more thorough
   947 transitive closure to encode linear predicates is normally either more thorough
   960 or more efficient than unrolling (depending on the value of \textit{iter}), but
   948 or more efficient than unrolling (depending on the value of \textit{iter}), but
   961 for those cases where it isn't you can disable it by passing the
   949 you can disable it by passing the \textit{dont\_star\_linear\_preds} option.
   962 \textit{dont\_star\_linear\_preds} option.
       
   963 
   950 
   964 \subsection{Coinductive Datatypes}
   951 \subsection{Coinductive Datatypes}
   965 \label{coinductive-datatypes}
   952 \label{coinductive-datatypes}
   966 
   953 
   967 While Isabelle regrettably lacks a high-level mechanism for defining coinductive
   954 While Isabelle regrettably lacks a high-level mechanism for defining coinductive
   983 Although it is otherwise no friend of infinity, Nitpick can find counterexamples
   970 Although it is otherwise no friend of infinity, Nitpick can find counterexamples
   984 involving cyclic lists such as \textit{ps} and \textit{qs} above as well as
   971 involving cyclic lists such as \textit{ps} and \textit{qs} above as well as
   985 finite lists:
   972 finite lists:
   986 
   973 
   987 \prew
   974 \prew
   988 \textbf{lemma} ``$\textit{xs} \not= \textit{LCons}~a~\textit{xs}$'' \\
   975 \textbf{lemma} ``$\textit{xs} \not= \textit{LCons}~a~\textit{xs\/}$'' \\
   989 \textbf{nitpick} \\[2\smallskipamount]
   976 \textbf{nitpick} \\[2\smallskipamount]
   990 \slshape Nitpick found a counterexample for {\itshape card}~$'a$ = 1: \\[2\smallskipamount]
   977 \slshape Nitpick found a counterexample for {\itshape card}~$'a$ = 1: \\[2\smallskipamount]
   991 \hbox{}\qquad Free variables: \nopagebreak \\
   978 \hbox{}\qquad Free variables: \nopagebreak \\
   992 \hbox{}\qquad\qquad $\textit{a} = a_1$ \\
   979 \hbox{}\qquad\qquad $\textit{a} = a_1$ \\
   993 \hbox{}\qquad\qquad $\textit{xs} = \textsl{THE}~\omega.\; \omega = \textit{LCons}~a_1~\omega$
   980 \hbox{}\qquad\qquad $\textit{xs} = \textsl{THE}~\omega.\; \omega = \textit{LCons}~a_1~\omega$
   999 
   986 
  1000 The next example is more interesting:
   987 The next example is more interesting:
  1001 
   988 
  1002 \prew
   989 \prew
  1003 \textbf{lemma}~``$\lbrakk\textit{xs} = \textit{LCons}~a~\textit{xs};\>\,
   990 \textbf{lemma}~``$\lbrakk\textit{xs} = \textit{LCons}~a~\textit{xs};\>\,
  1004 \textit{ys} = \textit{iterates}~(\lambda b.\> a)~b\rbrakk \,\Longrightarrow\, \textit{xs} = \textit{ys}$'' \\
   991 \textit{ys} = \textit{iterates}~(\lambda b.\> a)~b\rbrakk \,\Longrightarrow\, \textit{xs} = \textit{ys\/}$'' \\
  1005 \textbf{nitpick} [\textit{verbose}] \\[2\smallskipamount]
   992 \textbf{nitpick} [\textit{verbose}] \\[2\smallskipamount]
  1006 \slshape The type ``\kern1pt$'a$'' passed the monotonicity test. Nitpick might be able to skip
   993 \slshape The type $'a$ passed the monotonicity test. Nitpick might be able to skip
  1007 some scopes. \\[2\smallskipamount]
   994 some scopes. \\[2\smallskipamount]
  1008 Trying 10 scopes: \\
   995 Trying 10 scopes: \\
  1009 \hbox{}\qquad \textit{card} $'a$~= 1, \textit{card} ``\kern1pt$'a~\textit{list\/}$''~= 1,
   996 \hbox{}\qquad \textit{card} $'a$~= 1, \textit{card} ``\kern1pt$'a~\textit{list\/}$''~= 1,
  1010 and \textit{bisim\_depth}~= 0. \\
   997 and \textit{bisim\_depth}~= 0. \\
  1011 \hbox{}\qquad $\qquad\vdots$ \\[.5\smallskipamount]
   998 \hbox{}\qquad $\qquad\vdots$ \\[.5\smallskipamount]
  1012 \hbox{}\qquad \textit{card} $'a$~= 10, \textit{card} ``\kern1pt$'a~\textit{list\/}$''~= 10,
   999 \hbox{}\qquad \textit{card} $'a$~= 10, \textit{card} ``\kern1pt$'a~\textit{list\/}$''~= 10,
  1013 and \textit{bisim\_depth}~= 9. \\[2\smallskipamount]
  1000 and \textit{bisim\_depth}~= 9. \\[2\smallskipamount]
       
  1001 Limit reached: arity 11 of Kodkod relation associated with
       
  1002 ``\textit{Set.insert\/}'' too large for universe of cardinality 9. Skipping scope.
       
  1003 \\[2\smallskipamount]
  1014 Nitpick found a counterexample for {\itshape card}~$'a$ = 2,
  1004 Nitpick found a counterexample for {\itshape card}~$'a$ = 2,
  1015 \textit{card}~``\kern1pt$'a~\textit{list\/}$''~= 2, and \textit{bisim\_\allowbreak
  1005 \textit{card}~``\kern1pt$'a~\textit{llist\/}$''~= 2, and \textit{bisim\_\allowbreak
  1016 depth}~= 1:
  1006 depth}~= 1:
  1017 \\[2\smallskipamount]
  1007 \\[2\smallskipamount]
  1018 \hbox{}\qquad Free variables: \nopagebreak \\
  1008 \hbox{}\qquad Free variables: \nopagebreak \\
  1019 \hbox{}\qquad\qquad $\textit{a} = a_1$ \\
  1009 \hbox{}\qquad\qquad $\textit{a} = a_1$ \\
  1020 \hbox{}\qquad\qquad $\textit{b} = a_2$ \\
  1010 \hbox{}\qquad\qquad $\textit{b} = a_2$ \\
  1021 \hbox{}\qquad\qquad $\textit{xs} = \textsl{THE}~\omega.\; \omega = \textit{LCons}~a_1~\omega$ \\
  1011 \hbox{}\qquad\qquad $\textit{xs} = \textsl{THE}~\omega.\; \omega = \textit{LCons}~a_1~\omega$ \\
  1022 \hbox{}\qquad\qquad $\textit{ys} = \textit{LCons}~a_2~(\textsl{THE}~\omega.\; \omega = \textit{LCons}~a_1~\omega)$ \\[2\smallskipamount]
  1012 \hbox{}\qquad\qquad $\textit{ys} = \textit{LCons}~a_2~(\textsl{THE}~\omega.\; \omega = \textit{LCons}~a_1~\omega)$ \\[2\smallskipamount]
  1023 Total time: 1.02 s.
  1013 Total time: 1.11 s.
  1024 \postw
  1014 \postw
  1025 
  1015 
  1026 The lazy list $\textit{xs}$ is simply $[a_1, a_1, a_1, \ldots]$, whereas
  1016 The lazy list $\textit{xs}$ is simply $[a_1, a_1, a_1, \ldots]$, whereas
  1027 $\textit{ys}$ is $[a_2, a_1, a_1, a_1, \ldots]$, i.e., a lasso-shaped list with
  1017 $\textit{ys}$ is $[a_2, a_1, a_1, a_1, \ldots]$, i.e., a lasso-shaped list with
  1028 $[a_2]$ as its stem and $[a_1]$ as its cycle. In general, the list segment
  1018 $[a_2]$ as its stem and $[a_1]$ as its cycle. In general, the list segment
  1054 The next formula illustrates the need for bisimilarity (either as a Kodkod
  1044 The next formula illustrates the need for bisimilarity (either as a Kodkod
  1055 predicate or as an after-the-fact check) to prevent spurious counterexamples:
  1045 predicate or as an after-the-fact check) to prevent spurious counterexamples:
  1056 
  1046 
  1057 \prew
  1047 \prew
  1058 \textbf{lemma} ``$\lbrakk xs = \textit{LCons}~a~\textit{xs};\>\, \textit{ys} = \textit{LCons}~a~\textit{ys}\rbrakk
  1048 \textbf{lemma} ``$\lbrakk xs = \textit{LCons}~a~\textit{xs};\>\, \textit{ys} = \textit{LCons}~a~\textit{ys}\rbrakk
  1059 \,\Longrightarrow\, \textit{xs} = \textit{ys}$'' \\
  1049 \,\Longrightarrow\, \textit{xs} = \textit{ys\/}$'' \\
  1060 \textbf{nitpick} [\textit{bisim\_depth} = $-1$, \textit{show\_datatypes}] \\[2\smallskipamount]
  1050 \textbf{nitpick} [\textit{bisim\_depth} = $-1$, \textit{show\_datatypes}] \\[2\smallskipamount]
  1061 \slshape Nitpick found a quasi genuine counterexample for $\textit{card}~'a$ = 2: \\[2\smallskipamount]
  1051 \slshape Nitpick found a quasi genuine counterexample for $\textit{card}~'a$ = 2: \\[2\smallskipamount]
  1062 \hbox{}\qquad Free variables: \nopagebreak \\
  1052 \hbox{}\qquad Free variables: \nopagebreak \\
  1063 \hbox{}\qquad\qquad $a = a_1$ \\
  1053 \hbox{}\qquad\qquad $a = a_1$ \\
  1064 \hbox{}\qquad\qquad $\textit{xs} = \textsl{THE}~\omega.\; \omega =
  1054 \hbox{}\qquad\qquad $\textit{xs} = \textsl{THE}~\omega.\; \omega =
  1151 \pre
  1141 \pre
  1152 \textbf{lemma}~``$\lnot\,\textit{loose}~t~0 \,\Longrightarrow\, \textit{subst}~\sigma~t = t$'' \\
  1142 \textbf{lemma}~``$\lnot\,\textit{loose}~t~0 \,\Longrightarrow\, \textit{subst}~\sigma~t = t$'' \\
  1153 \textbf{nitpick} [\textit{verbose}] \\[2\smallskipamount]
  1143 \textbf{nitpick} [\textit{verbose}] \\[2\smallskipamount]
  1154 \slshape
  1144 \slshape
  1155 Trying 10 scopes: \nopagebreak \\
  1145 Trying 10 scopes: \nopagebreak \\
  1156 \hbox{}\qquad \textit{card~nat}~= 1, \textit{card tm}~= 1, and \textit{card} ``$\textit{nat} \Rightarrow \textit{tm}$'' = 1; \\
  1146 \hbox{}\qquad \textit{card~nat}~= 1, \textit{card tm}~= 1, and \textit{card} ``$\textit{nat} \Rightarrow \textit{tm\/}$'' = 1; \\
  1157 \hbox{}\qquad \textit{card~nat}~= 2, \textit{card tm}~= 2, and \textit{card} ``$\textit{nat} \Rightarrow \textit{tm}$'' = 2; \\
  1147 \hbox{}\qquad \textit{card~nat}~= 2, \textit{card tm}~= 2, and \textit{card} ``$\textit{nat} \Rightarrow \textit{tm\/}$'' = 2; \\
  1158 \hbox{}\qquad $\qquad\vdots$ \\[.5\smallskipamount]
  1148 \hbox{}\qquad $\qquad\vdots$ \\[.5\smallskipamount]
  1159 \hbox{}\qquad \textit{card~nat}~= 10, \textit{card tm}~= 10, and \textit{card} ``$\textit{nat} \Rightarrow \textit{tm}$'' = 10. \\[2\smallskipamount]
  1149 \hbox{}\qquad \textit{card~nat}~= 10, \textit{card tm}~= 10, and \textit{card} ``$\textit{nat} \Rightarrow \textit{tm\/}$'' = 10. \\[2\smallskipamount]
  1160 Nitpick found a counterexample for \textit{card~nat}~= 6, \textit{card~tm}~= 6,
  1150 Nitpick found a counterexample for \textit{card~nat}~= 6, \textit{card~tm}~= 6,
  1161 and \textit{card}~``$\textit{nat} \Rightarrow \textit{tm}$''~= 6: \\[2\smallskipamount]
  1151 and \textit{card}~``$\textit{nat} \Rightarrow \textit{tm\/}$''~= 6: \\[2\smallskipamount]
  1162 \hbox{}\qquad Free variables: \nopagebreak \\
  1152 \hbox{}\qquad Free variables: \nopagebreak \\
  1163 \hbox{}\qquad\qquad $\sigma = \undef(\!\begin{aligned}[t]
  1153 \hbox{}\qquad\qquad $\sigma = \unkef(\!\begin{aligned}[t]
  1164 & 0 := \textit{Var}~0,\>
  1154 & 0 := \textit{Var}~0,\>
  1165   1 := \textit{Var}~0,\>
  1155   1 := \textit{Var}~0,\>
  1166   2 := \textit{Var}~0, \\[-2pt]
  1156   2 := \textit{Var}~0, \\[-2pt]
  1167 & 3 := \textit{Var}~0,\>
  1157 & 3 := \textit{Var}~0,\>
  1168   4 := \textit{Var}~0,\>
  1158   4 := \textit{Var}~0,\>
  1179 replaced with $\textit{lift}~(\sigma~m)~0$.
  1169 replaced with $\textit{lift}~(\sigma~m)~0$.
  1180 
  1170 
  1181 An interesting aspect of Nitpick's verbose output is that it assigned inceasing
  1171 An interesting aspect of Nitpick's verbose output is that it assigned inceasing
  1182 cardinalities from 1 to 10 to the type $\textit{nat} \Rightarrow \textit{tm}$.
  1172 cardinalities from 1 to 10 to the type $\textit{nat} \Rightarrow \textit{tm}$.
  1183 For the formula of interest, knowing 6 values of that type was enough to find
  1173 For the formula of interest, knowing 6 values of that type was enough to find
  1184 the counterexample. Without boxing, $46\,656$ ($= 6^6$) values must be
  1174 the counterexample. Without boxing, $6^6 = 46\,656$ values must be
  1185 considered, a hopeless undertaking:
  1175 considered, a hopeless undertaking:
  1186 
  1176 
  1187 \prew
  1177 \prew
  1188 \textbf{nitpick} [\textit{dont\_box}] \\[2\smallskipamount]
  1178 \textbf{nitpick} [\textit{dont\_box}] \\[2\smallskipamount]
  1189 {\slshape Nitpick ran out of time after checking 3 of 10 scopes.}
  1179 {\slshape Nitpick ran out of time after checking 3 of 10 scopes.}
  1190 \postw
  1180 \postw
  1191 
  1181 
  1192 {\looseness=-1
       
  1193 Boxing can be enabled or disabled globally or on a per-type basis using the
  1182 Boxing can be enabled or disabled globally or on a per-type basis using the
  1194 \textit{box} option. Nitpick usually performs reasonable choices about which
  1183 \textit{box} option. Nitpick usually performs reasonable choices about which
  1195 types should be boxed, but option tweaking sometimes helps. A related optimization,
  1184 types should be boxed, but option tweaking sometimes helps.
  1196 ``finalization,'' attempts to wrap functions that constant at all but finitely
  1185 
  1197 many points (e.g., finite sets); see the documentation for the \textit{finalize}
  1186 %A related optimization,
  1198 option in \S\ref{scope-of-search} for details.
  1187 %``finitization,'' attempts to wrap functions that are constant at all but finitely
  1199 
  1188 %many points (e.g., finite sets); see the documentation for the \textit{finitize}
  1200 }
  1189 %option in \S\ref{scope-of-search} for details.
  1201 
  1190 
  1202 \subsection{Scope Monotonicity}
  1191 \subsection{Scope Monotonicity}
  1203 \label{scope-monotonicity}
  1192 \label{scope-monotonicity}
  1204 
  1193 
  1205 The \textit{card} option (together with \textit{iter}, \textit{bisim\_depth},
  1194 The \textit{card} option (together with \textit{iter}, \textit{bisim\_depth},
  1231 definitions:
  1220 definitions:
  1232 
  1221 
  1233 \prew
  1222 \prew
  1234 \textbf{nitpick}~[\textit{verbose}] \\[2\smallskipamount]
  1223 \textbf{nitpick}~[\textit{verbose}] \\[2\smallskipamount]
  1235 \slshape
  1224 \slshape
  1236 The types ``\kern1pt$'a$'' and ``\kern1pt$'b$'' passed the monotonicity test.
  1225 The types $'a$ and $'b$ passed the monotonicity test.
  1237 Nitpick might be able to skip some scopes.
  1226 Nitpick might be able to skip some scopes.
  1238  \\[2\smallskipamount]
  1227  \\[2\smallskipamount]
  1239 Trying 10 scopes: \\
  1228 Trying 10 scopes: \\
  1240 \hbox{}\qquad \textit{card} $'a$~= 1, \textit{card} $'b$~= 1,
  1229 \hbox{}\qquad \textit{card} $'a$~= 1, \textit{card} $'b$~= 1,
  1241 \textit{card} \textit{nat}~= 1, \textit{card} ``$('a \times {'}b)$
  1230 \textit{card} \textit{nat}~= 1, \textit{card} ``$('a \times {'}b)$
  1445 \hbox{}\qquad\qquad $t = \xi_1$ \\
  1434 \hbox{}\qquad\qquad $t = \xi_1$ \\
  1446 \hbox{}\qquad\qquad $u = \xi_2$ \\
  1435 \hbox{}\qquad\qquad $u = \xi_2$ \\
  1447 \hbox{}\qquad Datatype: \nopagebreak \\
  1436 \hbox{}\qquad Datatype: \nopagebreak \\
  1448 \hbox{}\qquad\qquad $\alpha~\textit{btree} = \{\xi_1 \mathbin{=} \textit{Branch}~\xi_1~\xi_1,\> \xi_2 \mathbin{=} \textit{Branch}~\xi_2~\xi_2,\> \textit{Branch}~\xi_1~\xi_2\}$ \\
  1437 \hbox{}\qquad\qquad $\alpha~\textit{btree} = \{\xi_1 \mathbin{=} \textit{Branch}~\xi_1~\xi_1,\> \xi_2 \mathbin{=} \textit{Branch}~\xi_2~\xi_2,\> \textit{Branch}~\xi_1~\xi_2\}$ \\
  1449 \hbox{}\qquad {\slshape Constants:} \nopagebreak \\
  1438 \hbox{}\qquad {\slshape Constants:} \nopagebreak \\
  1450 \hbox{}\qquad\qquad $\textit{labels} = \undef
  1439 \hbox{}\qquad\qquad $\textit{labels} = \unkef
  1451     (\!\begin{aligned}[t]%
  1440     (\!\begin{aligned}[t]%
  1452     & \xi_1 := \{a_2, a_3\},\> \xi_2 := \{a_1\},\> \\[-2pt]
  1441     & \xi_1 := \{a_2, a_3\},\> \xi_2 := \{a_1\},\> \\[-2pt]
  1453     & \textit{Branch}~\xi_1~\xi_2 := \{a_1, a_2, a_3\})\end{aligned}$ \\
  1442     & \textit{Branch}~\xi_1~\xi_2 := \{a_1, a_2, a_3\})\end{aligned}$ \\
  1454 \hbox{}\qquad\qquad $\lambda x_1.\> \textit{swap}~x_1~a~b = \undef
  1443 \hbox{}\qquad\qquad $\lambda x_1.\> \textit{swap}~x_1~a~b = \unkef
  1455     (\!\begin{aligned}[t]%
  1444     (\!\begin{aligned}[t]%
  1456     & \xi_1 := \xi_2,\> \xi_2 := \xi_2, \\[-2pt]
  1445     & \xi_1 := \xi_2,\> \xi_2 := \xi_2, \\[-2pt]
  1457     & \textit{Branch}~\xi_1~\xi_2 := \xi_2)\end{aligned}$ \\[2\smallskipamount]
  1446     & \textit{Branch}~\xi_1~\xi_2 := \xi_2)\end{aligned}$ \\[2\smallskipamount]
  1458 The existence of a nonstandard model suggests that the induction hypothesis is not general enough or may even
  1447 The existence of a nonstandard model suggests that the induction hypothesis is not general enough or may even
  1459 be wrong. See the Nitpick manual's ``Inductive Properties'' section for details (``\textit{isabelle doc nitpick}'').
  1448 be wrong. See the Nitpick manual's ``Inductive Properties'' section for details (``\textit{isabelle doc nitpick}'').
  1659 a total order $<$. We start by defining the datatype and some basic extractor
  1648 a total order $<$. We start by defining the datatype and some basic extractor
  1660 functions:
  1649 functions:
  1661 
  1650 
  1662 \prew
  1651 \prew
  1663 \textbf{datatype} $'a$~\textit{aa\_tree} = \\
  1652 \textbf{datatype} $'a$~\textit{aa\_tree} = \\
  1664 \hbox{}\quad $\Lambda$ $\mid$ $N$ ``\kern1pt$'a\Colon \textit{linorder}$'' \textit{nat} ``\kern1pt$'a$ \textit{aa\_tree}'' ``\kern1pt$'a$ \textit{aa\_tree}''  \\[2\smallskipamount]
  1653 \hbox{}\quad $\Lambda$ $\mid$ $N$ ``\kern1pt$'a\Colon \textit{linorder\/}$'' \textit{nat} ``\kern1pt$'a$ \textit{aa\_tree}'' ``\kern1pt$'a$ \textit{aa\_tree}''  \\[2\smallskipamount]
  1665 \textbf{primrec} \textit{data} \textbf{where} \\
  1654 \textbf{primrec} \textit{data} \textbf{where} \\
  1666 ``$\textit{data}~\Lambda = \undef$'' $\,\mid$ \\
  1655 ``$\textit{data}~\Lambda = \unkef$'' $\,\mid$ \\
  1667 ``$\textit{data}~(N~x~\_~\_~\_) = x$'' \\[2\smallskipamount]
  1656 ``$\textit{data}~(N~x~\_~\_~\_) = x$'' \\[2\smallskipamount]
  1668 \textbf{primrec} \textit{dataset} \textbf{where} \\
  1657 \textbf{primrec} \textit{dataset} \textbf{where} \\
  1669 ``$\textit{dataset}~\Lambda = \{\}$'' $\,\mid$ \\
  1658 ``$\textit{dataset}~\Lambda = \{\}$'' $\,\mid$ \\
  1670 ``$\textit{dataset}~(N~x~\_~t~u) = \{x\} \cup \textit{dataset}~t \mathrel{\cup} \textit{dataset}~u$'' \\[2\smallskipamount]
  1659 ``$\textit{dataset}~(N~x~\_~t~u) = \{x\} \cup \textit{dataset}~t \mathrel{\cup} \textit{dataset}~u$'' \\[2\smallskipamount]
  1671 \textbf{primrec} \textit{level} \textbf{where} \\
  1660 \textbf{primrec} \textit{level} \textbf{where} \\
  1708 
  1697 
  1709 The \textit{wf} predicate formalizes this description:
  1698 The \textit{wf} predicate formalizes this description:
  1710 
  1699 
  1711 \prew
  1700 \prew
  1712 \textbf{primrec} \textit{wf} \textbf{where} \\
  1701 \textbf{primrec} \textit{wf} \textbf{where} \\
  1713 ``$\textit{wf}~\Lambda = \textit{True}$'' $\,\mid$ \\
  1702 ``$\textit{wf}~\Lambda = \textit{True\/}$'' $\,\mid$ \\
  1714 ``$\textit{wf}~(N~\_~k~t~u) =$ \\
  1703 ``$\textit{wf}~(N~\_~k~t~u) =$ \\
  1715 \phantom{``}$(\textrm{if}~t = \Lambda~\textrm{then}$ \\
  1704 \phantom{``}$(\textrm{if}~t = \Lambda~\textrm{then}$ \\
  1716 \phantom{``$(\quad$}$k = 1 \mathrel{\land} (u = \Lambda \mathrel{\lor} (\textit{level}~u = 1 \mathrel{\land} \textit{left}~u = \Lambda \mathrel{\land} \textit{right}~u = \Lambda))$ \\
  1705 \phantom{``$(\quad$}$k = 1 \mathrel{\land} (u = \Lambda \mathrel{\lor} (\textit{level}~u = 1 \mathrel{\land} \textit{left}~u = \Lambda \mathrel{\land} \textit{right}~u = \Lambda))$ \\
  1717 \phantom{``$($}$\textrm{else}$ \\
  1706 \phantom{``$($}$\textrm{else}$ \\
  1718 \hbox{}\phantom{``$(\quad$}$\textit{wf}~t \mathrel{\land} \textit{wf}~u
  1707 \hbox{}\phantom{``$(\quad$}$\textit{wf}~t \mathrel{\land} \textit{wf}~u
  2847 for which the function is not defined. For example:
  2836 for which the function is not defined. For example:
  2848 
  2837 
  2849 \prew
  2838 \prew
  2850 \textbf{primrec} \textit{prec} \textbf{where} \\
  2839 \textbf{primrec} \textit{prec} \textbf{where} \\
  2851 ``$\textit{prec}~(\textit{Suc}~n) = n$'' \\[2\smallskipamount]
  2840 ``$\textit{prec}~(\textit{Suc}~n) = n$'' \\[2\smallskipamount]
  2852 \textbf{lemma} ``$\textit{prec}~0 = \undef$'' \\
  2841 \textbf{lemma} ``$\textit{prec}~0 = \textit{undefined\/}$'' \\
  2853 \textbf{nitpick} \\[2\smallskipamount]
  2842 \textbf{nitpick} \\[2\smallskipamount]
  2854 \quad{\slshape Nitpick found a counterexample for \textit{card nat}~= 2:
  2843 \quad{\slshape Nitpick found a counterexample for \textit{card nat}~= 2:
  2855 \nopagebreak
  2844 \nopagebreak
  2856 \\[2\smallskipamount]
  2845 \\[2\smallskipamount]
  2857 \hbox{}\qquad Empty assignment} \nopagebreak\\[2\smallskipamount]
  2846 \hbox{}\qquad Empty assignment} \nopagebreak\\[2\smallskipamount]