src/HOL/Predicate_Compile.thy
author wenzelm
Mon Aug 31 21:28:08 2015 +0200 (2015-08-31)
changeset 61070 b72a990adfe2
parent 60758 d8d85a8172b5
child 62390 842917225d56
permissions -rw-r--r--
prefer symbols;
     1 (*  Title:      HOL/Predicate_Compile.thy
     2     Author:     Stefan Berghofer, Lukas Bulwahn, Florian Haftmann, TU Muenchen
     3 *)
     4 
     5 section \<open>A compiler for predicates defined by introduction rules\<close>
     6 
     7 theory Predicate_Compile
     8 imports Random_Sequence Quickcheck_Exhaustive
     9 keywords "code_pred" :: thy_goal and "values" :: diag
    10 begin
    11 
    12 ML_file "Tools/Predicate_Compile/predicate_compile_aux.ML"
    13 ML_file "Tools/Predicate_Compile/predicate_compile_compilations.ML"
    14 ML_file "Tools/Predicate_Compile/core_data.ML"
    15 ML_file "Tools/Predicate_Compile/mode_inference.ML"
    16 ML_file "Tools/Predicate_Compile/predicate_compile_proof.ML"
    17 ML_file "Tools/Predicate_Compile/predicate_compile_core.ML"
    18 ML_file "Tools/Predicate_Compile/predicate_compile_data.ML"
    19 ML_file "Tools/Predicate_Compile/predicate_compile_fun.ML"
    20 ML_file "Tools/Predicate_Compile/predicate_compile_pred.ML"
    21 ML_file "Tools/Predicate_Compile/predicate_compile_specialisation.ML"
    22 ML_file "Tools/Predicate_Compile/predicate_compile.ML"
    23 
    24 
    25 subsection \<open>Set membership as a generator predicate\<close>
    26 
    27 text \<open>
    28   Introduce a new constant for membership to allow 
    29   fine-grained control in code equations. 
    30 \<close>
    31 
    32 definition contains :: "'a set => 'a => bool"
    33 where "contains A x \<longleftrightarrow> x : A"
    34 
    35 definition contains_pred :: "'a set => 'a => unit Predicate.pred"
    36 where "contains_pred A x = (if x : A then Predicate.single () else bot)"
    37 
    38 lemma pred_of_setE:
    39   assumes "Predicate.eval (pred_of_set A) x"
    40   obtains "contains A x"
    41 using assms by(simp add: contains_def)
    42 
    43 lemma pred_of_setI: "contains A x ==> Predicate.eval (pred_of_set A) x"
    44 by(simp add: contains_def)
    45 
    46 lemma pred_of_set_eq: "pred_of_set \<equiv> \<lambda>A. Predicate.Pred (contains A)"
    47 by(simp add: contains_def[abs_def] pred_of_set_def o_def)
    48 
    49 lemma containsI: "x \<in> A ==> contains A x" 
    50 by(simp add: contains_def)
    51 
    52 lemma containsE: assumes "contains A x"
    53   obtains A' x' where "A = A'" "x = x'" "x : A"
    54 using assms by(simp add: contains_def)
    55 
    56 lemma contains_predI: "contains A x ==> Predicate.eval (contains_pred A x) ()"
    57 by(simp add: contains_pred_def contains_def)
    58 
    59 lemma contains_predE: 
    60   assumes "Predicate.eval (contains_pred A x) y"
    61   obtains "contains A x"
    62 using assms by(simp add: contains_pred_def contains_def split: split_if_asm)
    63 
    64 lemma contains_pred_eq: "contains_pred \<equiv> \<lambda>A x. Predicate.Pred (\<lambda>y. contains A x)"
    65 by(rule eq_reflection)(auto simp add: contains_pred_def fun_eq_iff contains_def intro: pred_eqI)
    66 
    67 lemma contains_pred_notI:
    68    "\<not> contains A x ==> Predicate.eval (Predicate.not_pred (contains_pred A x)) ()"
    69 by(simp add: contains_pred_def contains_def not_pred_eq)
    70 
    71 setup \<open>
    72 let
    73   val Fun = Predicate_Compile_Aux.Fun
    74   val Input = Predicate_Compile_Aux.Input
    75   val Output = Predicate_Compile_Aux.Output
    76   val Bool = Predicate_Compile_Aux.Bool
    77   val io = Fun (Input, Fun (Output, Bool))
    78   val ii = Fun (Input, Fun (Input, Bool))
    79 in
    80   Core_Data.PredData.map (Graph.new_node 
    81     (@{const_name contains}, 
    82      Core_Data.PredData {
    83        pos = Position.thread_data (),
    84        intros = [(NONE, @{thm containsI})], 
    85        elim = SOME @{thm containsE}, 
    86        preprocessed = true,
    87        function_names = [(Predicate_Compile_Aux.Pred, 
    88          [(io, @{const_name pred_of_set}), (ii, @{const_name contains_pred})])], 
    89        predfun_data = [
    90          (io, Core_Data.PredfunData {
    91             elim = @{thm pred_of_setE}, intro = @{thm pred_of_setI},
    92             neg_intro = NONE, definition = @{thm pred_of_set_eq}
    93           }),
    94          (ii, Core_Data.PredfunData {
    95             elim = @{thm contains_predE}, intro = @{thm contains_predI}, 
    96             neg_intro = SOME @{thm contains_pred_notI}, definition = @{thm contains_pred_eq}
    97           })],
    98        needs_random = []}))
    99 end
   100 \<close>
   101 
   102 hide_const (open) contains contains_pred
   103 hide_fact (open) pred_of_setE pred_of_setI pred_of_set_eq 
   104   containsI containsE contains_predI contains_predE contains_pred_eq contains_pred_notI
   105 
   106 end