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