src/HOL/Predicate.thy
changeset 66012 59bf29d2b3a1
parent 62390 842917225d56
child 66251 cd935b7cb3fb
equal deleted inserted replaced
66011:f10bbfe07c41 66012:59bf29d2b3a1
     8 imports String
     8 imports String
     9 begin
     9 begin
    10 
    10 
    11 subsection \<open>The type of predicate enumerations (a monad)\<close>
    11 subsection \<open>The type of predicate enumerations (a monad)\<close>
    12 
    12 
    13 datatype (plugins only: code extraction) (dead 'a) pred = Pred "'a \<Rightarrow> bool"
    13 datatype (plugins only: extraction) (dead 'a) pred = Pred (eval: "'a \<Rightarrow> bool")
    14 
       
    15 primrec eval :: "'a pred \<Rightarrow> 'a \<Rightarrow> bool" where
       
    16   eval_pred: "eval (Pred f) = f"
       
    17 
       
    18 lemma Pred_eval [simp]:
       
    19   "Pred (eval x) = x"
       
    20   by (cases x) simp
       
    21 
    14 
    22 lemma pred_eqI:
    15 lemma pred_eqI:
    23   "(\<And>w. eval P w \<longleftrightarrow> eval Q w) \<Longrightarrow> P = Q"
    16   "(\<And>w. eval P w \<longleftrightarrow> eval Q w) \<Longrightarrow> P = Q"
    24   by (cases P, cases Q) (auto simp add: fun_eq_iff)
    17   by (cases P, cases Q) (auto simp add: fun_eq_iff)
    25 
    18 
   337 
   330 
   338 lemma if_predE: "eval (if_pred b) x \<Longrightarrow> (b \<Longrightarrow> x = () \<Longrightarrow> P) \<Longrightarrow> P"
   331 lemma if_predE: "eval (if_pred b) x \<Longrightarrow> (b \<Longrightarrow> x = () \<Longrightarrow> P) \<Longrightarrow> P"
   339   unfolding if_pred_eq by (cases b) (auto elim: botE)
   332   unfolding if_pred_eq by (cases b) (auto elim: botE)
   340 
   333 
   341 lemma not_predI: "\<not> P \<Longrightarrow> eval (not_pred (Pred (\<lambda>u. P))) ()"
   334 lemma not_predI: "\<not> P \<Longrightarrow> eval (not_pred (Pred (\<lambda>u. P))) ()"
   342   unfolding not_pred_eq eval_pred by (auto intro: singleI)
   335   unfolding not_pred_eq by (auto intro: singleI)
   343 
   336 
   344 lemma not_predI': "\<not> eval P () \<Longrightarrow> eval (not_pred P) ()"
   337 lemma not_predI': "\<not> eval P () \<Longrightarrow> eval (not_pred P) ()"
   345   unfolding not_pred_eq by (auto intro: singleI)
   338   unfolding not_pred_eq by (auto intro: singleI)
   346 
   339 
   347 lemma not_predE: "eval (not_pred (Pred (\<lambda>u. P))) x \<Longrightarrow> (\<not> P \<Longrightarrow> thesis) \<Longrightarrow> thesis"
   340 lemma not_predE: "eval (not_pred (Pred (\<lambda>u. P))) x \<Longrightarrow> (\<not> P \<Longrightarrow> thesis) \<Longrightarrow> thesis"
   527     | Insert x P \<Rightarrow> eval Q x \<and> P \<le> Q
   520     | Insert x P \<Rightarrow> eval Q x \<and> P \<le> Q
   528     | Join P xq \<Rightarrow> P \<le> Q \<and> contained xq Q)"
   521     | Join P xq \<Rightarrow> P \<le> Q \<and> contained xq Q)"
   529   by (cases "f ()")
   522   by (cases "f ()")
   530     (simp_all add: Seq_def single_less_eq_eval contained_less_eq)
   523     (simp_all add: Seq_def single_less_eq_eval contained_less_eq)
   531 
   524 
   532 lemma eq_pred_code [code]:
   525 instantiation pred :: (type) equal
   533   fixes P Q :: "'a pred"
   526 begin
   534   shows "HOL.equal P Q \<longleftrightarrow> P \<le> Q \<and> Q \<le> P"
   527 
   535   by (auto simp add: equal)
   528 definition equal_pred
       
   529   where [simp]: "HOL.equal P Q \<longleftrightarrow> P = (Q :: 'a pred)"
       
   530 
       
   531 instance by standard simp
       
   532 
       
   533 end
       
   534     
       
   535 lemma [code]:
       
   536   "HOL.equal P Q \<longleftrightarrow> P \<le> Q \<and> Q \<le> P" for P Q :: "'a pred"
       
   537   by auto
   536 
   538 
   537 lemma [code nbe]:
   539 lemma [code nbe]:
   538   "HOL.equal (x :: 'a pred) x \<longleftrightarrow> True"
   540   "HOL.equal P P \<longleftrightarrow> True" for P :: "'a pred"
   539   by (fact equal_refl)
   541   by (fact equal_refl)
   540 
   542 
   541 lemma [code]:
   543 lemma [code]:
   542   "case_pred f P = f (eval P)"
   544   "case_pred f P = f (eval P)"
   543   by (cases P) simp
   545   by (fact pred.case_eq_if)
   544 
   546 
   545 lemma [code]:
   547 lemma [code]:
   546   "rec_pred f P = f (eval P)"
   548   "rec_pred f P = f (eval P)"
   547   by (cases P) simp
   549   by (cases P) simp
   548 
   550