593 The mandatory @{text mode} argument specifies the mode of operation |
593 The mandatory @{text mode} argument specifies the mode of operation |
594 of the command, which directly corresponds to a complete partial |
594 of the command, which directly corresponds to a complete partial |
595 order on the result type. By default, the following modes are |
595 order on the result type. By default, the following modes are |
596 defined: |
596 defined: |
597 |
597 |
598 \begin{description} |
598 \<^descr> @{text option} defines functions that map into the @{type |
599 |
|
600 \item @{text option} defines functions that map into the @{type |
|
601 option} type. Here, the value @{term None} is used to model a |
599 option} type. Here, the value @{term None} is used to model a |
602 non-terminating computation. Monotonicity requires that if @{term |
600 non-terminating computation. Monotonicity requires that if @{term |
603 None} is returned by a recursive call, then the overall result must |
601 None} is returned by a recursive call, then the overall result must |
604 also be @{term None}. This is best achieved through the use of the |
602 also be @{term None}. This is best achieved through the use of the |
605 monadic operator @{const "Option.bind"}. |
603 monadic operator @{const "Option.bind"}. |
606 |
604 |
607 \item @{text tailrec} defines functions with an arbitrary result |
605 \<^descr> @{text tailrec} defines functions with an arbitrary result |
608 type and uses the slightly degenerated partial order where @{term |
606 type and uses the slightly degenerated partial order where @{term |
609 "undefined"} is the bottom element. Now, monotonicity requires that |
607 "undefined"} is the bottom element. Now, monotonicity requires that |
610 if @{term undefined} is returned by a recursive call, then the |
608 if @{term undefined} is returned by a recursive call, then the |
611 overall result must also be @{term undefined}. In practice, this is |
609 overall result must also be @{term undefined}. In practice, this is |
612 only satisfied when each recursive call is a tail call, whose result |
610 only satisfied when each recursive call is a tail call, whose result |
613 is directly returned. Thus, this mode of operation allows the |
611 is directly returned. Thus, this mode of operation allows the |
614 definition of arbitrary tail-recursive functions. |
612 definition of arbitrary tail-recursive functions. |
615 |
|
616 \end{description} |
|
617 |
613 |
618 Experienced users may define new modes by instantiating the locale |
614 Experienced users may define new modes by instantiating the locale |
619 @{const "partial_function_definitions"} appropriately. |
615 @{const "partial_function_definitions"} appropriately. |
620 |
616 |
621 \<^descr> @{attribute (HOL) partial_function_mono} declares rules for |
617 \<^descr> @{attribute (HOL) partial_function_mono} declares rules for |
1876 fixed number of random assignments in the search space, or exploring |
1864 fixed number of random assignments in the search space, or exploring |
1877 the search space symbolically using narrowing. By default, |
1865 the search space symbolically using narrowing. By default, |
1878 quickcheck uses exhaustive testing. A number of configuration |
1866 quickcheck uses exhaustive testing. A number of configuration |
1879 options are supported for @{command (HOL) "quickcheck"}, notably: |
1867 options are supported for @{command (HOL) "quickcheck"}, notably: |
1880 |
1868 |
1881 \begin{description} |
1869 \<^descr>[@{text tester}] specifies which testing approach to apply. |
1882 |
|
1883 \item[@{text tester}] specifies which testing approach to apply. |
|
1884 There are three testers, @{text exhaustive}, @{text random}, and |
1870 There are three testers, @{text exhaustive}, @{text random}, and |
1885 @{text narrowing}. An unknown configuration option is treated as |
1871 @{text narrowing}. An unknown configuration option is treated as |
1886 an argument to tester, making @{text "tester ="} optional. When |
1872 an argument to tester, making @{text "tester ="} optional. When |
1887 multiple testers are given, these are applied in parallel. If no |
1873 multiple testers are given, these are applied in parallel. If no |
1888 tester is specified, quickcheck uses the testers that are set |
1874 tester is specified, quickcheck uses the testers that are set |
1889 active, i.e.\ configurations @{attribute |
1875 active, i.e.\ configurations @{attribute |
1890 quickcheck_exhaustive_active}, @{attribute |
1876 quickcheck_exhaustive_active}, @{attribute |
1891 quickcheck_random_active}, @{attribute |
1877 quickcheck_random_active}, @{attribute |
1892 quickcheck_narrowing_active} are set to true. |
1878 quickcheck_narrowing_active} are set to true. |
1893 |
1879 |
1894 \item[@{text size}] specifies the maximum size of the search space |
1880 \<^descr>[@{text size}] specifies the maximum size of the search space |
1895 for assignment values. |
1881 for assignment values. |
1896 |
1882 |
1897 \item[@{text genuine_only}] sets quickcheck only to return genuine |
1883 \<^descr>[@{text genuine_only}] sets quickcheck only to return genuine |
1898 counterexample, but not potentially spurious counterexamples due |
1884 counterexample, but not potentially spurious counterexamples due |
1899 to underspecified functions. |
1885 to underspecified functions. |
1900 |
1886 |
1901 \item[@{text abort_potential}] sets quickcheck to abort once it |
1887 \<^descr>[@{text abort_potential}] sets quickcheck to abort once it |
1902 found a potentially spurious counterexample and to not continue |
1888 found a potentially spurious counterexample and to not continue |
1903 to search for a further genuine counterexample. |
1889 to search for a further genuine counterexample. |
1904 For this option to be effective, the @{text genuine_only} option |
1890 For this option to be effective, the @{text genuine_only} option |
1905 must be set to false. |
1891 must be set to false. |
1906 |
1892 |
1907 \item[@{text eval}] takes a term or a list of terms and evaluates |
1893 \<^descr>[@{text eval}] takes a term or a list of terms and evaluates |
1908 these terms under the variable assignment found by quickcheck. |
1894 these terms under the variable assignment found by quickcheck. |
1909 This option is currently only supported by the default |
1895 This option is currently only supported by the default |
1910 (exhaustive) tester. |
1896 (exhaustive) tester. |
1911 |
1897 |
1912 \item[@{text iterations}] sets how many sets of assignments are |
1898 \<^descr>[@{text iterations}] sets how many sets of assignments are |
1913 generated for each particular size. |
1899 generated for each particular size. |
1914 |
1900 |
1915 \item[@{text no_assms}] specifies whether assumptions in |
1901 \<^descr>[@{text no_assms}] specifies whether assumptions in |
1916 structured proofs should be ignored. |
1902 structured proofs should be ignored. |
1917 |
1903 |
1918 \item[@{text locale}] specifies how to process conjectures in |
1904 \<^descr>[@{text locale}] specifies how to process conjectures in |
1919 a locale context, i.e.\ they can be interpreted or expanded. |
1905 a locale context, i.e.\ they can be interpreted or expanded. |
1920 The option is a whitespace-separated list of the two words |
1906 The option is a whitespace-separated list of the two words |
1921 @{text interpret} and @{text expand}. The list determines the |
1907 @{text interpret} and @{text expand}. The list determines the |
1922 order they are employed. The default setting is to first use |
1908 order they are employed. The default setting is to first use |
1923 interpretations and then test the expanded conjecture. |
1909 interpretations and then test the expanded conjecture. |
1924 The option is only provided as attribute declaration, but not |
1910 The option is only provided as attribute declaration, but not |
1925 as parameter to the command. |
1911 as parameter to the command. |
1926 |
1912 |
1927 \item[@{text timeout}] sets the time limit in seconds. |
1913 \<^descr>[@{text timeout}] sets the time limit in seconds. |
1928 |
1914 |
1929 \item[@{text default_type}] sets the type(s) generally used to |
1915 \<^descr>[@{text default_type}] sets the type(s) generally used to |
1930 instantiate type variables. |
1916 instantiate type variables. |
1931 |
1917 |
1932 \item[@{text report}] if set quickcheck reports how many tests |
1918 \<^descr>[@{text report}] if set quickcheck reports how many tests |
1933 fulfilled the preconditions. |
1919 fulfilled the preconditions. |
1934 |
1920 |
1935 \item[@{text use_subtype}] if set quickcheck automatically lifts |
1921 \<^descr>[@{text use_subtype}] if set quickcheck automatically lifts |
1936 conjectures to registered subtypes if possible, and tests the |
1922 conjectures to registered subtypes if possible, and tests the |
1937 lifted conjecture. |
1923 lifted conjecture. |
1938 |
1924 |
1939 \item[@{text quiet}] if set quickcheck does not output anything |
1925 \<^descr>[@{text quiet}] if set quickcheck does not output anything |
1940 while testing. |
1926 while testing. |
1941 |
1927 |
1942 \item[@{text verbose}] if set quickcheck informs about the current |
1928 \<^descr>[@{text verbose}] if set quickcheck informs about the current |
1943 size and cardinality while testing. |
1929 size and cardinality while testing. |
1944 |
1930 |
1945 \item[@{text expect}] can be used to check if the user's |
1931 \<^descr>[@{text expect}] can be used to check if the user's |
1946 expectation was met (@{text no_expectation}, @{text |
1932 expectation was met (@{text no_expectation}, @{text |
1947 no_counterexample}, or @{text counterexample}). |
1933 no_counterexample}, or @{text counterexample}). |
1948 |
1934 |
1949 \end{description} |
|
1950 |
|
1951 These option can be given within square brackets. |
1935 These option can be given within square brackets. |
1952 |
1936 |
1953 Using the following type classes, the testers generate values and convert |
1937 Using the following type classes, the testers generate values and convert |
1954 them back into Isabelle terms for displaying counterexamples. |
1938 them back into Isabelle terms for displaying counterexamples. |
1955 |
1939 |
1956 \begin{description} |
1940 \<^descr>[@{text exhaustive}] The parameters of the type classes @{class exhaustive} |
1957 |
1941 and @{class full_exhaustive} implement the testing. They take a |
1958 \item[@{text exhaustive}] The parameters of the type classes @{class exhaustive} |
1942 testing function as a parameter, which takes a value of type @{typ "'a"} |
1959 and @{class full_exhaustive} implement the testing. They take a |
1943 and optionally produces a counterexample, and a size parameter for the test values. |
1960 testing function as a parameter, which takes a value of type @{typ "'a"} |
1944 In @{class full_exhaustive}, the testing function parameter additionally |
1961 and optionally produces a counterexample, and a size parameter for the test values. |
1945 expects a lazy term reconstruction in the type @{typ Code_Evaluation.term} |
1962 In @{class full_exhaustive}, the testing function parameter additionally |
1946 of the tested value. |
1963 expects a lazy term reconstruction in the type @{typ Code_Evaluation.term} |
1947 |
1964 of the tested value. |
1948 The canonical implementation for @{text exhaustive} testers calls the given |
1965 |
1949 testing function on all values up to the given size and stops as soon |
1966 The canonical implementation for @{text exhaustive} testers calls the given |
1950 as a counterexample is found. |
1967 testing function on all values up to the given size and stops as soon |
1951 |
1968 as a counterexample is found. |
1952 \<^descr>[@{text random}] The operation @{const Quickcheck_Random.random} |
1969 |
1953 of the type class @{class random} generates a pseudo-random |
1970 \item[@{text random}] The operation @{const Quickcheck_Random.random} |
1954 value of the given size and a lazy term reconstruction of the value |
1971 of the type class @{class random} generates a pseudo-random |
1955 in the type @{typ Code_Evaluation.term}. A pseudo-randomness generator |
1972 value of the given size and a lazy term reconstruction of the value |
1956 is defined in theory @{theory Random}. |
1973 in the type @{typ Code_Evaluation.term}. A pseudo-randomness generator |
1957 |
1974 is defined in theory @{theory Random}. |
1958 \<^descr>[@{text narrowing}] implements Haskell's Lazy Smallcheck @{cite "runciman-naylor-lindblad"} |
1975 |
1959 using the type classes @{class narrowing} and @{class partial_term_of}. |
1976 \item[@{text narrowing}] implements Haskell's Lazy Smallcheck @{cite "runciman-naylor-lindblad"} |
1960 Variables in the current goal are initially represented as symbolic variables. |
1977 using the type classes @{class narrowing} and @{class partial_term_of}. |
1961 If the execution of the goal tries to evaluate one of them, the test engine |
1978 Variables in the current goal are initially represented as symbolic variables. |
1962 replaces it with refinements provided by @{const narrowing}. |
1979 If the execution of the goal tries to evaluate one of them, the test engine |
1963 Narrowing views every value as a sum-of-products which is expressed using the operations |
1980 replaces it with refinements provided by @{const narrowing}. |
1964 @{const Quickcheck_Narrowing.cons} (embedding a value), |
1981 Narrowing views every value as a sum-of-products which is expressed using the operations |
1965 @{const Quickcheck_Narrowing.apply} (product) and @{const Quickcheck_Narrowing.sum} (sum). |
1982 @{const Quickcheck_Narrowing.cons} (embedding a value), |
1966 The refinement should enable further evaluation of the goal. |
1983 @{const Quickcheck_Narrowing.apply} (product) and @{const Quickcheck_Narrowing.sum} (sum). |
1967 |
1984 The refinement should enable further evaluation of the goal. |
1968 For example, @{const narrowing} for the list type @{typ "'a :: narrowing list"} |
1985 |
1969 can be recursively defined as |
1986 For example, @{const narrowing} for the list type @{typ "'a :: narrowing list"} |
1970 @{term "Quickcheck_Narrowing.sum (Quickcheck_Narrowing.cons []) |
1987 can be recursively defined as |
1971 (Quickcheck_Narrowing.apply |
1988 @{term "Quickcheck_Narrowing.sum (Quickcheck_Narrowing.cons []) |
|
1989 (Quickcheck_Narrowing.apply |
1972 (Quickcheck_Narrowing.apply |
1990 (Quickcheck_Narrowing.apply |
1973 (Quickcheck_Narrowing.cons (op #)) |
1991 (Quickcheck_Narrowing.cons (op #)) |
1974 narrowing) |
1992 narrowing) |
1975 narrowing)"}. |
1993 narrowing)"}. |
1976 If a symbolic variable of type @{typ "_ list"} is evaluated, it is replaced by (i)~the empty |
1994 If a symbolic variable of type @{typ "_ list"} is evaluated, it is replaced by (i)~the empty |
1977 list @{term "[]"} and (ii)~by a non-empty list whose head and tail can then be recursively |
1995 list @{term "[]"} and (ii)~by a non-empty list whose head and tail can then be recursively |
1978 refined if needed. |
1996 refined if needed. |
1979 |
1997 |
1980 To reconstruct counterexamples, the operation @{const partial_term_of} transforms |
1998 To reconstruct counterexamples, the operation @{const partial_term_of} transforms |
1981 @{text narrowing}'s deep representation of terms to the type @{typ Code_Evaluation.term}. |
1999 @{text narrowing}'s deep representation of terms to the type @{typ Code_Evaluation.term}. |
1982 The deep representation models symbolic variables as |
2000 The deep representation models symbolic variables as |
1983 @{const Quickcheck_Narrowing.Narrowing_variable}, which are normally converted to |
2001 @{const Quickcheck_Narrowing.Narrowing_variable}, which are normally converted to |
1984 @{const Code_Evaluation.Free}, and refined values as |
2002 @{const Code_Evaluation.Free}, and refined values as |
1985 @{term "Quickcheck_Narrowing.Narrowing_constructor i args"}, where @{term "i :: integer"} |
2003 @{term "Quickcheck_Narrowing.Narrowing_constructor i args"}, where @{term "i :: integer"} |
1986 denotes the index in the sum of refinements. In the above example for lists, |
2004 denotes the index in the sum of refinements. In the above example for lists, |
1987 @{term "0"} corresponds to @{term "[]"} and @{term "1"} |
2005 @{term "0"} corresponds to @{term "[]"} and @{term "1"} |
1988 to @{term "op #"}. |
2006 to @{term "op #"}. |
1989 |
2007 |
1990 The command @{command (HOL) "code_datatype"} sets up @{const partial_term_of} |
2008 The command @{command (HOL) "code_datatype"} sets up @{const partial_term_of} |
1991 such that the @{term "i"}-th refinement is interpreted as the @{term "i"}-th constructor, |
2009 such that the @{term "i"}-th refinement is interpreted as the @{term "i"}-th constructor, |
1992 but it does not ensures consistency with @{const narrowing}. |
2010 but it does not ensures consistency with @{const narrowing}. |
|
2011 \end{description} |
|
2012 |
1993 |
2013 \<^descr> @{command (HOL) "quickcheck_params"} changes @{command (HOL) |
1994 \<^descr> @{command (HOL) "quickcheck_params"} changes @{command (HOL) |
2014 "quickcheck"} configuration options persistently. |
1995 "quickcheck"} configuration options persistently. |
2015 |
1996 |
2016 \<^descr> @{command (HOL) "quickcheck_generator"} creates random and |
1997 \<^descr> @{command (HOL) "quickcheck_generator"} creates random and |