src/HOL/HOLCF/Sprod.thy
author haftmann
Sun Jun 23 21:16:07 2013 +0200 (2013-06-23)
changeset 52435 6646bb548c6b
parent 49759 ecf1d5d87e5e
child 58880 0baae4311a9f
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/Sprod.thy
huffman@40502
     2
    Author:     Franz Regensburger
huffman@40502
     3
    Author:     Brian Huffman
huffman@15576
     4
*)
huffman@15576
     5
huffman@15576
     6
header {* The type of strict products *}
huffman@15576
     7
huffman@15577
     8
theory Sprod
huffman@40502
     9
imports Cfun
huffman@15577
    10
begin
huffman@15576
    11
wenzelm@36452
    12
default_sort pcpo
huffman@16082
    13
huffman@15591
    14
subsection {* Definition of strict product type *}
huffman@15591
    15
wenzelm@45695
    16
definition "sprod = {p::'a \<times> 'b. p = \<bottom> \<or> (fst p \<noteq> \<bottom> \<and> snd p \<noteq> \<bottom>)}"
wenzelm@45695
    17
huffman@49759
    18
pcpodef ('a, 'b) sprod (infixr "**" 20) = "sprod :: ('a \<times> 'b) set"
wenzelm@45695
    19
  unfolding sprod_def by simp_all
huffman@15576
    20
huffman@35525
    21
instance sprod :: ("{chfin,pcpo}", "{chfin,pcpo}") chfin
huffman@40098
    22
by (rule typedef_chfin [OF type_definition_sprod below_sprod_def])
huffman@25827
    23
wenzelm@35427
    24
type_notation (xsymbols)
wenzelm@35547
    25
  sprod  ("(_ \<otimes>/ _)" [21,20] 20)
wenzelm@35427
    26
type_notation (HTML output)
wenzelm@35547
    27
  sprod  ("(_ \<otimes>/ _)" [21,20] 20)
huffman@15576
    28
huffman@16059
    29
subsection {* Definitions of constants *}
huffman@15576
    30
wenzelm@25135
    31
definition
wenzelm@25135
    32
  sfst :: "('a ** 'b) \<rightarrow> 'a" where
huffman@40098
    33
  "sfst = (\<Lambda> p. fst (Rep_sprod p))"
wenzelm@25135
    34
wenzelm@25135
    35
definition
wenzelm@25135
    36
  ssnd :: "('a ** 'b) \<rightarrow> 'b" where
huffman@40098
    37
  "ssnd = (\<Lambda> p. snd (Rep_sprod p))"
huffman@15576
    38
wenzelm@25135
    39
definition
wenzelm@25135
    40
  spair :: "'a \<rightarrow> 'b \<rightarrow> ('a ** 'b)" where
huffman@40767
    41
  "spair = (\<Lambda> a b. Abs_sprod (seq\<cdot>b\<cdot>a, seq\<cdot>a\<cdot>b))"
huffman@15576
    42
wenzelm@25135
    43
definition
wenzelm@25135
    44
  ssplit :: "('a \<rightarrow> 'b \<rightarrow> 'c) \<rightarrow> ('a ** 'b) \<rightarrow> 'c" where
huffman@40767
    45
  "ssplit = (\<Lambda> f p. seq\<cdot>p\<cdot>(f\<cdot>(sfst\<cdot>p)\<cdot>(ssnd\<cdot>p)))"
wenzelm@25135
    46
wenzelm@25135
    47
syntax
huffman@41479
    48
  "_stuple" :: "[logic, args] \<Rightarrow> logic"  ("(1'(:_,/ _:'))")
huffman@41479
    49
huffman@15576
    50
translations
huffman@18078
    51
  "(:x, y, z:)" == "(:x, (:y, z:):)"
wenzelm@25131
    52
  "(:x, y:)"    == "CONST spair\<cdot>x\<cdot>y"
huffman@18078
    53
huffman@18078
    54
translations
wenzelm@25131
    55
  "\<Lambda>(CONST spair\<cdot>x\<cdot>y). t" == "CONST ssplit\<cdot>(\<Lambda> x y. t)"
huffman@15576
    56
huffman@16059
    57
subsection {* Case analysis *}
huffman@15576
    58
huffman@40767
    59
lemma spair_sprod: "(seq\<cdot>b\<cdot>a, seq\<cdot>a\<cdot>b) \<in> sprod"
huffman@40767
    60
by (simp add: sprod_def seq_conv_if)
huffman@40083
    61
huffman@40767
    62
lemma Rep_sprod_spair: "Rep_sprod (:a, b:) = (seq\<cdot>b\<cdot>a, seq\<cdot>a\<cdot>b)"
huffman@40098
    63
by (simp add: spair_def cont_Abs_sprod Abs_sprod_inverse spair_sprod)
huffman@40080
    64
huffman@40098
    65
lemmas Rep_sprod_simps =
huffman@40098
    66
  Rep_sprod_inject [symmetric] below_sprod_def
huffman@44066
    67
  prod_eq_iff below_prod_def
huffman@40098
    68
  Rep_sprod_strict Rep_sprod_spair
huffman@15576
    69
huffman@35783
    70
lemma sprodE [case_names bottom spair, cases type: sprod]:
huffman@40080
    71
  obtains "p = \<bottom>" | x y where "p = (:x, y:)" and "x \<noteq> \<bottom>" and "y \<noteq> \<bottom>"
huffman@40098
    72
using Rep_sprod [of p] by (auto simp add: sprod_def Rep_sprod_simps)
huffman@16059
    73
huffman@35783
    74
lemma sprod_induct [case_names bottom spair, induct type: sprod]:
huffman@25757
    75
  "\<lbrakk>P \<bottom>; \<And>x y. \<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> P (:x, y:)\<rbrakk> \<Longrightarrow> P x"
huffman@25757
    76
by (cases x, simp_all)
huffman@25757
    77
huffman@35900
    78
subsection {* Properties of \emph{spair} *}
huffman@16059
    79
huffman@16317
    80
lemma spair_strict1 [simp]: "(:\<bottom>, y:) = \<bottom>"
huffman@40098
    81
by (simp add: Rep_sprod_simps)
huffman@15576
    82
huffman@16317
    83
lemma spair_strict2 [simp]: "(:x, \<bottom>:) = \<bottom>"
huffman@40098
    84
by (simp add: Rep_sprod_simps)
huffman@25914
    85
huffman@40321
    86
lemma spair_bottom_iff [simp]: "((:x, y:) = \<bottom>) = (x = \<bottom> \<or> y = \<bottom>)"
huffman@40767
    87
by (simp add: Rep_sprod_simps seq_conv_if)
huffman@25914
    88
huffman@31076
    89
lemma spair_below_iff:
huffman@25914
    90
  "((:a, b:) \<sqsubseteq> (:c, d:)) = (a = \<bottom> \<or> b = \<bottom> \<or> (a \<sqsubseteq> c \<and> b \<sqsubseteq> d))"
huffman@40767
    91
by (simp add: Rep_sprod_simps seq_conv_if)
huffman@25914
    92
huffman@25914
    93
lemma spair_eq_iff:
huffman@25914
    94
  "((:a, b:) = (:c, d:)) =
huffman@25914
    95
    (a = c \<and> b = d \<or> (a = \<bottom> \<or> b = \<bottom>) \<and> (c = \<bottom> \<or> d = \<bottom>))"
huffman@40767
    96
by (simp add: Rep_sprod_simps seq_conv_if)
huffman@15576
    97
huffman@16317
    98
lemma spair_strict: "x = \<bottom> \<or> y = \<bottom> \<Longrightarrow> (:x, y:) = \<bottom>"
huffman@25914
    99
by simp
huffman@16059
   100
huffman@16212
   101
lemma spair_strict_rev: "(:x, y:) \<noteq> \<bottom> \<Longrightarrow> x \<noteq> \<bottom> \<and> y \<noteq> \<bottom>"
huffman@25914
   102
by simp
huffman@16059
   103
huffman@25914
   104
lemma spair_defined: "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> (:x, y:) \<noteq> \<bottom>"
huffman@25914
   105
by simp
huffman@15576
   106
huffman@16317
   107
lemma spair_defined_rev: "(:x, y:) = \<bottom> \<Longrightarrow> x = \<bottom> \<or> y = \<bottom>"
huffman@25914
   108
by simp
huffman@15576
   109
huffman@40095
   110
lemma spair_below:
huffman@40095
   111
  "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> (:x, y:) \<sqsubseteq> (:a, b:) = (x \<sqsubseteq> a \<and> y \<sqsubseteq> b)"
huffman@40095
   112
by (simp add: spair_below_iff)
huffman@40095
   113
huffman@16317
   114
lemma spair_eq:
huffman@16317
   115
  "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> ((:x, y:) = (:a, b:)) = (x = a \<and> y = b)"
huffman@25914
   116
by (simp add: spair_eq_iff)
huffman@16317
   117
huffman@16212
   118
lemma spair_inject:
huffman@16317
   119
  "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>; (:x, y:) = (:a, b:)\<rbrakk> \<Longrightarrow> x = a \<and> y = b"
huffman@16317
   120
by (rule spair_eq [THEN iffD1])
huffman@15576
   121
huffman@41430
   122
lemma inst_sprod_pcpo2: "\<bottom> = (:\<bottom>, \<bottom>:)"
huffman@16059
   123
by simp
huffman@15576
   124
huffman@33504
   125
lemma sprodE2: "(\<And>x y. p = (:x, y:) \<Longrightarrow> Q) \<Longrightarrow> Q"
huffman@33504
   126
by (cases p, simp only: inst_sprod_pcpo2, simp)
huffman@33504
   127
huffman@35900
   128
subsection {* Properties of \emph{sfst} and \emph{ssnd} *}
huffman@15576
   129
huffman@16212
   130
lemma sfst_strict [simp]: "sfst\<cdot>\<bottom> = \<bottom>"
huffman@40098
   131
by (simp add: sfst_def cont_Rep_sprod Rep_sprod_strict)
huffman@15576
   132
huffman@16212
   133
lemma ssnd_strict [simp]: "ssnd\<cdot>\<bottom> = \<bottom>"
huffman@40098
   134
by (simp add: ssnd_def cont_Rep_sprod Rep_sprod_strict)
huffman@15576
   135
huffman@16212
   136
lemma sfst_spair [simp]: "y \<noteq> \<bottom> \<Longrightarrow> sfst\<cdot>(:x, y:) = x"
huffman@40098
   137
by (simp add: sfst_def cont_Rep_sprod Rep_sprod_spair)
huffman@15576
   138
huffman@16212
   139
lemma ssnd_spair [simp]: "x \<noteq> \<bottom> \<Longrightarrow> ssnd\<cdot>(:x, y:) = y"
huffman@40098
   140
by (simp add: ssnd_def cont_Rep_sprod Rep_sprod_spair)
huffman@15576
   141
huffman@40321
   142
lemma sfst_bottom_iff [simp]: "(sfst\<cdot>p = \<bottom>) = (p = \<bottom>)"
huffman@25757
   143
by (cases p, simp_all)
huffman@16777
   144
huffman@40321
   145
lemma ssnd_bottom_iff [simp]: "(ssnd\<cdot>p = \<bottom>) = (p = \<bottom>)"
huffman@25757
   146
by (cases p, simp_all)
huffman@16317
   147
huffman@16777
   148
lemma sfst_defined: "p \<noteq> \<bottom> \<Longrightarrow> sfst\<cdot>p \<noteq> \<bottom>"
huffman@16777
   149
by simp
huffman@16777
   150
huffman@16777
   151
lemma ssnd_defined: "p \<noteq> \<bottom> \<Longrightarrow> ssnd\<cdot>p \<noteq> \<bottom>"
huffman@16777
   152
by simp
huffman@16777
   153
huffman@40094
   154
lemma spair_sfst_ssnd: "(:sfst\<cdot>p, ssnd\<cdot>p:) = p"
huffman@25757
   155
by (cases p, simp_all)
huffman@15576
   156
huffman@40436
   157
lemma below_sprod: "(x \<sqsubseteq> y) = (sfst\<cdot>x \<sqsubseteq> sfst\<cdot>y \<and> ssnd\<cdot>x \<sqsubseteq> ssnd\<cdot>y)"
huffman@40098
   158
by (simp add: Rep_sprod_simps sfst_def ssnd_def cont_Rep_sprod)
huffman@16317
   159
huffman@16751
   160
lemma eq_sprod: "(x = y) = (sfst\<cdot>x = sfst\<cdot>y \<and> ssnd\<cdot>x = ssnd\<cdot>y)"
huffman@31076
   161
by (auto simp add: po_eq_conv below_sprod)
huffman@16751
   162
huffman@40436
   163
lemma sfst_below_iff: "sfst\<cdot>x \<sqsubseteq> y \<longleftrightarrow> x \<sqsubseteq> (:y, ssnd\<cdot>x:)"
huffman@25881
   164
apply (cases "x = \<bottom>", simp, cases "y = \<bottom>", simp)
huffman@31076
   165
apply (simp add: below_sprod)
huffman@25881
   166
done
huffman@25881
   167
huffman@40436
   168
lemma ssnd_below_iff: "ssnd\<cdot>x \<sqsubseteq> y \<longleftrightarrow> x \<sqsubseteq> (:sfst\<cdot>x, y:)"
huffman@25881
   169
apply (cases "x = \<bottom>", simp, cases "y = \<bottom>", simp)
huffman@31076
   170
apply (simp add: below_sprod)
huffman@25881
   171
done
huffman@25881
   172
huffman@25881
   173
subsection {* Compactness *}
huffman@25881
   174
huffman@25881
   175
lemma compact_sfst: "compact x \<Longrightarrow> compact (sfst\<cdot>x)"
huffman@31076
   176
by (rule compactI, simp add: sfst_below_iff)
huffman@25881
   177
huffman@25881
   178
lemma compact_ssnd: "compact x \<Longrightarrow> compact (ssnd\<cdot>x)"
huffman@31076
   179
by (rule compactI, simp add: ssnd_below_iff)
huffman@25881
   180
huffman@25881
   181
lemma compact_spair: "\<lbrakk>compact x; compact y\<rbrakk> \<Longrightarrow> compact (:x, y:)"
huffman@40767
   182
by (rule compact_sprod, simp add: Rep_sprod_spair seq_conv_if)
huffman@25881
   183
huffman@25881
   184
lemma compact_spair_iff:
huffman@25881
   185
  "compact (:x, y:) = (x = \<bottom> \<or> y = \<bottom> \<or> (compact x \<and> compact y))"
huffman@25881
   186
apply (safe elim!: compact_spair)
huffman@25881
   187
apply (drule compact_sfst, simp)
huffman@25881
   188
apply (drule compact_ssnd, simp)
huffman@25881
   189
apply simp
huffman@25881
   190
apply simp
huffman@25881
   191
done
huffman@25881
   192
huffman@35900
   193
subsection {* Properties of \emph{ssplit} *}
huffman@15576
   194
huffman@16059
   195
lemma ssplit1 [simp]: "ssplit\<cdot>f\<cdot>\<bottom> = \<bottom>"
huffman@15591
   196
by (simp add: ssplit_def)
huffman@15591
   197
huffman@16920
   198
lemma ssplit2 [simp]: "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> ssplit\<cdot>f\<cdot>(:x, y:) = f\<cdot>x\<cdot>y"
huffman@15591
   199
by (simp add: ssplit_def)
huffman@15591
   200
huffman@16553
   201
lemma ssplit3 [simp]: "ssplit\<cdot>spair\<cdot>z = z"
huffman@25757
   202
by (cases z, simp_all)
huffman@15576
   203
huffman@25827
   204
subsection {* Strict product preserves flatness *}
huffman@25827
   205
huffman@35525
   206
instance sprod :: (flat, flat) flat
huffman@27310
   207
proof
huffman@27310
   208
  fix x y :: "'a \<otimes> 'b"
huffman@27310
   209
  assume "x \<sqsubseteq> y" thus "x = \<bottom> \<or> x = y"
huffman@27310
   210
    apply (induct x, simp)
huffman@27310
   211
    apply (induct y, simp)
huffman@31076
   212
    apply (simp add: spair_below_iff flat_below_iff)
huffman@27310
   213
    done
huffman@27310
   214
qed
huffman@25827
   215
huffman@26962
   216
end