src/HOL/Tools/Predicate_Compile/predicate_compile_quickcheck.ML
changeset 50057 57209cfbf16b
parent 45750 17100f4ce0b5
child 50093 a2886be4d615
equal deleted inserted replaced
50056:72efd6b4038d 50057:57209cfbf16b
     4 A quickcheck generator based on the predicate compiler.
     4 A quickcheck generator based on the predicate compiler.
     5 *)
     5 *)
     6 
     6 
     7 signature PREDICATE_COMPILE_QUICKCHECK =
     7 signature PREDICATE_COMPILE_QUICKCHECK =
     8 sig
     8 sig
       
     9   type seed = Random_Engine.seed
     9   (*val quickcheck : Proof.context -> term -> int -> term list option*)
    10   (*val quickcheck : Proof.context -> term -> int -> term list option*)
    10   val put_pred_result :
    11   val put_pred_result :
    11     (unit -> int -> int -> int -> int * int -> term list Predicate.pred) ->
    12     (unit -> int -> int -> int -> seed -> term list Predicate.pred) ->
    12       Proof.context -> Proof.context;
    13       Proof.context -> Proof.context;
    13   val put_dseq_result :
    14   val put_dseq_result :
    14     (unit -> int -> int -> int * int -> term list DSequence.dseq * (int * int)) ->
    15     (unit -> int -> int -> seed -> term list DSequence.dseq * seed) ->
    15       Proof.context -> Proof.context;
    16       Proof.context -> Proof.context;
    16   val put_lseq_result :
    17   val put_lseq_result :
    17     (unit -> int -> int -> int * int -> int -> term list Lazy_Sequence.lazy_sequence) ->
    18     (unit -> int -> int -> seed -> int -> term list Lazy_Sequence.lazy_sequence) ->
    18       Proof.context -> Proof.context;
    19       Proof.context -> Proof.context;
    19   val put_new_dseq_result : (unit -> int -> term list Lazy_Sequence.lazy_sequence) ->
    20   val put_new_dseq_result : (unit -> int -> term list Lazy_Sequence.lazy_sequence) ->
    20     Proof.context -> Proof.context
    21     Proof.context -> Proof.context
    21   val put_cps_result : (unit -> int -> (bool * term list) option) ->
    22   val put_cps_result : (unit -> int -> (bool * term list) option) ->
    22     Proof.context -> Proof.context
    23     Proof.context -> Proof.context
    32 structure Predicate_Compile_Quickcheck : PREDICATE_COMPILE_QUICKCHECK =
    33 structure Predicate_Compile_Quickcheck : PREDICATE_COMPILE_QUICKCHECK =
    33 struct
    34 struct
    34 
    35 
    35 open Predicate_Compile_Aux;
    36 open Predicate_Compile_Aux;
    36 
    37 
       
    38 type seed = Random_Engine.seed:
       
    39 
    37 (* FIXME just one data slot (record) per program unit *)
    40 (* FIXME just one data slot (record) per program unit *)
    38 
    41 
    39 structure Pred_Result = Proof_Data
    42 structure Pred_Result = Proof_Data
    40 (
    43 (
    41   type T = unit -> int -> int -> int -> int * int -> term list Predicate.pred
    44   type T = unit -> int -> int -> int -> seed -> term list Predicate.pred
    42   (* FIXME avoid user error with non-user text *)
    45   (* FIXME avoid user error with non-user text *)
    43   fun init _ () = error "Pred_Result"
    46   fun init _ () = error "Pred_Result"
    44 );
    47 );
    45 val put_pred_result = Pred_Result.put;
    48 val put_pred_result = Pred_Result.put;
    46 
    49 
    47 structure Dseq_Result = Proof_Data
    50 structure Dseq_Result = Proof_Data
    48 (
    51 (
    49   type T = unit -> int -> int -> int * int -> term list DSequence.dseq * (int * int)
    52   type T = unit -> int -> int -> seed -> term list DSequence.dseq * seed
    50   (* FIXME avoid user error with non-user text *)
    53   (* FIXME avoid user error with non-user text *)
    51   fun init _ () = error "Dseq_Result"
    54   fun init _ () = error "Dseq_Result"
    52 );
    55 );
    53 val put_dseq_result = Dseq_Result.put;
    56 val put_dseq_result = Dseq_Result.put;
    54 
    57 
    55 structure Lseq_Result = Proof_Data
    58 structure Lseq_Result = Proof_Data
    56 (
    59 (
    57   type T = unit -> int -> int -> int * int -> int -> term list Lazy_Sequence.lazy_sequence
    60   type T = unit -> int -> int -> seed -> int -> term list Lazy_Sequence.lazy_sequence
    58   (* FIXME avoid user error with non-user text *)
    61   (* FIXME avoid user error with non-user text *)
    59   fun init _ () = error "Lseq_Result"
    62   fun init _ () = error "Lseq_Result"
    60 );
    63 );
    61 val put_lseq_result = Lseq_Result.put;
    64 val put_lseq_result = Lseq_Result.put;
    62 
    65 
   257               Pos_Random_DSeq => mk_randompredT (HOLogic.mk_tupleT (map snd vs'))
   260               Pos_Random_DSeq => mk_randompredT (HOLogic.mk_tupleT (map snd vs'))
   258             | New_Pos_Random_DSeq => mk_new_randompredT (HOLogic.mk_tupleT (map snd vs'))
   261             | New_Pos_Random_DSeq => mk_new_randompredT (HOLogic.mk_tupleT (map snd vs'))
   259             | Pos_Generator_DSeq => mk_new_dseqT (HOLogic.mk_tupleT (map snd vs'))
   262             | Pos_Generator_DSeq => mk_new_dseqT (HOLogic.mk_tupleT (map snd vs'))
   260             | Depth_Limited_Random =>
   263             | Depth_Limited_Random =>
   261               [@{typ code_numeral}, @{typ code_numeral}, @{typ code_numeral},
   264               [@{typ code_numeral}, @{typ code_numeral}, @{typ code_numeral},
   262               @{typ "code_numeral * code_numeral"}] ---> mk_predT (HOLogic.mk_tupleT (map snd vs'))
   265               @{typ Random.seed}] ---> mk_predT (HOLogic.mk_tupleT (map snd vs'))
   263             | Pos_Generator_CPS => mk_cpsT (HOLogic.mk_tupleT (map snd vs'))
   266             | Pos_Generator_CPS => mk_cpsT (HOLogic.mk_tupleT (map snd vs'))
   264         in
   267         in
   265           Const (name, T)
   268           Const (name, T)
   266         end
   269         end
   267       else error ("Predicate Compile Quickcheck failed: " ^ commas (map string_of_mode modes))
   270       else error ("Predicate Compile Quickcheck failed: " ^ commas (map string_of_mode modes))
   281             mk_split_lambda (map Free vs') (mk_Some @{typ "bool * term list"} $
   284             mk_split_lambda (map Free vs') (mk_Some @{typ "bool * term list"} $
   282             HOLogic.mk_prod (@{term "True"}, HOLogic.mk_list @{typ term}
   285             HOLogic.mk_prod (@{term "True"}, HOLogic.mk_list @{typ term}
   283                 (map2 HOLogic.mk_term_of (map snd vs') (map Free vs'))))     
   286                 (map2 HOLogic.mk_term_of (map snd vs') (map Free vs'))))     
   284         | Depth_Limited_Random => fold_rev absdummy
   287         | Depth_Limited_Random => fold_rev absdummy
   285             [@{typ code_numeral}, @{typ code_numeral}, @{typ code_numeral},
   288             [@{typ code_numeral}, @{typ code_numeral}, @{typ code_numeral},
   286              @{typ "code_numeral * code_numeral"}]
   289              @{typ Random.seed}]
   287             (mk_bind' (list_comb (prog, map Bound (3 downto 0)),
   290             (mk_bind' (list_comb (prog, map Bound (3 downto 0)),
   288             mk_split_lambda (map Free vs') (mk_return' (HOLogic.mk_list @{typ term}
   291             mk_split_lambda (map Free vs') (mk_return' (HOLogic.mk_list @{typ term}
   289             (map2 HOLogic.mk_term_of (map snd vs') (map Free vs'))))))
   292             (map2 HOLogic.mk_term_of (map snd vs') (map Free vs'))))))
   290     val prog =
   293     val prog =
   291       case compilation of
   294       case compilation of