src/HOL/Tools/Predicate_Compile/predicate_compile_core.ML
changeset 45450 dc2236b19a3d
parent 45214 66ba67adafab
child 45452 414732ebf891
equal deleted inserted replaced
45449:eeffd04cd899 45450:dc2236b19a3d
    43   val add_equations : options -> string list -> theory -> theory
    43   val add_equations : options -> string list -> theory -> theory
    44   val add_depth_limited_random_equations : options -> string list -> theory -> theory
    44   val add_depth_limited_random_equations : options -> string list -> theory -> theory
    45   val add_random_dseq_equations : options -> string list -> theory -> theory
    45   val add_random_dseq_equations : options -> string list -> theory -> theory
    46   val add_new_random_dseq_equations : options -> string list -> theory -> theory
    46   val add_new_random_dseq_equations : options -> string list -> theory -> theory
    47   val add_generator_dseq_equations : options -> string list -> theory -> theory
    47   val add_generator_dseq_equations : options -> string list -> theory -> theory
       
    48   val add_generator_cps_equations : options -> string list -> theory -> theory
    48   val mk_tracing : string -> term -> term
    49   val mk_tracing : string -> term -> term
    49   val prepare_intrs : options -> Proof.context -> string list -> thm list ->
    50   val prepare_intrs : options -> Proof.context -> string list -> thm list ->
    50     ((string * typ) list * string list * string list * (string * mode list) list *
    51     ((string * typ) list * string list * string list * (string * mode list) list *
    51       (string *  (Term.term list * Predicate_Compile_Aux.indprem list) list) list)
    52       (string *  (Term.term list * Predicate_Compile_Aux.indprem list) list) list)
    52   type mode_analysis_options =
    53   type mode_analysis_options =
   296 
   297 
   297 val depth_limited_comp_modifiers = Comp_Mod.Comp_Modifiers
   298 val depth_limited_comp_modifiers = Comp_Mod.Comp_Modifiers
   298   {
   299   {
   299   compilation = Depth_Limited,
   300   compilation = Depth_Limited,
   300   function_name_prefix = "depth_limited_",
   301   function_name_prefix = "depth_limited_",
   301   compfuns = PredicateCompFuns.compfuns,
   302   compfuns = Predicate_Comp_Funs.compfuns,
   302   mk_random = (fn _ => error "no random generation"),
   303   mk_random = (fn _ => error "no random generation"),
   303   additional_arguments = fn names =>
   304   additional_arguments = fn names =>
   304     let
   305     let
   305       val depth_name = singleton (Name.variant_list names) "depth"
   306       val depth_name = singleton (Name.variant_list names) "depth"
   306     in [Free (depth_name, @{typ code_numeral})] end,
   307     in [Free (depth_name, @{typ code_numeral})] end,
   330 
   331 
   331 val random_comp_modifiers = Comp_Mod.Comp_Modifiers
   332 val random_comp_modifiers = Comp_Mod.Comp_Modifiers
   332   {
   333   {
   333   compilation = Random,
   334   compilation = Random,
   334   function_name_prefix = "random_",
   335   function_name_prefix = "random_",
   335   compfuns = PredicateCompFuns.compfuns,
   336   compfuns = Predicate_Comp_Funs.compfuns,
   336   mk_random = (fn T => fn additional_arguments =>
   337   mk_random = (fn T => fn additional_arguments =>
   337   list_comb (Const(@{const_name Quickcheck.iter},
   338   list_comb (Const(@{const_name Quickcheck.iter},
   338   [@{typ code_numeral}, @{typ code_numeral}, @{typ Random.seed}] ---> 
   339   [@{typ code_numeral}, @{typ code_numeral}, @{typ Random.seed}] ---> 
   339     PredicateCompFuns.mk_predT T), additional_arguments)),
   340     Predicate_Comp_Funs.mk_predT T), additional_arguments)),
   340   modify_funT = (fn T =>
   341   modify_funT = (fn T =>
   341     let
   342     let
   342       val (Ts, U) = strip_type T
   343       val (Ts, U) = strip_type T
   343       val Ts' = [@{typ code_numeral}, @{typ code_numeral}, @{typ "code_numeral * code_numeral"}]
   344       val Ts' = [@{typ code_numeral}, @{typ code_numeral}, @{typ "code_numeral * code_numeral"}]
   344     in (Ts @ Ts') ---> U end),
   345     in (Ts @ Ts') ---> U end),
   356 
   357 
   357 val depth_limited_random_comp_modifiers = Comp_Mod.Comp_Modifiers
   358 val depth_limited_random_comp_modifiers = Comp_Mod.Comp_Modifiers
   358   {
   359   {
   359   compilation = Depth_Limited_Random,
   360   compilation = Depth_Limited_Random,
   360   function_name_prefix = "depth_limited_random_",
   361   function_name_prefix = "depth_limited_random_",
   361   compfuns = PredicateCompFuns.compfuns,
   362   compfuns = Predicate_Comp_Funs.compfuns,
   362   mk_random = (fn T => fn additional_arguments =>
   363   mk_random = (fn T => fn additional_arguments =>
   363   list_comb (Const(@{const_name Quickcheck.iter},
   364   list_comb (Const(@{const_name Quickcheck.iter},
   364   [@{typ code_numeral}, @{typ code_numeral}, @{typ Random.seed}] ---> 
   365   [@{typ code_numeral}, @{typ code_numeral}, @{typ Random.seed}] ---> 
   365     PredicateCompFuns.mk_predT T), tl additional_arguments)),
   366     Predicate_Comp_Funs.mk_predT T), tl additional_arguments)),
   366   modify_funT = (fn T =>
   367   modify_funT = (fn T =>
   367     let
   368     let
   368       val (Ts, U) = strip_type T
   369       val (Ts, U) = strip_type T
   369       val Ts' = [@{typ code_numeral}, @{typ code_numeral}, @{typ code_numeral},
   370       val Ts' = [@{typ code_numeral}, @{typ code_numeral}, @{typ code_numeral},
   370         @{typ "code_numeral * code_numeral"}]
   371         @{typ "code_numeral * code_numeral"}]
   401 
   402 
   402 val predicate_comp_modifiers = Comp_Mod.Comp_Modifiers
   403 val predicate_comp_modifiers = Comp_Mod.Comp_Modifiers
   403   {
   404   {
   404   compilation = Pred,
   405   compilation = Pred,
   405   function_name_prefix = "",
   406   function_name_prefix = "",
   406   compfuns = PredicateCompFuns.compfuns,
   407   compfuns = Predicate_Comp_Funs.compfuns,
   407   mk_random = (fn _ => error "no random generation"),
   408   mk_random = (fn _ => error "no random generation"),
   408   modify_funT = I,
   409   modify_funT = I,
   409   additional_arguments = K [],
   410   additional_arguments = K [],
   410   wrap_compilation = K (K (K (K (K I))))
   411   wrap_compilation = K (K (K (K (K I))))
   411    : (compilation_funs -> string -> typ -> mode -> term list -> term -> term),
   412    : (compilation_funs -> string -> typ -> mode -> term list -> term -> term),
   414 
   415 
   415 val annotated_comp_modifiers = Comp_Mod.Comp_Modifiers
   416 val annotated_comp_modifiers = Comp_Mod.Comp_Modifiers
   416   {
   417   {
   417   compilation = Annotated,
   418   compilation = Annotated,
   418   function_name_prefix = "annotated_",
   419   function_name_prefix = "annotated_",
   419   compfuns = PredicateCompFuns.compfuns,
   420   compfuns = Predicate_Comp_Funs.compfuns,
   420   mk_random = (fn _ => error "no random generation"),
   421   mk_random = (fn _ => error "no random generation"),
   421   modify_funT = I,
   422   modify_funT = I,
   422   additional_arguments = K [],
   423   additional_arguments = K [],
   423   wrap_compilation =
   424   wrap_compilation =
   424     fn compfuns => fn s => fn T => fn mode => fn additional_arguments => fn compilation =>
   425     fn compfuns => fn s => fn T => fn mode => fn additional_arguments => fn compilation =>
   525   additional_arguments = K [],
   526   additional_arguments = K [],
   526   wrap_compilation = K (K (K (K (K I))))
   527   wrap_compilation = K (K (K (K (K I))))
   527    : (compilation_funs -> string -> typ -> mode -> term list -> term -> term),
   528    : (compilation_funs -> string -> typ -> mode -> term list -> term -> term),
   528   transform_additional_arguments = K I : (indprem -> term list -> term list)
   529   transform_additional_arguments = K I : (indprem -> term list -> term list)
   529   }
   530   }
   530 
   531   
   531 val neg_generator_dseq_comp_modifiers = Comp_Mod.Comp_Modifiers
   532 val neg_generator_dseq_comp_modifiers = Comp_Mod.Comp_Modifiers
   532   {
   533   {
   533   compilation = Neg_Generator_DSeq,
   534   compilation = Neg_Generator_DSeq,
   534   function_name_prefix = "generator_dseq_neg_",
   535   function_name_prefix = "generator_dseq_neg_",
   535   compfuns = New_Neg_DSequence_CompFuns.depth_limited_compfuns,
   536   compfuns = New_Neg_DSequence_CompFuns.depth_limited_compfuns,
   539   wrap_compilation = K (K (K (K (K I))))
   540   wrap_compilation = K (K (K (K (K I))))
   540    : (compilation_funs -> string -> typ -> mode -> term list -> term -> term),
   541    : (compilation_funs -> string -> typ -> mode -> term list -> term -> term),
   541   transform_additional_arguments = K I : (indprem -> term list -> term list)
   542   transform_additional_arguments = K I : (indprem -> term list -> term list)
   542   }
   543   }
   543 
   544 
       
   545 val pos_generator_cps_comp_modifiers = Comp_Mod.Comp_Modifiers
       
   546   {
       
   547   compilation = Pos_Generator_CPS,
       
   548   function_name_prefix = "generator_cps_pos_",
       
   549   compfuns = Pos_Bounded_CPS_Comp_Funs.compfuns,
       
   550   mk_random =
       
   551     (fn T => fn additional_arguments =>
       
   552        Const (@{const_name "Quickcheck_Exhaustive.exhaustive"},
       
   553        (T --> @{typ "term list option"}) --> @{typ "code_numeral => term list option"})),
       
   554   modify_funT = I,
       
   555   additional_arguments = K [],
       
   556   wrap_compilation = K (K (K (K (K I))))
       
   557    : (compilation_funs -> string -> typ -> mode -> term list -> term -> term),
       
   558   transform_additional_arguments = K I : (indprem -> term list -> term list)
       
   559   }  
       
   560 
       
   561 val neg_generator_cps_comp_modifiers = Comp_Mod.Comp_Modifiers
       
   562   {
       
   563   compilation = Neg_Generator_CPS,
       
   564   function_name_prefix = "generator_cps_neg_",
       
   565   compfuns = Neg_Bounded_CPS_Comp_Funs.compfuns,
       
   566   mk_random = (fn _ => error "No enumerators"),
       
   567   modify_funT = I,
       
   568   additional_arguments = K [],
       
   569   wrap_compilation = K (K (K (K (K I))))
       
   570    : (compilation_funs -> string -> typ -> mode -> term list -> term -> term),
       
   571   transform_additional_arguments = K I : (indprem -> term list -> term list)
       
   572   }
       
   573   
   544 fun negative_comp_modifiers_of comp_modifiers =
   574 fun negative_comp_modifiers_of comp_modifiers =
   545     (case Comp_Mod.compilation comp_modifiers of
   575     (case Comp_Mod.compilation comp_modifiers of
   546       Pos_Random_DSeq => neg_random_dseq_comp_modifiers
   576       Pos_Random_DSeq => neg_random_dseq_comp_modifiers
   547     | Neg_Random_DSeq => pos_random_dseq_comp_modifiers
   577     | Neg_Random_DSeq => pos_random_dseq_comp_modifiers
   548     | New_Pos_Random_DSeq => new_neg_random_dseq_comp_modifiers
   578     | New_Pos_Random_DSeq => new_neg_random_dseq_comp_modifiers
   549     | New_Neg_Random_DSeq => new_pos_random_dseq_comp_modifiers 
   579     | New_Neg_Random_DSeq => new_pos_random_dseq_comp_modifiers 
   550     | Pos_Generator_DSeq => neg_generator_dseq_comp_modifiers
   580     | Pos_Generator_DSeq => neg_generator_dseq_comp_modifiers
   551     | Neg_Generator_DSeq => pos_generator_dseq_comp_modifiers
   581     | Neg_Generator_DSeq => pos_generator_dseq_comp_modifiers
       
   582     | Pos_Generator_CPS => neg_generator_cps_comp_modifiers
       
   583     | Neg_Generator_CPS => pos_generator_cps_comp_modifiers
   552     | c => comp_modifiers)
   584     | c => comp_modifiers)
   553 
   585 
   554 (* term construction *)
   586 (* term construction *)
   555 
   587 
   556 fun mk_v (names, vs) s T = (case AList.lookup (op =) vs s of
   588 fun mk_v (names, vs) s T = (case AList.lookup (op =) vs s of
   591             (HOLogic.split_const (T1, T2, @{typ bool}) $ (mk_split_abs T1 (mk_split_abs T2 t)))
   623             (HOLogic.split_const (T1, T2, @{typ bool}) $ (mk_split_abs T1 (mk_split_abs T2 t)))
   592       | mk_split_abs T t = absdummy T t
   624       | mk_split_abs T t = absdummy T t
   593     val args = rev (fst (fold_map mk_bounds (rev (binder_types T)) 0))
   625     val args = rev (fst (fold_map mk_bounds (rev (binder_types T)) 0))
   594     val (inargs, outargs) = split_mode mode args
   626     val (inargs, outargs) = split_mode mode args
   595     val (inTs, outTs) = split_map_modeT (fn _ => fn T => (SOME T, NONE)) mode (binder_types T)
   627     val (inTs, outTs) = split_map_modeT (fn _ => fn T => (SOME T, NONE)) mode (binder_types T)
   596     val inner_term = PredicateCompFuns.mk_Eval (list_comb (P, inargs), fst (mk_tuple (outargs ~~ outTs)))
   628     val inner_term = Predicate_Comp_Funs.mk_Eval (list_comb (P, inargs), fst (mk_tuple (outargs ~~ outTs)))
   597   in
   629   in
   598     fold_rev mk_split_abs (binder_types T) inner_term
   630     fold_rev mk_split_abs (binder_types T) inner_term
   599   end
   631   end
   600 
   632 
   601 fun compile_arg compilation_modifiers additional_arguments ctxt param_modes arg = 
   633 fun compile_arg compilation_modifiers additional_arguments ctxt param_modes arg = 
  1016       in
  1048       in
  1017         (HOLogic.mk_prod (t1, t2), names'')
  1049         (HOLogic.mk_prod (t1, t2), names'')
  1018       end
  1050       end
  1019   | mk_args is_eval ((m as Fun _), T) names =
  1051   | mk_args is_eval ((m as Fun _), T) names =
  1020     let
  1052     let
  1021       val funT = funT_of PredicateCompFuns.compfuns m T
  1053       val funT = funT_of Predicate_Comp_Funs.compfuns m T
  1022       val x = singleton (Name.variant_list names) "x"
  1054       val x = singleton (Name.variant_list names) "x"
  1023       val (args, _) = fold_map (mk_args is_eval) (strip_fun_mode m ~~ binder_types T) (x :: names)
  1055       val (args, _) = fold_map (mk_args is_eval) (strip_fun_mode m ~~ binder_types T) (x :: names)
  1024       val (inargs, outargs) = split_map_mode (fn _ => fn t => (SOME t, NONE)) m args
  1056       val (inargs, outargs) = split_map_mode (fn _ => fn t => (SOME t, NONE)) m args
  1025       val t = fold_rev HOLogic.tupled_lambda args (PredicateCompFuns.mk_Eval
  1057       val t = fold_rev HOLogic.tupled_lambda args (Predicate_Comp_Funs.mk_Eval
  1026         (list_comb (Free (x, funT), inargs), HOLogic.mk_tuple outargs))
  1058         (list_comb (Free (x, funT), inargs), HOLogic.mk_tuple outargs))
  1027     in
  1059     in
  1028       (if is_eval then t else Free (x, funT), x :: names)
  1060       (if is_eval then t else Free (x, funT), x :: names)
  1029     end
  1061     end
  1030   | mk_args is_eval (_, T) names =
  1062   | mk_args is_eval (_, T) names =
  1040     val Ts = binder_types (fastype_of pred)
  1072     val Ts = binder_types (fastype_of pred)
  1041     val (args, argnames) = fold_map (mk_args true) (strip_fun_mode mode ~~ Ts) []
  1073     val (args, argnames) = fold_map (mk_args true) (strip_fun_mode mode ~~ Ts) []
  1042     fun strip_eval _ t =
  1074     fun strip_eval _ t =
  1043       let
  1075       let
  1044         val t' = strip_split_abs t
  1076         val t' = strip_split_abs t
  1045         val (r, _) = PredicateCompFuns.dest_Eval t'
  1077         val (r, _) = Predicate_Comp_Funs.dest_Eval t'
  1046       in (SOME (fst (strip_comb r)), NONE) end
  1078       in (SOME (fst (strip_comb r)), NONE) end
  1047     val (inargs, outargs) = split_map_mode strip_eval mode args
  1079     val (inargs, outargs) = split_map_mode strip_eval mode args
  1048     val eval_hoargs = ho_args_of mode args
  1080     val eval_hoargs = ho_args_of mode args
  1049     val hoargTs = ho_argsT_of mode Ts
  1081     val hoargTs = ho_argsT_of mode Ts
  1050     val hoarg_names' =
  1082     val hoarg_names' =
  1052     val hoargs' = map2 (curry Free) hoarg_names' hoargTs
  1084     val hoargs' = map2 (curry Free) hoarg_names' hoargTs
  1053     val args' = replace_ho_args mode hoargs' args
  1085     val args' = replace_ho_args mode hoargs' args
  1054     val predpropI = HOLogic.mk_Trueprop (list_comb (pred, args'))
  1086     val predpropI = HOLogic.mk_Trueprop (list_comb (pred, args'))
  1055     val predpropE = HOLogic.mk_Trueprop (list_comb (pred, args))
  1087     val predpropE = HOLogic.mk_Trueprop (list_comb (pred, args))
  1056     val param_eqs = map2 (HOLogic.mk_Trueprop oo (curry HOLogic.mk_eq)) eval_hoargs hoargs'
  1088     val param_eqs = map2 (HOLogic.mk_Trueprop oo (curry HOLogic.mk_eq)) eval_hoargs hoargs'
  1057     val funpropE = HOLogic.mk_Trueprop (PredicateCompFuns.mk_Eval (list_comb (funtrm, inargs),
  1089     val funpropE = HOLogic.mk_Trueprop (Predicate_Comp_Funs.mk_Eval (list_comb (funtrm, inargs),
  1058                     if null outargs then Free("y", HOLogic.unitT) else HOLogic.mk_tuple outargs))
  1090                     if null outargs then Free("y", HOLogic.unitT) else HOLogic.mk_tuple outargs))
  1059     val funpropI = HOLogic.mk_Trueprop (PredicateCompFuns.mk_Eval (list_comb (funtrm, inargs),
  1091     val funpropI = HOLogic.mk_Trueprop (Predicate_Comp_Funs.mk_Eval (list_comb (funtrm, inargs),
  1060                      HOLogic.mk_tuple outargs))
  1092                      HOLogic.mk_tuple outargs))
  1061     val introtrm = Logic.list_implies (predpropI :: param_eqs, funpropI)
  1093     val introtrm = Logic.list_implies (predpropI :: param_eqs, funpropI)
  1062     val simprules = [defthm, @{thm eval_pred},
  1094     val simprules = [defthm, @{thm eval_pred},
  1063       @{thm "split_beta"}, @{thm "fst_conv"}, @{thm "snd_conv"}, @{thm pair_collapse}]
  1095       @{thm "split_beta"}, @{thm "fst_conv"}, @{thm "snd_conv"}, @{thm pair_collapse}]
  1064     val unfolddef_tac = Simplifier.asm_full_simp_tac (HOL_basic_ss addsimps simprules) 1
  1096     val unfolddef_tac = Simplifier.asm_full_simp_tac (HOL_basic_ss addsimps simprules) 1
  1071     val opt_neg_introthm =
  1103     val opt_neg_introthm =
  1072       if is_all_input mode then
  1104       if is_all_input mode then
  1073         let
  1105         let
  1074           val neg_predpropI = HOLogic.mk_Trueprop (HOLogic.mk_not (list_comb (pred, args')))
  1106           val neg_predpropI = HOLogic.mk_Trueprop (HOLogic.mk_not (list_comb (pred, args')))
  1075           val neg_funpropI =
  1107           val neg_funpropI =
  1076             HOLogic.mk_Trueprop (PredicateCompFuns.mk_Eval
  1108             HOLogic.mk_Trueprop (Predicate_Comp_Funs.mk_Eval
  1077               (PredicateCompFuns.mk_not (list_comb (funtrm, inargs)), HOLogic.unit))
  1109               (Predicate_Comp_Funs.mk_not (list_comb (funtrm, inargs)), HOLogic.unit))
  1078           val neg_introtrm = Logic.list_implies (neg_predpropI :: param_eqs, neg_funpropI)
  1110           val neg_introtrm = Logic.list_implies (neg_predpropI :: param_eqs, neg_funpropI)
  1079           val tac =
  1111           val tac =
  1080             Simplifier.asm_full_simp_tac (HOL_basic_ss addsimps
  1112             Simplifier.asm_full_simp_tac (HOL_basic_ss addsimps
  1081               (@{thm if_False} :: @{thm Predicate.not_pred_eq} :: simprules)) 1
  1113               (@{thm if_False} :: @{thm Predicate.not_pred_eq} :: simprules)) 1
  1082             THEN rtac @{thm Predicate.singleI} 1
  1114             THEN rtac @{thm Predicate.singleI} 1
  1097     Sign.full_bname thy name
  1129     Sign.full_bname thy name
  1098   end;
  1130   end;
  1099 
  1131 
  1100 fun create_definitions options preds (name, modes) thy =
  1132 fun create_definitions options preds (name, modes) thy =
  1101   let
  1133   let
  1102     val compfuns = PredicateCompFuns.compfuns
  1134     val compfuns = Predicate_Comp_Funs.compfuns
  1103     val T = AList.lookup (op =) preds name |> the
  1135     val T = AList.lookup (op =) preds name |> the
  1104     fun create_definition mode thy =
  1136     fun create_definition mode thy =
  1105       let
  1137       let
  1106         val mode_cname = create_constname_of_mode options thy "" name T mode
  1138         val mode_cname = create_constname_of_mode options thy "" name T mode
  1107         val mode_cbasename = Long_Name.base_name mode_cname
  1139         val mode_cbasename = Long_Name.base_name mode_cname
  1108         val funT = funT_of compfuns mode T
  1140         val funT = funT_of compfuns mode T
  1109         val (args, _) = fold_map (mk_args true) ((strip_fun_mode mode) ~~ (binder_types T)) []
  1141         val (args, _) = fold_map (mk_args true) ((strip_fun_mode mode) ~~ (binder_types T)) []
  1110         fun strip_eval m t =
  1142         fun strip_eval m t =
  1111           let
  1143           let
  1112             val t' = strip_split_abs t
  1144             val t' = strip_split_abs t
  1113             val (r, _) = PredicateCompFuns.dest_Eval t'
  1145             val (r, _) = Predicate_Comp_Funs.dest_Eval t'
  1114           in (SOME (fst (strip_comb r)), NONE) end
  1146           in (SOME (fst (strip_comb r)), NONE) end
  1115         val (inargs, outargs) = split_map_mode strip_eval mode args
  1147         val (inargs, outargs) = split_map_mode strip_eval mode args
  1116         val predterm = fold_rev HOLogic.tupled_lambda inargs
  1148         val predterm = fold_rev HOLogic.tupled_lambda inargs
  1117           (PredicateCompFuns.mk_Enum (HOLogic.tupled_lambda (HOLogic.mk_tuple outargs)
  1149           (Predicate_Comp_Funs.mk_Enum (HOLogic.tupled_lambda (HOLogic.mk_tuple outargs)
  1118             (list_comb (Const (name, T), args))))
  1150             (list_comb (Const (name, T), args))))
  1119         val lhs = Const (mode_cname, funT)
  1151         val lhs = Const (mode_cname, funT)
  1120         val def = Logic.mk_equals (lhs, predterm)
  1152         val def = Logic.mk_equals (lhs, predterm)
  1121         val ([definition], thy') = thy |>
  1153         val ([definition], thy') = thy |>
  1122           Sign.add_consts_i [(Binding.name mode_cbasename, funT, NoSyn)] |>
  1154           Sign.add_consts_i [(Binding.name mode_cbasename, funT, NoSyn)] |>
  1307             val Ts = binder_types T
  1339             val Ts = binder_types T
  1308             val arg_names = Name.variant_list []
  1340             val arg_names = Name.variant_list []
  1309               (map (fn i => "x" ^ string_of_int i) (1 upto length Ts))
  1341               (map (fn i => "x" ^ string_of_int i) (1 upto length Ts))
  1310             val args = map2 (curry Free) arg_names Ts
  1342             val args = map2 (curry Free) arg_names Ts
  1311             val predfun = Const (function_name_of Pred ctxt predname full_mode,
  1343             val predfun = Const (function_name_of Pred ctxt predname full_mode,
  1312               Ts ---> PredicateCompFuns.mk_predT @{typ unit})
  1344               Ts ---> Predicate_Comp_Funs.mk_predT @{typ unit})
  1313             val rhs = @{term Predicate.holds} $ (list_comb (predfun, args))
  1345             val rhs = @{term Predicate.holds} $ (list_comb (predfun, args))
  1314             val eq_term = HOLogic.mk_Trueprop
  1346             val eq_term = HOLogic.mk_Trueprop
  1315               (HOLogic.mk_eq (list_comb (Const (predname, T), args), rhs))
  1347               (HOLogic.mk_eq (list_comb (Const (predname, T), args), rhs))
  1316             val def = predfun_definition_of ctxt predname full_mode
  1348             val def = predfun_definition_of ctxt predname full_mode
  1317             val tac = fn _ => Simplifier.simp_tac
  1349             val tac = fn _ => Simplifier.simp_tac
  1438 
  1470 
  1439 val add_depth_limited_equations = gen_add_equations
  1471 val add_depth_limited_equations = gen_add_equations
  1440   (Steps {
  1472   (Steps {
  1441   define_functions =
  1473   define_functions =
  1442     fn options => fn preds => fn (s, modes) =>
  1474     fn options => fn preds => fn (s, modes) =>
  1443     define_functions depth_limited_comp_modifiers PredicateCompFuns.compfuns
  1475     define_functions depth_limited_comp_modifiers Predicate_Comp_Funs.compfuns
  1444     options preds (s, map_filter (fn (true, m) => SOME m | _ => NONE) modes),
  1476     options preds (s, map_filter (fn (true, m) => SOME m | _ => NONE) modes),
  1445   prove = prove_by_skip,
  1477   prove = prove_by_skip,
  1446   add_code_equations = K (K I),
  1478   add_code_equations = K (K I),
  1447   comp_modifiers = depth_limited_comp_modifiers,
  1479   comp_modifiers = depth_limited_comp_modifiers,
  1448   use_generators = false,
  1480   use_generators = false,
  1450 
  1482 
  1451 val add_annotated_equations = gen_add_equations
  1483 val add_annotated_equations = gen_add_equations
  1452   (Steps {
  1484   (Steps {
  1453   define_functions =
  1485   define_functions =
  1454     fn options => fn preds => fn (s, modes) =>
  1486     fn options => fn preds => fn (s, modes) =>
  1455       define_functions annotated_comp_modifiers PredicateCompFuns.compfuns options preds
  1487       define_functions annotated_comp_modifiers Predicate_Comp_Funs.compfuns options preds
  1456       (s, map_filter (fn (true, m) => SOME m | _ => NONE) modes),
  1488       (s, map_filter (fn (true, m) => SOME m | _ => NONE) modes),
  1457   prove = prove_by_skip,
  1489   prove = prove_by_skip,
  1458   add_code_equations = K (K I),
  1490   add_code_equations = K (K I),
  1459   comp_modifiers = annotated_comp_modifiers,
  1491   comp_modifiers = annotated_comp_modifiers,
  1460   use_generators = false,
  1492   use_generators = false,
  1462 
  1494 
  1463 val add_random_equations = gen_add_equations
  1495 val add_random_equations = gen_add_equations
  1464   (Steps {
  1496   (Steps {
  1465   define_functions =
  1497   define_functions =
  1466     fn options => fn preds => fn (s, modes) =>
  1498     fn options => fn preds => fn (s, modes) =>
  1467       define_functions random_comp_modifiers PredicateCompFuns.compfuns options preds
  1499       define_functions random_comp_modifiers Predicate_Comp_Funs.compfuns options preds
  1468       (s, map_filter (fn (true, m) => SOME m | _ => NONE) modes),
  1500       (s, map_filter (fn (true, m) => SOME m | _ => NONE) modes),
  1469   comp_modifiers = random_comp_modifiers,
  1501   comp_modifiers = random_comp_modifiers,
  1470   prove = prove_by_skip,
  1502   prove = prove_by_skip,
  1471   add_code_equations = K (K I),
  1503   add_code_equations = K (K I),
  1472   use_generators = true,
  1504   use_generators = true,
  1474 
  1506 
  1475 val add_depth_limited_random_equations = gen_add_equations
  1507 val add_depth_limited_random_equations = gen_add_equations
  1476   (Steps {
  1508   (Steps {
  1477   define_functions =
  1509   define_functions =
  1478     fn options => fn preds => fn (s, modes) =>
  1510     fn options => fn preds => fn (s, modes) =>
  1479       define_functions depth_limited_random_comp_modifiers PredicateCompFuns.compfuns options preds
  1511       define_functions depth_limited_random_comp_modifiers Predicate_Comp_Funs.compfuns options preds
  1480       (s, map_filter (fn (true, m) => SOME m | _ => NONE) modes),
  1512       (s, map_filter (fn (true, m) => SOME m | _ => NONE) modes),
  1481   comp_modifiers = depth_limited_random_comp_modifiers,
  1513   comp_modifiers = depth_limited_random_comp_modifiers,
  1482   prove = prove_by_skip,
  1514   prove = prove_by_skip,
  1483   add_code_equations = K (K I),
  1515   add_code_equations = K (K I),
  1484   use_generators = true,
  1516   use_generators = true,
  1549   add_code_equations = K (K I),
  1581   add_code_equations = K (K I),
  1550   comp_modifiers = pos_generator_dseq_comp_modifiers,
  1582   comp_modifiers = pos_generator_dseq_comp_modifiers,
  1551   use_generators = true,
  1583   use_generators = true,
  1552   qname = "generator_dseq_equation"})
  1584   qname = "generator_dseq_equation"})
  1553 
  1585 
       
  1586 val add_generator_cps_equations = gen_add_equations
       
  1587   (Steps {
       
  1588   define_functions =
       
  1589   fn options => fn preds => fn (s, modes) =>
       
  1590     let
       
  1591       val pos_modes = map_filter (fn (true, m) => SOME m | _ => NONE) modes
       
  1592       val neg_modes = map_filter (fn (false, m) => SOME m | _ => NONE) modes
       
  1593     in 
       
  1594       define_functions pos_generator_cps_comp_modifiers Pos_Bounded_CPS_Comp_Funs.compfuns
       
  1595         options preds (s, pos_modes)
       
  1596       #> define_functions neg_generator_cps_comp_modifiers Neg_Bounded_CPS_Comp_Funs.compfuns
       
  1597         options preds (s, neg_modes)
       
  1598     end,
       
  1599   prove = prove_by_skip,
       
  1600   add_code_equations = K (K I),
       
  1601   comp_modifiers = pos_generator_cps_comp_modifiers,
       
  1602   use_generators = true,
       
  1603   qname = "generator_cps_equation"})
       
  1604   
       
  1605   
  1554 (** user interface **)
  1606 (** user interface **)
  1555 
  1607 
  1556 (* code_pred_intro attribute *)
  1608 (* code_pred_intro attribute *)
  1557 
  1609 
  1558 fun attrib' f opt_case_name =
  1610 fun attrib' f opt_case_name =
  1614            | Depth_Limited => add_depth_limited_equations
  1666            | Depth_Limited => add_depth_limited_equations
  1615            | Random => add_random_equations
  1667            | Random => add_random_equations
  1616            | Depth_Limited_Random => add_depth_limited_random_equations
  1668            | Depth_Limited_Random => add_depth_limited_random_equations
  1617            | New_Pos_Random_DSeq => add_new_random_dseq_equations
  1669            | New_Pos_Random_DSeq => add_new_random_dseq_equations
  1618            | Pos_Generator_DSeq => add_generator_dseq_equations
  1670            | Pos_Generator_DSeq => add_generator_dseq_equations
       
  1671            | Pos_Generator_CPS => add_generator_cps_equations
  1619            | compilation => error ("Compilation not supported")
  1672            | compilation => error ("Compilation not supported")
  1620            ) options [const]))
  1673            ) options [const]))
  1621       end
  1674       end
  1622   in
  1675   in
  1623     Proof.theorem NONE after_qed (map (single o (rpair [])) cases_rules) lthy''
  1676     Proof.theorem NONE after_qed (map (single o (rpair [])) cases_rules) lthy''