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