src/HOL/Tools/Predicate_Compile/predicate_compile_core.ML
changeset 40049 75d9f57123d6
parent 39785 05c4e9ecf5f6
child 40050 638ce4dabe53
equal deleted inserted replaced
40048:f3a46d524101 40049:75d9f57123d6
   837 
   837 
   838 val additional_arguments = #additional_arguments o dest_comp_modifiers
   838 val additional_arguments = #additional_arguments o dest_comp_modifiers
   839 val wrap_compilation = #wrap_compilation o dest_comp_modifiers
   839 val wrap_compilation = #wrap_compilation o dest_comp_modifiers
   840 val transform_additional_arguments = #transform_additional_arguments o dest_comp_modifiers
   840 val transform_additional_arguments = #transform_additional_arguments o dest_comp_modifiers
   841 
   841 
       
   842 fun set_compfuns compfuns' (Comp_Modifiers {compilation, function_name_prefix, compfuns, mk_random,
       
   843     modify_funT, additional_arguments, wrap_compilation, transform_additional_arguments}) =
       
   844     (Comp_Modifiers {compilation = compilation, function_name_prefix = function_name_prefix,
       
   845     compfuns = compfuns', mk_random = mk_random, modify_funT = modify_funT,
       
   846     additional_arguments = additional_arguments, wrap_compilation = wrap_compilation,
       
   847     transform_additional_arguments = transform_additional_arguments})
       
   848 
   842 end;
   849 end;
       
   850 
       
   851 fun unlimited_compfuns_of true Predicate_Compile_Aux.New_Pos_Random_DSeq =
       
   852     New_Pos_Random_Sequence_CompFuns.depth_unlimited_compfuns
       
   853   | unlimited_compfuns_of false Predicate_Compile_Aux.New_Pos_Random_DSeq =
       
   854     New_Neg_Random_Sequence_CompFuns.depth_unlimited_compfuns
       
   855   
       
   856 fun limited_compfuns_of true Predicate_Compile_Aux.New_Pos_Random_DSeq =
       
   857     New_Pos_Random_Sequence_CompFuns.depth_limited_compfuns
       
   858   | limited_compfuns_of false Predicate_Compile_Aux.New_Pos_Random_DSeq =
       
   859     New_Neg_Random_Sequence_CompFuns.depth_limited_compfuns
       
   860 
   843 
   861 
   844 val depth_limited_comp_modifiers = Comp_Mod.Comp_Modifiers
   862 val depth_limited_comp_modifiers = Comp_Mod.Comp_Modifiers
   845   {
   863   {
   846   compilation = Depth_Limited,
   864   compilation = Depth_Limited,
   847   function_name_prefix = "depth_limited_",
   865   function_name_prefix = "depth_limited_",
  1026 
  1044 
  1027 val new_pos_random_dseq_comp_modifiers = Comp_Mod.Comp_Modifiers
  1045 val new_pos_random_dseq_comp_modifiers = Comp_Mod.Comp_Modifiers
  1028   {
  1046   {
  1029   compilation = New_Pos_Random_DSeq,
  1047   compilation = New_Pos_Random_DSeq,
  1030   function_name_prefix = "new_random_dseq_",
  1048   function_name_prefix = "new_random_dseq_",
  1031   compfuns = New_Pos_Random_Sequence_CompFuns.compfuns,
  1049   compfuns = New_Pos_Random_Sequence_CompFuns.depth_limited_compfuns,
  1032   mk_random = (fn T => fn additional_arguments =>
  1050   mk_random = (fn T => fn additional_arguments =>
  1033   let
  1051   let
  1034     val random = Const ("Quickcheck.random_class.random",
  1052     val random = Const ("Quickcheck.random_class.random",
  1035       @{typ code_numeral} --> @{typ Random.seed} -->
  1053       @{typ code_numeral} --> @{typ Random.seed} -->
  1036         HOLogic.mk_prodT (HOLogic.mk_prodT (T, @{typ "unit => term"}), @{typ Random.seed}))
  1054         HOLogic.mk_prodT (HOLogic.mk_prodT (T, @{typ "unit => term"}), @{typ Random.seed}))
  1048 
  1066 
  1049 val new_neg_random_dseq_comp_modifiers = Comp_Mod.Comp_Modifiers
  1067 val new_neg_random_dseq_comp_modifiers = Comp_Mod.Comp_Modifiers
  1050   {
  1068   {
  1051   compilation = New_Neg_Random_DSeq,
  1069   compilation = New_Neg_Random_DSeq,
  1052   function_name_prefix = "new_random_dseq_neg_",
  1070   function_name_prefix = "new_random_dseq_neg_",
  1053   compfuns = New_Neg_Random_Sequence_CompFuns.compfuns,
  1071   compfuns = New_Neg_Random_Sequence_CompFuns.depth_limited_compfuns,
  1054   mk_random = (fn _ => error "no random generation"),
  1072   mk_random = (fn _ => error "no random generation"),
  1055   modify_funT = I,
  1073   modify_funT = I,
  1056   additional_arguments = K [],
  1074   additional_arguments = K [],
  1057   wrap_compilation = K (K (K (K (K I))))
  1075   wrap_compilation = K (K (K (K (K I))))
  1058    : (compilation_funs -> string -> typ -> mode -> term list -> term -> term),
  1076    : (compilation_funs -> string -> typ -> mode -> term list -> term -> term),
  1962 
  1980 
  1963 (* compilation of predicates *)
  1981 (* compilation of predicates *)
  1964 
  1982 
  1965 fun compile_pred options compilation_modifiers ctxt all_vs param_vs s T (pol, mode) moded_cls =
  1983 fun compile_pred options compilation_modifiers ctxt all_vs param_vs s T (pol, mode) moded_cls =
  1966   let
  1984   let
  1967     val compilation_modifiers = if pol then compilation_modifiers else
  1985     val is_terminating = true (* FIXME: requires an termination analysis *)  
  1968       negative_comp_modifiers_of compilation_modifiers
  1986     val compilation_modifiers =
       
  1987       (if pol then compilation_modifiers else
       
  1988         negative_comp_modifiers_of compilation_modifiers)
       
  1989       |> (if is_depth_limited_compilation (Comp_Mod.compilation compilation_modifiers) then
       
  1990            (if is_terminating then
       
  1991              (Comp_Mod.set_compfuns (unlimited_compfuns_of pol (Comp_Mod.compilation compilation_modifiers)))
       
  1992            else
       
  1993              (Comp_Mod.set_compfuns (limited_compfuns_of pol (Comp_Mod.compilation compilation_modifiers))))
       
  1994          else I)
  1969     val additional_arguments = Comp_Mod.additional_arguments compilation_modifiers
  1995     val additional_arguments = Comp_Mod.additional_arguments compilation_modifiers
  1970       (all_vs @ param_vs)
  1996       (all_vs @ param_vs)
  1971     val compfuns = Comp_Mod.compfuns compilation_modifiers
  1997     val compfuns = Comp_Mod.compfuns compilation_modifiers
  1972     fun is_param_type (T as Type ("fun",[_ , T'])) =
  1998     fun is_param_type (T as Type ("fun",[_ , T'])) =
  1973       is_some (try (dest_predT compfuns) T) orelse is_param_type T'
  1999       is_some (try (dest_predT compfuns) T) orelse is_param_type T'
  3060   define_functions =
  3086   define_functions =
  3061     fn options => fn preds => fn (s, modes) =>
  3087     fn options => fn preds => fn (s, modes) =>
  3062     let
  3088     let
  3063       val pos_modes = map_filter (fn (true, m) => SOME m | _ => NONE) modes
  3089       val pos_modes = map_filter (fn (true, m) => SOME m | _ => NONE) modes
  3064       val neg_modes = map_filter (fn (false, m) => SOME m | _ => NONE) modes
  3090       val neg_modes = map_filter (fn (false, m) => SOME m | _ => NONE) modes
  3065     in define_functions new_pos_random_dseq_comp_modifiers New_Pos_Random_Sequence_CompFuns.compfuns
  3091     in define_functions new_pos_random_dseq_comp_modifiers New_Pos_Random_Sequence_CompFuns.depth_limited_compfuns
  3066       options preds (s, pos_modes)
  3092       options preds (s, pos_modes)
  3067       #> define_functions new_neg_random_dseq_comp_modifiers New_Neg_Random_Sequence_CompFuns.compfuns
  3093       #> define_functions new_neg_random_dseq_comp_modifiers New_Neg_Random_Sequence_CompFuns.depth_limited_compfuns
  3068       options preds (s, neg_modes)
  3094       options preds (s, neg_modes)
  3069     end,
  3095     end,
  3070   prove = prove_by_skip,
  3096   prove = prove_by_skip,
  3071   add_code_equations = K (K I),
  3097   add_code_equations = K (K I),
  3072   comp_modifiers = new_pos_random_dseq_comp_modifiers,
  3098   comp_modifiers = new_pos_random_dseq_comp_modifiers,
  3290     val compfuns =
  3316     val compfuns =
  3291       case compilation of
  3317       case compilation of
  3292         Random => PredicateCompFuns.compfuns
  3318         Random => PredicateCompFuns.compfuns
  3293       | DSeq => DSequence_CompFuns.compfuns
  3319       | DSeq => DSequence_CompFuns.compfuns
  3294       | Pos_Random_DSeq => Random_Sequence_CompFuns.compfuns
  3320       | Pos_Random_DSeq => Random_Sequence_CompFuns.compfuns
  3295       | New_Pos_Random_DSeq => New_Pos_Random_Sequence_CompFuns.compfuns
  3321       | New_Pos_Random_DSeq => New_Pos_Random_Sequence_CompFuns.depth_unlimited_compfuns
  3296       | _ => PredicateCompFuns.compfuns
  3322       | _ => PredicateCompFuns.compfuns
  3297     val t = analyze_compr ctxt compfuns param_user_modes options t_compr;
  3323     val t = analyze_compr ctxt compfuns param_user_modes options t_compr;
  3298     val T = dest_predT compfuns (fastype_of t);
  3324     val T = dest_predT compfuns (fastype_of t);
  3299     val t' =
  3325     val t' =
  3300       if stats andalso compilation = New_Pos_Random_DSeq then
  3326       if stats andalso compilation = New_Pos_Random_DSeq then