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