src/HOL/HOLCF/Lift.thy
author haftmann
Sun Jun 23 21:16:07 2013 +0200 (2013-06-23)
changeset 52435 6646bb548c6b
parent 51717 9e7d1c139569
child 55417 01fbfb60c33e
permissions -rw-r--r--
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
wenzelm@42151
     1
(*  Title:      HOL/HOLCF/Lift.thy
wenzelm@12026
     2
    Author:     Olaf Mueller
slotosch@2640
     3
*)
slotosch@2640
     4
wenzelm@12338
     5
header {* Lifting types of class type to flat pcpo's *}
wenzelm@12026
     6
huffman@15577
     7
theory Lift
huffman@40086
     8
imports Discrete Up
huffman@15577
     9
begin
wenzelm@12026
    10
wenzelm@36452
    11
default_sort type
wenzelm@12026
    12
huffman@49759
    13
pcpodef 'a lift = "UNIV :: 'a discr u set"
wenzelm@29063
    14
by simp_all
wenzelm@12026
    15
huffman@16748
    16
lemmas inst_lift_pcpo = Abs_lift_strict [symmetric]
wenzelm@12026
    17
wenzelm@25131
    18
definition
wenzelm@25131
    19
  Def :: "'a \<Rightarrow> 'a lift" where
wenzelm@25131
    20
  "Def x = Abs_lift (up\<cdot>(Discr x))"
wenzelm@12026
    21
wenzelm@12026
    22
subsection {* Lift as a datatype *}
wenzelm@12026
    23
huffman@16748
    24
lemma lift_induct: "\<lbrakk>P \<bottom>; \<And>x. P (Def x)\<rbrakk> \<Longrightarrow> P y"
huffman@16748
    25
apply (induct y)
huffman@16755
    26
apply (rule_tac p=y in upE)
huffman@16748
    27
apply (simp add: Abs_lift_strict)
huffman@16748
    28
apply (case_tac x)
huffman@16748
    29
apply (simp add: Def_def)
huffman@16748
    30
done
wenzelm@12026
    31
haftmann@27104
    32
rep_datatype "\<bottom>\<Colon>'a lift" Def
huffman@40082
    33
  by (erule lift_induct) (simp_all add: Def_def Abs_lift_inject inst_lift_pcpo)
wenzelm@12026
    34
huffman@41430
    35
text {* @{term bottom} and @{term Def} *}
wenzelm@12026
    36
huffman@16748
    37
lemma not_Undef_is_Def: "(x \<noteq> \<bottom>) = (\<exists>y. x = Def y)"
wenzelm@12026
    38
  by (cases x) simp_all
wenzelm@12026
    39
huffman@16630
    40
lemma lift_definedE: "\<lbrakk>x \<noteq> \<bottom>; \<And>a. x = Def a \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
huffman@16630
    41
  by (cases x) simp_all
huffman@16630
    42
wenzelm@12026
    43
text {*
huffman@41430
    44
  For @{term "x ~= \<bottom>"} in assumptions @{text defined} replaces @{text
wenzelm@12026
    45
  x} by @{text "Def a"} in conclusion. *}
wenzelm@12026
    46
wenzelm@30607
    47
method_setup defined = {*
wenzelm@30607
    48
  Scan.succeed (fn ctxt => SIMPLE_METHOD'
wenzelm@51717
    49
    (etac @{thm lift_definedE} THEN' asm_simp_tac ctxt))
wenzelm@42814
    50
*}
wenzelm@12026
    51
huffman@16748
    52
lemma DefE: "Def x = \<bottom> \<Longrightarrow> R"
huffman@16748
    53
  by simp
wenzelm@12026
    54
huffman@16748
    55
lemma DefE2: "\<lbrakk>x = Def s; x = \<bottom>\<rbrakk> \<Longrightarrow> R"
wenzelm@12026
    56
  by simp
wenzelm@12026
    57
huffman@31076
    58
lemma Def_below_Def: "Def x \<sqsubseteq> Def y \<longleftrightarrow> x = y"
huffman@40082
    59
by (simp add: below_lift_def Def_def Abs_lift_inverse)
wenzelm@12026
    60
huffman@31076
    61
lemma Def_below_iff [simp]: "Def x \<sqsubseteq> y \<longleftrightarrow> Def x = y"
huffman@31076
    62
by (induct y, simp, simp add: Def_below_Def)
wenzelm@12026
    63
wenzelm@12026
    64
wenzelm@12026
    65
subsection {* Lift is flat *}
wenzelm@12026
    66
wenzelm@12338
    67
instance lift :: (type) flat
huffman@27292
    68
proof
huffman@27292
    69
  fix x y :: "'a lift"
huffman@27292
    70
  assume "x \<sqsubseteq> y" thus "x = \<bottom> \<or> x = y"
huffman@27292
    71
    by (induct x) auto
huffman@27292
    72
qed
wenzelm@12026
    73
huffman@40088
    74
subsection {* Continuity of @{const lift_case} *}
huffman@40088
    75
huffman@40088
    76
lemma lift_case_eq: "lift_case \<bottom> f x = fup\<cdot>(\<Lambda> y. f (undiscr y))\<cdot>(Rep_lift x)"
huffman@40088
    77
apply (induct x, unfold lift.cases)
huffman@40088
    78
apply (simp add: Rep_lift_strict)
huffman@40088
    79
apply (simp add: Def_def Abs_lift_inverse)
huffman@40088
    80
done
huffman@40088
    81
huffman@40088
    82
lemma cont2cont_lift_case [simp]:
huffman@40088
    83
  "\<lbrakk>\<And>y. cont (\<lambda>x. f x y); cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. lift_case \<bottom> (f x) (g x))"
huffman@40834
    84
unfolding lift_case_eq by (simp add: cont_Rep_lift)
huffman@40088
    85
huffman@16695
    86
subsection {* Further operations *}
huffman@16695
    87
wenzelm@25131
    88
definition
wenzelm@25131
    89
  flift1 :: "('a \<Rightarrow> 'b::pcpo) \<Rightarrow> ('a lift \<rightarrow> 'b)"  (binder "FLIFT " 10)  where
wenzelm@25131
    90
  "flift1 = (\<lambda>f. (\<Lambda> x. lift_case \<bottom> f x))"
huffman@16695
    91
huffman@40323
    92
translations
huffman@40323
    93
  "\<Lambda>(XCONST Def x). t" => "CONST flift1 (\<lambda>x. t)"
huffman@40323
    94
  "\<Lambda>(CONST Def x). FLIFT y. t" <= "FLIFT x y. t"
huffman@40323
    95
  "\<Lambda>(CONST Def x). t" <= "FLIFT x. t"
huffman@40323
    96
wenzelm@25131
    97
definition
wenzelm@25131
    98
  flift2 :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a lift \<rightarrow> 'b lift)" where
wenzelm@25131
    99
  "flift2 f = (FLIFT x. Def (f x))"
huffman@16695
   100
huffman@16695
   101
lemma flift1_Def [simp]: "flift1 f\<cdot>(Def x) = (f x)"
huffman@40088
   102
by (simp add: flift1_def)
huffman@16695
   103
huffman@16695
   104
lemma flift2_Def [simp]: "flift2 f\<cdot>(Def x) = Def (f x)"
huffman@16695
   105
by (simp add: flift2_def)
huffman@16695
   106
huffman@16695
   107
lemma flift1_strict [simp]: "flift1 f\<cdot>\<bottom> = \<bottom>"
huffman@40088
   108
by (simp add: flift1_def)
huffman@16695
   109
huffman@16695
   110
lemma flift2_strict [simp]: "flift2 f\<cdot>\<bottom> = \<bottom>"
huffman@16695
   111
by (simp add: flift2_def)
huffman@16695
   112
huffman@16695
   113
lemma flift2_defined [simp]: "x \<noteq> \<bottom> \<Longrightarrow> (flift2 f)\<cdot>x \<noteq> \<bottom>"
huffman@16695
   114
by (erule lift_definedE, simp)
huffman@16695
   115
huffman@40321
   116
lemma flift2_bottom_iff [simp]: "(flift2 f\<cdot>x = \<bottom>) = (x = \<bottom>)"
huffman@19520
   117
by (cases x, simp_all)
huffman@19520
   118
huffman@40088
   119
lemma FLIFT_mono:
huffman@40088
   120
  "(\<And>x. f x \<sqsubseteq> g x) \<Longrightarrow> (FLIFT x. f x) \<sqsubseteq> (FLIFT x. g x)"
huffman@40088
   121
by (rule cfun_belowI, case_tac x, simp_all)
huffman@40088
   122
huffman@40088
   123
lemma cont2cont_flift1 [simp, cont2cont]:
huffman@40088
   124
  "\<lbrakk>\<And>y. cont (\<lambda>x. f x y)\<rbrakk> \<Longrightarrow> cont (\<lambda>x. FLIFT y. f x y)"
huffman@40088
   125
by (simp add: flift1_def cont2cont_LAM)
huffman@40088
   126
slotosch@2640
   127
end