src/HOL/Product_Type.thy
author wenzelm
Thu Mar 14 16:55:06 2019 +0100 (3 months ago)
changeset 69913 ca515cf61651
parent 69605 a96320074298
child 69922 4a9167f377b0
permissions -rw-r--r--
more specific keyword kinds;
haftmann@58469
     1
(*  Title:      HOL/Product_Type.thy
nipkow@10213
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
nipkow@10213
     3
    Copyright   1992  University of Cambridge
wenzelm@11777
     4
*)
nipkow@10213
     5
wenzelm@60758
     6
section \<open>Cartesian products\<close>
nipkow@10213
     7
nipkow@15131
     8
theory Product_Type
wenzelm@63575
     9
  imports Typedef Inductive Fun
wenzelm@69913
    10
  keywords "inductive_set" "coinductive_set" :: thy_defn
nipkow@15131
    11
begin
wenzelm@11838
    12
wenzelm@69593
    13
subsection \<open>\<^typ>\<open>bool\<close> is a datatype\<close>
haftmann@24699
    14
blanchet@62594
    15
free_constructors (discs_sels) case_bool for True | False
blanchet@58189
    16
  by auto
blanchet@55393
    17
wenzelm@61799
    18
text \<open>Avoid name clashes by prefixing the output of \<open>old_rep_datatype\<close> with \<open>old\<close>.\<close>
blanchet@55442
    19
wenzelm@60758
    20
setup \<open>Sign.mandatory_path "old"\<close>
blanchet@55393
    21
blanchet@58306
    22
old_rep_datatype True False by (auto intro: bool_induct)
haftmann@24699
    23
wenzelm@60758
    24
setup \<open>Sign.parent_path\<close>
blanchet@55393
    25
wenzelm@61799
    26
text \<open>But erase the prefix for properties that are not generated by \<open>free_constructors\<close>.\<close>
blanchet@55442
    27
wenzelm@60758
    28
setup \<open>Sign.mandatory_path "bool"\<close>
blanchet@55393
    29
blanchet@55393
    30
lemmas induct = old.bool.induct
blanchet@55393
    31
lemmas inducts = old.bool.inducts
blanchet@55642
    32
lemmas rec = old.bool.rec
blanchet@55642
    33
lemmas simps = bool.distinct bool.case bool.rec
blanchet@55393
    34
wenzelm@60758
    35
setup \<open>Sign.parent_path\<close>
blanchet@55393
    36
haftmann@24699
    37
declare case_split [cases type: bool]
wenzelm@67443
    38
  \<comment> \<open>prefer plain propositional version\<close>
haftmann@24699
    39
wenzelm@63400
    40
lemma [code]: "HOL.equal False P \<longleftrightarrow> \<not> P"
wenzelm@63575
    41
  and [code]: "HOL.equal True P \<longleftrightarrow> P"
wenzelm@63400
    42
  and [code]: "HOL.equal P False \<longleftrightarrow> \<not> P"
wenzelm@63400
    43
  and [code]: "HOL.equal P True \<longleftrightarrow> P"
wenzelm@63400
    44
  and [code nbe]: "HOL.equal P P \<longleftrightarrow> True"
haftmann@38857
    45
  by (simp_all add: equal)
haftmann@25534
    46
haftmann@43654
    47
lemma If_case_cert:
haftmann@43654
    48
  assumes "CASE \<equiv> (\<lambda>b. If b f g)"
haftmann@43654
    49
  shows "(CASE True \<equiv> f) &&& (CASE False \<equiv> g)"
haftmann@43654
    50
  using assms by simp_all
haftmann@43654
    51
haftmann@66251
    52
setup \<open>Code.declare_case_global @{thm If_case_cert}\<close>
haftmann@43654
    53
haftmann@52435
    54
code_printing
haftmann@52435
    55
  constant "HOL.equal :: bool \<Rightarrow> bool \<Rightarrow> bool" \<rightharpoonup> (Haskell) infix 4 "=="
haftmann@52435
    56
| class_instance "bool" :: "equal" \<rightharpoonup> (Haskell) -
haftmann@24699
    57
haftmann@26358
    58
wenzelm@61799
    59
subsection \<open>The \<open>unit\<close> type\<close>
wenzelm@11838
    60
wenzelm@49834
    61
typedef unit = "{True}"
wenzelm@45694
    62
  by auto
wenzelm@11838
    63
wenzelm@45694
    64
definition Unity :: unit  ("'(')")
wenzelm@45694
    65
  where "() = Abs_unit True"
wenzelm@11838
    66
blanchet@35828
    67
lemma unit_eq [no_atp]: "u = ()"
huffman@40590
    68
  by (induct u) (simp add: Unity_def)
wenzelm@11838
    69
wenzelm@60758
    70
text \<open>
wenzelm@11838
    71
  Simplification procedure for @{thm [source] unit_eq}.  Cannot use
wenzelm@11838
    72
  this rule directly --- it loops!
wenzelm@60758
    73
\<close>
wenzelm@11838
    74
wenzelm@60758
    75
simproc_setup unit_eq ("x::unit") = \<open>
wenzelm@43594
    76
  fn _ => fn _ => fn ct =>
wenzelm@59582
    77
    if HOLogic.is_unit (Thm.term_of ct) then NONE
wenzelm@43594
    78
    else SOME (mk_meta_eq @{thm unit_eq})
wenzelm@60758
    79
\<close>
wenzelm@11838
    80
blanchet@55469
    81
free_constructors case_unit for "()"
blanchet@58189
    82
  by auto
blanchet@55393
    83
wenzelm@61799
    84
text \<open>Avoid name clashes by prefixing the output of \<open>old_rep_datatype\<close> with \<open>old\<close>.\<close>
blanchet@55442
    85
wenzelm@60758
    86
setup \<open>Sign.mandatory_path "old"\<close>
blanchet@55393
    87
blanchet@58306
    88
old_rep_datatype "()" by simp
haftmann@24699
    89
wenzelm@60758
    90
setup \<open>Sign.parent_path\<close>
blanchet@55393
    91
wenzelm@61799
    92
text \<open>But erase the prefix for properties that are not generated by \<open>free_constructors\<close>.\<close>
blanchet@55442
    93
wenzelm@60758
    94
setup \<open>Sign.mandatory_path "unit"\<close>
blanchet@55393
    95
blanchet@55393
    96
lemmas induct = old.unit.induct
blanchet@55393
    97
lemmas inducts = old.unit.inducts
blanchet@55642
    98
lemmas rec = old.unit.rec
blanchet@55642
    99
lemmas simps = unit.case unit.rec
blanchet@55393
   100
wenzelm@60758
   101
setup \<open>Sign.parent_path\<close>
blanchet@55393
   102
wenzelm@63400
   103
lemma unit_all_eq1: "(\<And>x::unit. PROP P x) \<equiv> PROP P ()"
wenzelm@11838
   104
  by simp
wenzelm@11838
   105
wenzelm@63400
   106
lemma unit_all_eq2: "(\<And>x::unit. PROP P) \<equiv> PROP P"
wenzelm@11838
   107
  by (rule triv_forall_equality)
wenzelm@11838
   108
wenzelm@60758
   109
text \<open>
wenzelm@61799
   110
  This rewrite counters the effect of simproc \<open>unit_eq\<close> on @{term
wenzelm@63400
   111
  [source] "\<lambda>u::unit. f u"}, replacing it by @{term [source]
wenzelm@63400
   112
  f} rather than by @{term [source] "\<lambda>u. f ()"}.
wenzelm@60758
   113
\<close>
wenzelm@11838
   114
wenzelm@63400
   115
lemma unit_abs_eta_conv [simp]: "(\<lambda>u::unit. f ()) = f"
wenzelm@11838
   116
  by (rule ext) simp
nipkow@10213
   117
wenzelm@63400
   118
lemma UNIV_unit: "UNIV = {()}"
wenzelm@63400
   119
  by auto
haftmann@43866
   120
haftmann@30924
   121
instantiation unit :: default
haftmann@30924
   122
begin
haftmann@30924
   123
haftmann@30924
   124
definition "default = ()"
haftmann@30924
   125
haftmann@30924
   126
instance ..
haftmann@30924
   127
haftmann@30924
   128
end
nipkow@10213
   129
wenzelm@63400
   130
instantiation unit :: "{complete_boolean_algebra,complete_linorder,wellorder}"
nipkow@57016
   131
begin
nipkow@57016
   132
haftmann@57233
   133
definition less_eq_unit :: "unit \<Rightarrow> unit \<Rightarrow> bool"
wenzelm@63400
   134
  where "(_::unit) \<le> _ \<longleftrightarrow> True"
haftmann@57233
   135
wenzelm@63400
   136
lemma less_eq_unit [iff]: "u \<le> v" for u v :: unit
haftmann@57233
   137
  by (simp add: less_eq_unit_def)
haftmann@57233
   138
haftmann@57233
   139
definition less_unit :: "unit \<Rightarrow> unit \<Rightarrow> bool"
wenzelm@63400
   140
  where "(_::unit) < _ \<longleftrightarrow> False"
haftmann@57233
   141
wenzelm@63400
   142
lemma less_unit [iff]: "\<not> u < v" for u v :: unit
haftmann@57233
   143
  by (simp_all add: less_eq_unit_def less_unit_def)
haftmann@57233
   144
haftmann@57233
   145
definition bot_unit :: unit
wenzelm@63400
   146
  where [code_unfold]: "\<bottom> = ()"
haftmann@57233
   147
haftmann@57233
   148
definition top_unit :: unit
wenzelm@63400
   149
  where [code_unfold]: "\<top> = ()"
nipkow@57016
   150
haftmann@57233
   151
definition inf_unit :: "unit \<Rightarrow> unit \<Rightarrow> unit"
wenzelm@63400
   152
  where [simp]: "_ \<sqinter> _ = ()"
haftmann@57233
   153
haftmann@57233
   154
definition sup_unit :: "unit \<Rightarrow> unit \<Rightarrow> unit"
wenzelm@63400
   155
  where [simp]: "_ \<squnion> _ = ()"
haftmann@57233
   156
haftmann@57233
   157
definition Inf_unit :: "unit set \<Rightarrow> unit"
wenzelm@63400
   158
  where [simp]: "\<Sqinter>_ = ()"
nipkow@57016
   159
haftmann@57233
   160
definition Sup_unit :: "unit set \<Rightarrow> unit"
wenzelm@63400
   161
  where [simp]: "\<Squnion>_ = ()"
haftmann@57233
   162
haftmann@57233
   163
definition uminus_unit :: "unit \<Rightarrow> unit"
wenzelm@63400
   164
  where [simp]: "- _ = ()"
haftmann@57233
   165
haftmann@57233
   166
declare less_eq_unit_def [abs_def, code_unfold]
haftmann@57233
   167
  less_unit_def [abs_def, code_unfold]
haftmann@57233
   168
  inf_unit_def [abs_def, code_unfold]
haftmann@57233
   169
  sup_unit_def [abs_def, code_unfold]
haftmann@57233
   170
  Inf_unit_def [abs_def, code_unfold]
haftmann@57233
   171
  Sup_unit_def [abs_def, code_unfold]
haftmann@57233
   172
  uminus_unit_def [abs_def, code_unfold]
nipkow@57016
   173
nipkow@57016
   174
instance
haftmann@57233
   175
  by intro_classes auto
nipkow@57016
   176
nipkow@57016
   177
end
nipkow@57016
   178
wenzelm@63400
   179
lemma [code]: "HOL.equal u v \<longleftrightarrow> True" for u v :: unit
wenzelm@63400
   180
  unfolding equal unit_eq [of u] unit_eq [of v] by rule+
haftmann@26358
   181
haftmann@52435
   182
code_printing
haftmann@52435
   183
  type_constructor unit \<rightharpoonup>
haftmann@52435
   184
    (SML) "unit"
haftmann@52435
   185
    and (OCaml) "unit"
haftmann@52435
   186
    and (Haskell) "()"
haftmann@52435
   187
    and (Scala) "Unit"
haftmann@52435
   188
| constant Unity \<rightharpoonup>
haftmann@52435
   189
    (SML) "()"
haftmann@52435
   190
    and (OCaml) "()"
haftmann@52435
   191
    and (Haskell) "()"
haftmann@52435
   192
    and (Scala) "()"
haftmann@52435
   193
| class_instance unit :: equal \<rightharpoonup>
haftmann@52435
   194
    (Haskell) -
haftmann@52435
   195
| constant "HOL.equal :: unit \<Rightarrow> unit \<Rightarrow> bool" \<rightharpoonup>
haftmann@52435
   196
    (Haskell) infix 4 "=="
haftmann@26358
   197
haftmann@26358
   198
code_reserved SML
haftmann@26358
   199
  unit
haftmann@26358
   200
haftmann@26358
   201
code_reserved OCaml
haftmann@26358
   202
  unit
haftmann@26358
   203
haftmann@34886
   204
code_reserved Scala
haftmann@34886
   205
  Unit
haftmann@34886
   206
haftmann@26358
   207
wenzelm@60758
   208
subsection \<open>The product type\<close>
nipkow@10213
   209
wenzelm@60758
   210
subsubsection \<open>Type definition\<close>
haftmann@37166
   211
wenzelm@63400
   212
definition Pair_Rep :: "'a \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool"
wenzelm@63400
   213
  where "Pair_Rep a b = (\<lambda>x y. x = a \<and> y = b)"
nipkow@10213
   214
wenzelm@61076
   215
definition "prod = {f. \<exists>a b. f = Pair_Rep (a::'a) (b::'b)}"
wenzelm@45696
   216
wenzelm@61955
   217
typedef ('a, 'b) prod ("(_ \<times>/ _)" [21, 20] 20) = "prod :: ('a \<Rightarrow> 'b \<Rightarrow> bool) set"
wenzelm@45696
   218
  unfolding prod_def by auto
nipkow@10213
   219
wenzelm@61955
   220
type_notation (ASCII)
wenzelm@61955
   221
  prod  (infixr "*" 20)
nipkow@10213
   222
wenzelm@63400
   223
definition Pair :: "'a \<Rightarrow> 'b \<Rightarrow> 'a \<times> 'b"
wenzelm@63400
   224
  where "Pair a b = Abs_prod (Pair_Rep a b)"
haftmann@37166
   225
blanchet@55393
   226
lemma prod_cases: "(\<And>a b. P (Pair a b)) \<Longrightarrow> P p"
blanchet@55393
   227
  by (cases p) (auto simp add: prod_def Pair_def Pair_Rep_def)
blanchet@55393
   228
haftmann@61424
   229
free_constructors case_prod for Pair fst snd
blanchet@55393
   230
proof -
blanchet@55393
   231
  fix P :: bool and p :: "'a \<times> 'b"
blanchet@55393
   232
  show "(\<And>x1 x2. p = Pair x1 x2 \<Longrightarrow> P) \<Longrightarrow> P"
blanchet@55393
   233
    by (cases p) (auto simp add: prod_def Pair_def Pair_Rep_def)
haftmann@37166
   234
next
haftmann@37166
   235
  fix a c :: 'a and b d :: 'b
haftmann@37166
   236
  have "Pair_Rep a b = Pair_Rep c d \<longleftrightarrow> a = c \<and> b = d"
nipkow@39302
   237
    by (auto simp add: Pair_Rep_def fun_eq_iff)
haftmann@37389
   238
  moreover have "Pair_Rep a b \<in> prod" and "Pair_Rep c d \<in> prod"
haftmann@37389
   239
    by (auto simp add: prod_def)
haftmann@37166
   240
  ultimately show "Pair a b = Pair c d \<longleftrightarrow> a = c \<and> b = d"
haftmann@37389
   241
    by (simp add: Pair_def Abs_prod_inject)
haftmann@37166
   242
qed
haftmann@37166
   243
wenzelm@61799
   244
text \<open>Avoid name clashes by prefixing the output of \<open>old_rep_datatype\<close> with \<open>old\<close>.\<close>
blanchet@55442
   245
wenzelm@60758
   246
setup \<open>Sign.mandatory_path "old"\<close>
blanchet@55393
   247
blanchet@58306
   248
old_rep_datatype Pair
wenzelm@63400
   249
  by (erule prod_cases) (rule prod.inject)
blanchet@55393
   250
wenzelm@60758
   251
setup \<open>Sign.parent_path\<close>
blanchet@37704
   252
wenzelm@61799
   253
text \<open>But erase the prefix for properties that are not generated by \<open>free_constructors\<close>.\<close>
blanchet@55442
   254
wenzelm@60758
   255
setup \<open>Sign.mandatory_path "prod"\<close>
blanchet@55393
   256
haftmann@61424
   257
declare old.prod.inject [iff del]
blanchet@55393
   258
blanchet@55393
   259
lemmas induct = old.prod.induct
blanchet@55393
   260
lemmas inducts = old.prod.inducts
blanchet@55642
   261
lemmas rec = old.prod.rec
blanchet@55642
   262
lemmas simps = prod.inject prod.case prod.rec
blanchet@55393
   263
wenzelm@60758
   264
setup \<open>Sign.parent_path\<close>
blanchet@55393
   265
blanchet@55393
   266
declare prod.case [nitpick_simp del]
wenzelm@63566
   267
declare old.prod.case_cong_weak [cong del]
haftmann@61424
   268
declare prod.case_eq_if [mono]
haftmann@61424
   269
declare prod.split [no_atp]
haftmann@61424
   270
declare prod.split_asm [no_atp]
haftmann@61424
   271
haftmann@61424
   272
text \<open>
wenzelm@61799
   273
  @{thm [source] prod.split} could be declared as \<open>[split]\<close>
haftmann@61424
   274
  done after the Splitter has been speeded up significantly;
haftmann@61424
   275
  precompute the constants involved and don't do anything unless the
haftmann@61424
   276
  current goal contains one of those constants.
haftmann@61424
   277
\<close>
haftmann@37411
   278
haftmann@37166
   279
wenzelm@60758
   280
subsubsection \<open>Tuple syntax\<close>
haftmann@37166
   281
wenzelm@60758
   282
text \<open>
wenzelm@69593
   283
  Patterns -- extends pre-defined type \<^typ>\<open>pttrn\<close> used in
wenzelm@11777
   284
  abstractions.
wenzelm@60758
   285
\<close>
nipkow@10213
   286
wenzelm@41229
   287
nonterminal tuple_args and patterns
nipkow@10213
   288
syntax
wenzelm@63400
   289
  "_tuple"      :: "'a \<Rightarrow> tuple_args \<Rightarrow> 'a \<times> 'b"        ("(1'(_,/ _'))")
wenzelm@63400
   290
  "_tuple_arg"  :: "'a \<Rightarrow> tuple_args"                   ("_")
wenzelm@63400
   291
  "_tuple_args" :: "'a \<Rightarrow> tuple_args \<Rightarrow> tuple_args"     ("_,/ _")
wenzelm@63400
   292
  "_pattern"    :: "pttrn \<Rightarrow> patterns \<Rightarrow> pttrn"         ("'(_,/ _')")
wenzelm@63400
   293
  ""            :: "pttrn \<Rightarrow> patterns"                  ("_")
wenzelm@63400
   294
  "_patterns"   :: "pttrn \<Rightarrow> patterns \<Rightarrow> patterns"      ("_,/ _")
haftmann@63237
   295
  "_unit"       :: pttrn                                ("'(')")
nipkow@10213
   296
translations
haftmann@61124
   297
  "(x, y)" \<rightleftharpoons> "CONST Pair x y"
haftmann@61124
   298
  "_pattern x y" \<rightleftharpoons> "CONST Pair x y"
haftmann@61124
   299
  "_patterns x y" \<rightleftharpoons> "CONST Pair x y"
haftmann@61124
   300
  "_tuple x (_tuple_args y z)" \<rightleftharpoons> "_tuple x (_tuple_arg (_tuple y z))"
haftmann@61424
   301
  "\<lambda>(x, y, zs). b" \<rightleftharpoons> "CONST case_prod (\<lambda>x (y, zs). b)"
haftmann@61424
   302
  "\<lambda>(x, y). b" \<rightleftharpoons> "CONST case_prod (\<lambda>x y. b)"
haftmann@61124
   303
  "_abs (CONST Pair x y) t" \<rightharpoonup> "\<lambda>(x, y). t"
wenzelm@61799
   304
  \<comment> \<open>This rule accommodates tuples in \<open>case C \<dots> (x, y) \<dots> \<Rightarrow> \<dots>\<close>:
wenzelm@61799
   305
     The \<open>(x, y)\<close> is parsed as \<open>Pair x y\<close> because it is \<open>logic\<close>,
wenzelm@61799
   306
     not \<open>pttrn\<close>.\<close>
haftmann@63237
   307
  "\<lambda>(). b" \<rightleftharpoons> "CONST case_unit b"
haftmann@63237
   308
  "_abs (CONST Unity) t" \<rightharpoonup> "\<lambda>(). t"
nipkow@10213
   309
wenzelm@69593
   310
text \<open>print \<^term>\<open>case_prod f\<close> as \<^term>\<open>\<lambda>(x, y). f x y\<close> and
wenzelm@69593
   311
  \<^term>\<open>case_prod (\<lambda>x. f x)\<close> as \<^term>\<open>\<lambda>(x, y). f x y\<close>\<close>
haftmann@61226
   312
haftmann@61226
   313
typed_print_translation \<open>
haftmann@61226
   314
  let
haftmann@61424
   315
    fun case_prod_guess_names_tr' T [Abs (x, _, Abs _)] = raise Match
haftmann@61424
   316
      | case_prod_guess_names_tr' T [Abs (x, xT, t)] =
haftmann@61226
   317
          (case (head_of t) of
wenzelm@69593
   318
            Const (\<^const_syntax>\<open>case_prod\<close>, _) => raise Match
haftmann@61226
   319
          | _ =>
wenzelm@63575
   320
            let
haftmann@61226
   321
              val (_ :: yT :: _) = binder_types (domain_type T) handle Bind => raise Match;
haftmann@61226
   322
              val (y, t') = Syntax_Trans.atomic_abs_tr' ("y", yT, incr_boundvars 1 t $ Bound 0);
haftmann@61226
   323
              val (x', t'') = Syntax_Trans.atomic_abs_tr' (x, xT, t');
haftmann@61226
   324
            in
wenzelm@69593
   325
              Syntax.const \<^syntax_const>\<open>_abs\<close> $
wenzelm@69593
   326
                (Syntax.const \<^syntax_const>\<open>_pattern\<close> $ x' $ y) $ t''
haftmann@61226
   327
            end)
haftmann@61424
   328
      | case_prod_guess_names_tr' T [t] =
haftmann@61226
   329
          (case head_of t of
wenzelm@69593
   330
            Const (\<^const_syntax>\<open>case_prod\<close>, _) => raise Match
haftmann@61226
   331
          | _ =>
haftmann@61226
   332
            let
haftmann@61226
   333
              val (xT :: yT :: _) = binder_types (domain_type T) handle Bind => raise Match;
haftmann@61226
   334
              val (y, t') =
haftmann@61226
   335
                Syntax_Trans.atomic_abs_tr' ("y", yT, incr_boundvars 2 t $ Bound 1 $ Bound 0);
haftmann@61226
   336
              val (x', t'') = Syntax_Trans.atomic_abs_tr' ("x", xT, t');
haftmann@61226
   337
            in
wenzelm@69593
   338
              Syntax.const \<^syntax_const>\<open>_abs\<close> $
wenzelm@69593
   339
                (Syntax.const \<^syntax_const>\<open>_pattern\<close> $ x' $ y) $ t''
haftmann@61226
   340
            end)
haftmann@61424
   341
      | case_prod_guess_names_tr' _ _ = raise Match;
wenzelm@69593
   342
  in [(\<^const_syntax>\<open>case_prod\<close>, K case_prod_guess_names_tr')] end
haftmann@61226
   343
\<close>
haftmann@61226
   344
wenzelm@69593
   345
text \<open>Reconstruct pattern from (nested) \<^const>\<open>case_prod\<close>s,
haftmann@61425
   346
  avoiding eta-contraction of body; required for enclosing "let",
wenzelm@63400
   347
  if "let" does not avoid eta-contraction, which has been observed to occur.\<close>
haftmann@61425
   348
haftmann@61425
   349
print_translation \<open>
haftmann@61425
   350
  let
haftmann@61425
   351
    fun case_prod_tr' [Abs (x, T, t as (Abs abs))] =
haftmann@61425
   352
          (* case_prod (\<lambda>x y. t) \<Rightarrow> \<lambda>(x, y) t *)
haftmann@61425
   353
          let
haftmann@61425
   354
            val (y, t') = Syntax_Trans.atomic_abs_tr' abs;
haftmann@61425
   355
            val (x', t'') = Syntax_Trans.atomic_abs_tr' (x, T, t');
haftmann@61425
   356
          in
wenzelm@69593
   357
            Syntax.const \<^syntax_const>\<open>_abs\<close> $
wenzelm@69593
   358
              (Syntax.const \<^syntax_const>\<open>_pattern\<close> $ x' $ y) $ t''
haftmann@61425
   359
          end
wenzelm@69593
   360
      | case_prod_tr' [Abs (x, T, (s as Const (\<^const_syntax>\<open>case_prod\<close>, _) $ t))] =
haftmann@61425
   361
          (* case_prod (\<lambda>x. (case_prod (\<lambda>y z. t))) \<Rightarrow> \<lambda>(x, y, z). t *)
haftmann@61425
   362
          let
wenzelm@69593
   363
            val Const (\<^syntax_const>\<open>_abs\<close>, _) $
wenzelm@69593
   364
              (Const (\<^syntax_const>\<open>_pattern\<close>, _) $ y $ z) $ t' =
haftmann@61425
   365
                case_prod_tr' [t];
haftmann@61425
   366
            val (x', t'') = Syntax_Trans.atomic_abs_tr' (x, T, t');
haftmann@61425
   367
          in
wenzelm@69593
   368
            Syntax.const \<^syntax_const>\<open>_abs\<close> $
wenzelm@69593
   369
              (Syntax.const \<^syntax_const>\<open>_pattern\<close> $ x' $
wenzelm@69593
   370
                (Syntax.const \<^syntax_const>\<open>_patterns\<close> $ y $ z)) $ t''
haftmann@61425
   371
          end
wenzelm@69593
   372
      | case_prod_tr' [Const (\<^const_syntax>\<open>case_prod\<close>, _) $ t] =
haftmann@61425
   373
          (* case_prod (case_prod (\<lambda>x y z. t)) \<Rightarrow> \<lambda>((x, y), z). t *)
haftmann@61425
   374
          case_prod_tr' [(case_prod_tr' [t])]
haftmann@61425
   375
            (* inner case_prod_tr' creates next pattern *)
wenzelm@69593
   376
      | case_prod_tr' [Const (\<^syntax_const>\<open>_abs\<close>, _) $ x_y $ Abs abs] =
haftmann@61425
   377
          (* case_prod (\<lambda>pttrn z. t) \<Rightarrow> \<lambda>(pttrn, z). t *)
haftmann@61425
   378
          let val (z, t) = Syntax_Trans.atomic_abs_tr' abs in
wenzelm@69593
   379
            Syntax.const \<^syntax_const>\<open>_abs\<close> $
wenzelm@69593
   380
              (Syntax.const \<^syntax_const>\<open>_pattern\<close> $ x_y $ z) $ t
haftmann@61425
   381
          end
haftmann@61425
   382
      | case_prod_tr' _ = raise Match;
wenzelm@69593
   383
  in [(\<^const_syntax>\<open>case_prod\<close>, K case_prod_tr')] end
haftmann@61425
   384
\<close>
haftmann@61425
   385
nipkow@10213
   386
wenzelm@60758
   387
subsubsection \<open>Code generator setup\<close>
haftmann@37166
   388
haftmann@52435
   389
code_printing
haftmann@52435
   390
  type_constructor prod \<rightharpoonup>
haftmann@52435
   391
    (SML) infix 2 "*"
haftmann@52435
   392
    and (OCaml) infix 2 "*"
haftmann@52435
   393
    and (Haskell) "!((_),/ (_))"
haftmann@52435
   394
    and (Scala) "((_),/ (_))"
haftmann@52435
   395
| constant Pair \<rightharpoonup>
haftmann@52435
   396
    (SML) "!((_),/ (_))"
haftmann@52435
   397
    and (OCaml) "!((_),/ (_))"
haftmann@52435
   398
    and (Haskell) "!((_),/ (_))"
haftmann@52435
   399
    and (Scala) "!((_),/ (_))"
haftmann@52435
   400
| class_instance  prod :: equal \<rightharpoonup>
haftmann@52435
   401
    (Haskell) -
haftmann@52435
   402
| constant "HOL.equal :: 'a \<times> 'b \<Rightarrow> 'a \<times> 'b \<Rightarrow> bool" \<rightharpoonup>
haftmann@52435
   403
    (Haskell) infix 4 "=="
haftmann@61424
   404
| constant fst \<rightharpoonup> (Haskell) "fst"
haftmann@61424
   405
| constant snd \<rightharpoonup> (Haskell) "snd"
haftmann@37166
   406
haftmann@37166
   407
wenzelm@60758
   408
subsubsection \<open>Fundamental operations and properties\<close>
wenzelm@11838
   409
wenzelm@63400
   410
lemma Pair_inject: "(a, b) = (a', b') \<Longrightarrow> (a = a' \<Longrightarrow> b = b' \<Longrightarrow> R) \<Longrightarrow> R"
wenzelm@63400
   411
  by simp
bulwahn@49897
   412
wenzelm@63400
   413
lemma surj_pair [simp]: "\<exists>x y. p = (x, y)"
haftmann@37166
   414
  by (cases p) simp
nipkow@10213
   415
wenzelm@63400
   416
lemma fst_eqD: "fst (x, y) = a \<Longrightarrow> x = a"
wenzelm@11838
   417
  by simp
wenzelm@11838
   418
wenzelm@63400
   419
lemma snd_eqD: "snd (x, y) = a \<Longrightarrow> y = a"
wenzelm@11838
   420
  by simp
wenzelm@11838
   421
haftmann@61424
   422
lemma case_prod_unfold [nitpick_unfold]: "case_prod = (\<lambda>c p. c (fst p) (snd p))"
haftmann@61424
   423
  by (simp add: fun_eq_iff split: prod.split)
haftmann@61424
   424
haftmann@61424
   425
lemma case_prod_conv [simp, code]: "(case (a, b) of (c, d) \<Rightarrow> f c d) = f a b"
haftmann@61424
   426
  by (fact prod.case)
haftmann@61424
   427
blanchet@55393
   428
lemmas surjective_pairing = prod.collapse [symmetric]
wenzelm@11838
   429
huffman@44066
   430
lemma prod_eq_iff: "s = t \<longleftrightarrow> fst s = fst t \<and> snd s = snd t"
haftmann@37166
   431
  by (cases s, cases t) simp
haftmann@37166
   432
haftmann@37166
   433
lemma prod_eqI [intro?]: "fst p = fst q \<Longrightarrow> snd p = snd q \<Longrightarrow> p = q"
huffman@44066
   434
  by (simp add: prod_eq_iff)
haftmann@37166
   435
haftmann@61424
   436
lemma case_prodI: "f a b \<Longrightarrow> case (a, b) of (c, d) \<Rightarrow> f c d"
haftmann@61424
   437
  by (rule prod.case [THEN iffD2])
haftmann@37166
   438
haftmann@61424
   439
lemma case_prodD: "(case (a, b) of (c, d) \<Rightarrow> f c d) \<Longrightarrow> f a b"
haftmann@61424
   440
  by (rule prod.case [THEN iffD1])
haftmann@37166
   441
haftmann@61424
   442
lemma case_prod_Pair [simp]: "case_prod Pair = id"
nipkow@39302
   443
  by (simp add: fun_eq_iff split: prod.split)
haftmann@37166
   444
haftmann@61424
   445
lemma case_prod_eta: "(\<lambda>(x, y). f (x, y)) = f"
wenzelm@69593
   446
  \<comment> \<open>Subsumes the old \<open>split_Pair\<close> when \<^term>\<open>f\<close> is the identity function.\<close>
nipkow@39302
   447
  by (simp add: fun_eq_iff split: prod.split)
haftmann@37166
   448
nipkow@67575
   449
(* This looks like a sensible simp-rule but appears to do more harm than good:
nipkow@67575
   450
lemma case_prod_const [simp]: "(\<lambda>(_,_). c) = (\<lambda>_. c)"
nipkow@67575
   451
by(rule case_prod_eta)
nipkow@67575
   452
*)
nipkow@67575
   453
haftmann@61424
   454
lemma case_prod_comp: "(case x of (a, b) \<Rightarrow> (f \<circ> g) a b) = f (g (fst x)) (snd x)"
haftmann@37166
   455
  by (cases x) simp
haftmann@37166
   456
haftmann@61424
   457
lemma The_case_prod: "The (case_prod P) = (THE xy. P (fst xy) (snd xy))"
blanchet@55414
   458
  by (simp add: case_prod_unfold)
haftmann@37166
   459
wenzelm@63400
   460
lemma cond_case_prod_eta: "(\<And>x y. f x y = g (x, y)) \<Longrightarrow> (\<lambda>(x, y). f x y) = g"
haftmann@61424
   461
  by (simp add: case_prod_eta)
haftmann@37166
   462
wenzelm@63400
   463
lemma split_paired_all [no_atp]: "(\<And>x. PROP P x) \<equiv> (\<And>a b. PROP P (a, b))"
wenzelm@11820
   464
proof
wenzelm@11820
   465
  fix a b
wenzelm@63400
   466
  assume "\<And>x. PROP P x"
wenzelm@19535
   467
  then show "PROP P (a, b)" .
wenzelm@11820
   468
next
wenzelm@11820
   469
  fix x
wenzelm@63400
   470
  assume "\<And>a b. PROP P (a, b)"
wenzelm@60758
   471
  from \<open>PROP P (fst x, snd x)\<close> show "PROP P x" by simp
wenzelm@11820
   472
qed
wenzelm@11820
   473
wenzelm@60758
   474
text \<open>
wenzelm@11838
   475
  The rule @{thm [source] split_paired_all} does not work with the
wenzelm@11838
   476
  Simplifier because it also affects premises in congrence rules,
wenzelm@63400
   477
  where this can lead to premises of the form \<open>\<And>a b. \<dots> = ?P(a, b)\<close>
wenzelm@63400
   478
  which cannot be solved by reflexivity.
wenzelm@60758
   479
\<close>
wenzelm@11838
   480
haftmann@26358
   481
lemmas split_tupled_all = split_paired_all unit_all_eq2
haftmann@26358
   482
wenzelm@60758
   483
ML \<open>
wenzelm@11838
   484
  (* replace parameters of product type by individual component parameters *)
wenzelm@11838
   485
  local (* filtering with exists_paired_all is an essential optimization *)
wenzelm@69593
   486
    fun exists_paired_all (Const (\<^const_name>\<open>Pure.all\<close>, _) $ Abs (_, T, t)) =
wenzelm@11838
   487
          can HOLogic.dest_prodT T orelse exists_paired_all t
wenzelm@11838
   488
      | exists_paired_all (t $ u) = exists_paired_all t orelse exists_paired_all u
wenzelm@11838
   489
      | exists_paired_all (Abs (_, _, t)) = exists_paired_all t
wenzelm@11838
   490
      | exists_paired_all _ = false;
wenzelm@51717
   491
    val ss =
wenzelm@51717
   492
      simpset_of
wenzelm@69593
   493
       (put_simpset HOL_basic_ss \<^context>
wenzelm@51717
   494
        addsimps [@{thm split_paired_all}, @{thm unit_all_eq2}, @{thm unit_abs_eta_conv}]
wenzelm@69593
   495
        addsimprocs [\<^simproc>\<open>unit_eq\<close>]);
wenzelm@11838
   496
  in
wenzelm@51717
   497
    fun split_all_tac ctxt = SUBGOAL (fn (t, i) =>
wenzelm@51717
   498
      if exists_paired_all t then safe_full_simp_tac (put_simpset ss ctxt) i else no_tac);
wenzelm@51717
   499
wenzelm@51717
   500
    fun unsafe_split_all_tac ctxt = SUBGOAL (fn (t, i) =>
wenzelm@51717
   501
      if exists_paired_all t then full_simp_tac (put_simpset ss ctxt) i else no_tac);
wenzelm@51717
   502
wenzelm@51717
   503
    fun split_all ctxt th =
wenzelm@51717
   504
      if exists_paired_all (Thm.prop_of th)
wenzelm@51717
   505
      then full_simplify (put_simpset ss ctxt) th else th;
wenzelm@11838
   506
  end;
wenzelm@60758
   507
\<close>
wenzelm@11838
   508
wenzelm@60758
   509
setup \<open>map_theory_claset (fn ctxt => ctxt addSbefore ("split_all_tac", split_all_tac))\<close>
wenzelm@11838
   510
wenzelm@63400
   511
lemma split_paired_All [simp, no_atp]: "(\<forall>x. P x) \<longleftrightarrow> (\<forall>a b. P (a, b))"
wenzelm@61799
   512
  \<comment> \<open>\<open>[iff]\<close> is not a good idea because it makes \<open>blast\<close> loop\<close>
wenzelm@11838
   513
  by fast
wenzelm@11838
   514
wenzelm@63400
   515
lemma split_paired_Ex [simp, no_atp]: "(\<exists>x. P x) \<longleftrightarrow> (\<exists>a b. P (a, b))"
haftmann@26358
   516
  by fast
haftmann@26358
   517
blanchet@47740
   518
lemma split_paired_The [no_atp]: "(THE x. P x) = (THE (a, b). P (a, b))"
wenzelm@61799
   519
  \<comment> \<open>Can't be added to simpset: loops!\<close>
haftmann@61424
   520
  by (simp add: case_prod_eta)
wenzelm@11838
   521
wenzelm@60758
   522
text \<open>
haftmann@61424
   523
  Simplification procedure for @{thm [source] cond_case_prod_eta}.  Using
haftmann@61424
   524
  @{thm [source] case_prod_eta} as a rewrite rule is not general enough,
haftmann@61424
   525
  and using @{thm [source] cond_case_prod_eta} directly would render some
wenzelm@61799
   526
  existing proofs very inefficient; similarly for \<open>prod.case_eq_if\<close>.
wenzelm@60758
   527
\<close>
wenzelm@11838
   528
wenzelm@60758
   529
ML \<open>
wenzelm@11838
   530
local
haftmann@61424
   531
  val cond_case_prod_eta_ss =
wenzelm@69593
   532
    simpset_of (put_simpset HOL_basic_ss \<^context> addsimps @{thms cond_case_prod_eta});
wenzelm@35364
   533
  fun Pair_pat k 0 (Bound m) = (m = k)
wenzelm@69593
   534
    | Pair_pat k i (Const (\<^const_name>\<open>Pair\<close>,  _) $ Bound m $ t) =
wenzelm@35364
   535
        i > 0 andalso m = k + i andalso Pair_pat k (i - 1) t
wenzelm@35364
   536
    | Pair_pat _ _ _ = false;
wenzelm@35364
   537
  fun no_args k i (Abs (_, _, t)) = no_args (k + 1) i t
wenzelm@35364
   538
    | no_args k i (t $ u) = no_args k i t andalso no_args k i u
wenzelm@35364
   539
    | no_args k i (Bound m) = m < k orelse m > k + i
wenzelm@35364
   540
    | no_args _ _ _ = true;
wenzelm@35364
   541
  fun split_pat tp i (Abs  (_, _, t)) = if tp 0 i t then SOME (i, t) else NONE
wenzelm@69593
   542
    | split_pat tp i (Const (\<^const_name>\<open>case_prod\<close>, _) $ Abs (_, _, t)) = split_pat tp (i + 1) t
wenzelm@35364
   543
    | split_pat tp i _ = NONE;
wenzelm@51717
   544
  fun metaeq ctxt lhs rhs = mk_meta_eq (Goal.prove ctxt [] []
wenzelm@35364
   545
        (HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs)))
haftmann@61424
   546
        (K (simp_tac (put_simpset cond_case_prod_eta_ss ctxt) 1)));
wenzelm@11838
   547
wenzelm@35364
   548
  fun beta_term_pat k i (Abs (_, _, t)) = beta_term_pat (k + 1) i t
wenzelm@35364
   549
    | beta_term_pat k i (t $ u) =
wenzelm@35364
   550
        Pair_pat k i (t $ u) orelse (beta_term_pat k i t andalso beta_term_pat k i u)
wenzelm@35364
   551
    | beta_term_pat k i t = no_args k i t;
wenzelm@35364
   552
  fun eta_term_pat k i (f $ arg) = no_args k i f andalso Pair_pat k i arg
wenzelm@35364
   553
    | eta_term_pat _ _ _ = false;
wenzelm@11838
   554
  fun subst arg k i (Abs (x, T, t)) = Abs (x, T, subst arg (k+1) i t)
wenzelm@35364
   555
    | subst arg k i (t $ u) =
wenzelm@35364
   556
        if Pair_pat k i (t $ u) then incr_boundvars k arg
wenzelm@35364
   557
        else (subst arg k i t $ subst arg k i u)
wenzelm@35364
   558
    | subst arg k i t = t;
wenzelm@43595
   559
in
wenzelm@69593
   560
  fun beta_proc ctxt (s as Const (\<^const_name>\<open>case_prod\<close>, _) $ Abs (_, _, t) $ arg) =
wenzelm@11838
   561
        (case split_pat beta_term_pat 1 t of
wenzelm@51717
   562
          SOME (i, f) => SOME (metaeq ctxt s (subst arg 0 i f))
skalberg@15531
   563
        | NONE => NONE)
wenzelm@35364
   564
    | beta_proc _ _ = NONE;
wenzelm@69593
   565
  fun eta_proc ctxt (s as Const (\<^const_name>\<open>case_prod\<close>, _) $ Abs (_, _, t)) =
wenzelm@11838
   566
        (case split_pat eta_term_pat 1 t of
haftmann@58468
   567
          SOME (_, ft) => SOME (metaeq ctxt s (let val f $ _ = ft in f end))
skalberg@15531
   568
        | NONE => NONE)
wenzelm@35364
   569
    | eta_proc _ _ = NONE;
wenzelm@11838
   570
end;
wenzelm@60758
   571
\<close>
haftmann@61424
   572
simproc_setup case_prod_beta ("case_prod f z") =
wenzelm@60758
   573
  \<open>fn _ => fn ctxt => fn ct => beta_proc ctxt (Thm.term_of ct)\<close>
haftmann@61424
   574
simproc_setup case_prod_eta ("case_prod f") =
wenzelm@60758
   575
  \<open>fn _ => fn ctxt => fn ct => eta_proc ctxt (Thm.term_of ct)\<close>
wenzelm@11838
   576
haftmann@61424
   577
lemma case_prod_beta': "(\<lambda>(x,y). f x y) = (\<lambda>x. f (fst x) (snd x))"
hoelzl@50104
   578
  by (auto simp: fun_eq_iff)
hoelzl@50104
   579
wenzelm@60758
   580
text \<open>
wenzelm@69593
   581
  \<^medskip> \<^const>\<open>case_prod\<close> used as a logical connective or set former.
wenzelm@11838
   582
wenzelm@63400
   583
  \<^medskip> These rules are for use with \<open>blast\<close>; could instead
wenzelm@61799
   584
  call \<open>simp\<close> using @{thm [source] prod.split} as rewrite.\<close>
wenzelm@11838
   585
haftmann@61424
   586
lemma case_prodI2:
haftmann@61424
   587
  "\<And>p. (\<And>a b. p = (a, b) \<Longrightarrow> c a b) \<Longrightarrow> case p of (a, b) \<Rightarrow> c a b"
haftmann@61424
   588
  by (simp add: split_tupled_all)
wenzelm@11838
   589
haftmann@61424
   590
lemma case_prodI2':
haftmann@61424
   591
  "\<And>p. (\<And>a b. (a, b) = p \<Longrightarrow> c a b x) \<Longrightarrow> (case p of (a, b) \<Rightarrow> c a b) x"
haftmann@61424
   592
  by (simp add: split_tupled_all)
wenzelm@11838
   593
haftmann@61424
   594
lemma case_prodE [elim!]:
haftmann@61424
   595
  "(case p of (a, b) \<Rightarrow> c a b) \<Longrightarrow> (\<And>x y. p = (x, y) \<Longrightarrow> c x y \<Longrightarrow> Q) \<Longrightarrow> Q"
haftmann@61424
   596
  by (induct p) simp
wenzelm@11838
   597
haftmann@61424
   598
lemma case_prodE' [elim!]:
haftmann@61424
   599
  "(case p of (a, b) \<Rightarrow> c a b) z \<Longrightarrow> (\<And>x y. p = (x, y) \<Longrightarrow> c x y z \<Longrightarrow> Q) \<Longrightarrow> Q"
haftmann@61424
   600
  by (induct p) simp
wenzelm@11838
   601
haftmann@61424
   602
lemma case_prodE2:
haftmann@61424
   603
  assumes q: "Q (case z of (a, b) \<Rightarrow> P a b)"
haftmann@61424
   604
    and r: "\<And>x y. z = (x, y) \<Longrightarrow> Q (P x y) \<Longrightarrow> R"
haftmann@61424
   605
  shows R
haftmann@61424
   606
proof (rule r)
haftmann@61424
   607
  show "z = (fst z, snd z)" by simp
haftmann@61424
   608
  then show "Q (P (fst z) (snd z))"
haftmann@61424
   609
    using q by (simp add: case_prod_unfold)
wenzelm@11838
   610
qed
wenzelm@11838
   611
wenzelm@63400
   612
lemma case_prodD': "(case (a, b) of (c, d) \<Rightarrow> R c d) c \<Longrightarrow> R a b c"
wenzelm@11838
   613
  by simp
wenzelm@11838
   614
wenzelm@63400
   615
lemma mem_case_prodI: "z \<in> c a b \<Longrightarrow> z \<in> (case (a, b) of (d, e) \<Rightarrow> c d e)"
wenzelm@11838
   616
  by simp
wenzelm@11838
   617
haftmann@61424
   618
lemma mem_case_prodI2 [intro!]:
haftmann@61127
   619
  "\<And>p. (\<And>a b. p = (a, b) \<Longrightarrow> z \<in> c a b) \<Longrightarrow> z \<in> (case p of (a, b) \<Rightarrow> c a b)"
haftmann@61127
   620
  by (simp only: split_tupled_all) simp
wenzelm@11838
   621
wenzelm@61799
   622
declare mem_case_prodI [intro!] \<comment> \<open>postponed to maintain traditional declaration order!\<close>
wenzelm@61799
   623
declare case_prodI2' [intro!] \<comment> \<open>postponed to maintain traditional declaration order!\<close>
wenzelm@61799
   624
declare case_prodI2 [intro!] \<comment> \<open>postponed to maintain traditional declaration order!\<close>
wenzelm@61799
   625
declare case_prodI [intro!] \<comment> \<open>postponed to maintain traditional declaration order!\<close>
wenzelm@63575
   626
haftmann@61424
   627
lemma mem_case_prodE [elim!]:
haftmann@61424
   628
  assumes "z \<in> case_prod c p"
haftmann@58468
   629
  obtains x y where "p = (x, y)" and "z \<in> c x y"
haftmann@61424
   630
  using assms by (rule case_prodE2)
wenzelm@11838
   631
wenzelm@60758
   632
ML \<open>
wenzelm@11838
   633
local (* filtering with exists_p_split is an essential optimization *)
wenzelm@69593
   634
  fun exists_p_split (Const (\<^const_name>\<open>case_prod\<close>,_) $ _ $ (Const (\<^const_name>\<open>Pair\<close>,_)$_$_)) = true
wenzelm@11838
   635
    | exists_p_split (t $ u) = exists_p_split t orelse exists_p_split u
wenzelm@11838
   636
    | exists_p_split (Abs (_, _, t)) = exists_p_split t
wenzelm@11838
   637
    | exists_p_split _ = false;
wenzelm@11838
   638
in
wenzelm@63575
   639
  fun split_conv_tac ctxt = SUBGOAL (fn (t, i) =>
wenzelm@63575
   640
    if exists_p_split t
wenzelm@63575
   641
    then safe_full_simp_tac (put_simpset HOL_basic_ss ctxt addsimps @{thms case_prod_conv}) i
wenzelm@63575
   642
    else no_tac);
wenzelm@11838
   643
end;
wenzelm@60758
   644
\<close>
wenzelm@26340
   645
wenzelm@11838
   646
(* This prevents applications of splitE for already splitted arguments leading
wenzelm@11838
   647
   to quite time-consuming computations (in particular for nested tuples) *)
wenzelm@60758
   648
setup \<open>map_theory_claset (fn ctxt => ctxt addSbefore ("split_conv_tac", split_conv_tac))\<close>
wenzelm@11838
   649
wenzelm@63400
   650
lemma split_eta_SetCompr [simp, no_atp]: "(\<lambda>u. \<exists>x y. u = (x, y) \<and> P (x, y)) = P"
wenzelm@18372
   651
  by (rule ext) fast
wenzelm@11838
   652
wenzelm@63400
   653
lemma split_eta_SetCompr2 [simp, no_atp]: "(\<lambda>u. \<exists>x y. u = (x, y) \<and> P x y) = case_prod P"
wenzelm@18372
   654
  by (rule ext) fast
wenzelm@11838
   655
wenzelm@63400
   656
lemma split_part [simp]: "(\<lambda>(a,b). P \<and> Q a b) = (\<lambda>ab. P \<and> case_prod Q ab)"
wenzelm@61799
   657
  \<comment> \<open>Allows simplifications of nested splits in case of independent predicates.\<close>
wenzelm@18372
   658
  by (rule ext) blast
wenzelm@11838
   659
nipkow@14337
   660
(* Do NOT make this a simp rule as it
nipkow@14337
   661
   a) only helps in special situations
nipkow@14337
   662
   b) can lead to nontermination in the presence of split_def
nipkow@14337
   663
*)
wenzelm@63575
   664
lemma split_comp_eq:
wenzelm@63400
   665
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c"
wenzelm@63400
   666
    and g :: "'d \<Rightarrow> 'a"
wenzelm@63400
   667
  shows "(\<lambda>u. f (g (fst u)) (snd u)) = case_prod (\<lambda>x. f (g x))"
wenzelm@18372
   668
  by (rule ext) auto
oheimb@14101
   669
wenzelm@63400
   670
lemma pair_imageI [intro]: "(a, b) \<in> A \<Longrightarrow> f a b \<in> (\<lambda>(a, b). f a b) ` A"
wenzelm@63400
   671
  by (rule image_eqI [where x = "(a, b)"]) auto
haftmann@26358
   672
nipkow@68457
   673
lemma Collect_const_case_prod[simp]: "{(a,b). P} = (if P then UNIV else {})"
nipkow@68457
   674
by auto
nipkow@68457
   675
wenzelm@63400
   676
lemma The_split_eq [simp]: "(THE (x',y'). x = x' \<and> y = y') = (x, y)"
wenzelm@11838
   677
  by blast
wenzelm@11838
   678
wenzelm@11838
   679
(*
wenzelm@11838
   680
the following  would be slightly more general,
wenzelm@11838
   681
but cannot be used as rewrite rule:
wenzelm@11838
   682
### Cannot add premise as rewrite rule because it contains (type) unknowns:
wenzelm@11838
   683
### ?y = .x
wenzelm@11838
   684
Goal "[| P y; !!x. P x ==> x = y |] ==> (@(x',y). x = x' & P y) = (x,y)"
paulson@14208
   685
by (rtac some_equality 1)
paulson@14208
   686
by ( Simp_tac 1)
paulson@14208
   687
by (split_all_tac 1)
paulson@14208
   688
by (Asm_full_simp_tac 1)
wenzelm@11838
   689
qed "The_split_eq";
wenzelm@11838
   690
*)
wenzelm@11838
   691
wenzelm@63400
   692
lemma case_prod_beta: "case_prod f p = f (fst p) (snd p)"
haftmann@61424
   693
  by (fact prod.case_eq_if)
bulwahn@26143
   694
blanchet@55417
   695
lemma prod_cases3 [cases type]:
haftmann@24699
   696
  obtains (fields) a b c where "y = (a, b, c)"
haftmann@24699
   697
  by (cases y, case_tac b) blast
haftmann@24699
   698
haftmann@24699
   699
lemma prod_induct3 [case_names fields, induct type]:
wenzelm@63400
   700
  "(\<And>a b c. P (a, b, c)) \<Longrightarrow> P x"
haftmann@24699
   701
  by (cases x) blast
haftmann@24699
   702
blanchet@55417
   703
lemma prod_cases4 [cases type]:
haftmann@24699
   704
  obtains (fields) a b c d where "y = (a, b, c, d)"
haftmann@24699
   705
  by (cases y, case_tac c) blast
haftmann@24699
   706
haftmann@24699
   707
lemma prod_induct4 [case_names fields, induct type]:
wenzelm@63400
   708
  "(\<And>a b c d. P (a, b, c, d)) \<Longrightarrow> P x"
haftmann@24699
   709
  by (cases x) blast
haftmann@24699
   710
blanchet@55417
   711
lemma prod_cases5 [cases type]:
haftmann@24699
   712
  obtains (fields) a b c d e where "y = (a, b, c, d, e)"
haftmann@24699
   713
  by (cases y, case_tac d) blast
haftmann@24699
   714
haftmann@24699
   715
lemma prod_induct5 [case_names fields, induct type]:
wenzelm@63400
   716
  "(\<And>a b c d e. P (a, b, c, d, e)) \<Longrightarrow> P x"
haftmann@24699
   717
  by (cases x) blast
haftmann@24699
   718
blanchet@55417
   719
lemma prod_cases6 [cases type]:
haftmann@24699
   720
  obtains (fields) a b c d e f where "y = (a, b, c, d, e, f)"
haftmann@24699
   721
  by (cases y, case_tac e) blast
haftmann@24699
   722
haftmann@24699
   723
lemma prod_induct6 [case_names fields, induct type]:
wenzelm@63400
   724
  "(\<And>a b c d e f. P (a, b, c, d, e, f)) \<Longrightarrow> P x"
haftmann@24699
   725
  by (cases x) blast
haftmann@24699
   726
blanchet@55417
   727
lemma prod_cases7 [cases type]:
haftmann@24699
   728
  obtains (fields) a b c d e f g where "y = (a, b, c, d, e, f, g)"
haftmann@24699
   729
  by (cases y, case_tac f) blast
haftmann@24699
   730
haftmann@24699
   731
lemma prod_induct7 [case_names fields, induct type]:
wenzelm@63400
   732
  "(\<And>a b c d e f g. P (a, b, c, d, e, f, g)) \<Longrightarrow> P x"
haftmann@24699
   733
  by (cases x) blast
haftmann@24699
   734
wenzelm@63400
   735
definition internal_case_prod :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'a \<times> 'b \<Rightarrow> 'c"
wenzelm@63400
   736
  where "internal_case_prod \<equiv> case_prod"
haftmann@37166
   737
haftmann@61424
   738
lemma internal_case_prod_conv: "internal_case_prod c (a, b) = c a b"
haftmann@61424
   739
  by (simp only: internal_case_prod_def case_prod_conv)
haftmann@37166
   740
wenzelm@69605
   741
ML_file \<open>Tools/split_rule.ML\<close>
haftmann@37166
   742
haftmann@61424
   743
hide_const internal_case_prod
haftmann@37166
   744
haftmann@24699
   745
wenzelm@60758
   746
subsubsection \<open>Derived operations\<close>
haftmann@26358
   747
wenzelm@63400
   748
definition curry :: "('a \<times> 'b \<Rightarrow> 'c) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'c"
wenzelm@63400
   749
  where "curry = (\<lambda>c x y. c (x, y))"
haftmann@37166
   750
haftmann@37166
   751
lemma curry_conv [simp, code]: "curry f a b = f (a, b)"
haftmann@37166
   752
  by (simp add: curry_def)
haftmann@37166
   753
haftmann@37166
   754
lemma curryI [intro!]: "f (a, b) \<Longrightarrow> curry f a b"
haftmann@37166
   755
  by (simp add: curry_def)
haftmann@37166
   756
haftmann@37166
   757
lemma curryD [dest!]: "curry f a b \<Longrightarrow> f (a, b)"
haftmann@37166
   758
  by (simp add: curry_def)
haftmann@37166
   759
haftmann@37166
   760
lemma curryE: "curry f a b \<Longrightarrow> (f (a, b) \<Longrightarrow> Q) \<Longrightarrow> Q"
haftmann@37166
   761
  by (simp add: curry_def)
haftmann@37166
   762
haftmann@61424
   763
lemma curry_case_prod [simp]: "curry (case_prod f) = f"
haftmann@61032
   764
  by (simp add: curry_def case_prod_unfold)
haftmann@37166
   765
haftmann@61424
   766
lemma case_prod_curry [simp]: "case_prod (curry f) = f"
haftmann@61032
   767
  by (simp add: curry_def case_prod_unfold)
haftmann@37166
   768
Andreas@54630
   769
lemma curry_K: "curry (\<lambda>x. c) = (\<lambda>x y. c)"
wenzelm@63400
   770
  by (simp add: fun_eq_iff)
Andreas@54630
   771
wenzelm@63400
   772
text \<open>The composition-uncurry combinator.\<close>
haftmann@26358
   773
haftmann@37751
   774
notation fcomp (infixl "\<circ>>" 60)
haftmann@26358
   775
wenzelm@63400
   776
definition scomp :: "('a \<Rightarrow> 'b \<times> 'c) \<Rightarrow> ('b \<Rightarrow> 'c \<Rightarrow> 'd) \<Rightarrow> 'a \<Rightarrow> 'd"  (infixl "\<circ>\<rightarrow>" 60)
wenzelm@63400
   777
  where "f \<circ>\<rightarrow> g = (\<lambda>x. case_prod g (f x))"
haftmann@26358
   778
haftmann@37678
   779
lemma scomp_unfold: "scomp = (\<lambda>f g x. g (fst (f x)) (snd (f x)))"
blanchet@55414
   780
  by (simp add: fun_eq_iff scomp_def case_prod_unfold)
haftmann@37678
   781
haftmann@61424
   782
lemma scomp_apply [simp]: "(f \<circ>\<rightarrow> g) x = case_prod g (f x)"
blanchet@55414
   783
  by (simp add: scomp_unfold case_prod_unfold)
haftmann@26358
   784
haftmann@37751
   785
lemma Pair_scomp: "Pair x \<circ>\<rightarrow> f = f x"
huffman@44921
   786
  by (simp add: fun_eq_iff)
haftmann@26358
   787
haftmann@37751
   788
lemma scomp_Pair: "x \<circ>\<rightarrow> Pair = x"
huffman@44921
   789
  by (simp add: fun_eq_iff)
haftmann@26358
   790
haftmann@37751
   791
lemma scomp_scomp: "(f \<circ>\<rightarrow> g) \<circ>\<rightarrow> h = f \<circ>\<rightarrow> (\<lambda>x. g x \<circ>\<rightarrow> h)"
nipkow@39302
   792
  by (simp add: fun_eq_iff scomp_unfold)
haftmann@26358
   793
haftmann@37751
   794
lemma scomp_fcomp: "(f \<circ>\<rightarrow> g) \<circ>> h = f \<circ>\<rightarrow> (\<lambda>x. g x \<circ>> h)"
nipkow@39302
   795
  by (simp add: fun_eq_iff scomp_unfold fcomp_def)
haftmann@26358
   796
haftmann@37751
   797
lemma fcomp_scomp: "(f \<circ>> g) \<circ>\<rightarrow> h = f \<circ>> (g \<circ>\<rightarrow> h)"
huffman@44921
   798
  by (simp add: fun_eq_iff scomp_unfold)
haftmann@26358
   799
haftmann@52435
   800
code_printing
haftmann@52435
   801
  constant scomp \<rightharpoonup> (Eval) infixl 3 "#->"
haftmann@31202
   802
haftmann@37751
   803
no_notation fcomp (infixl "\<circ>>" 60)
haftmann@37751
   804
no_notation scomp (infixl "\<circ>\<rightarrow>" 60)
haftmann@26358
   805
wenzelm@60758
   806
text \<open>
wenzelm@69593
   807
  \<^term>\<open>map_prod\<close> --- action of the product functor upon functions.
wenzelm@60758
   808
\<close>
haftmann@21195
   809
wenzelm@63400
   810
definition map_prod :: "('a \<Rightarrow> 'c) \<Rightarrow> ('b \<Rightarrow> 'd) \<Rightarrow> 'a \<times> 'b \<Rightarrow> 'c \<times> 'd"
wenzelm@63400
   811
  where "map_prod f g = (\<lambda>(x, y). (f x, g y))"
haftmann@26358
   812
wenzelm@63400
   813
lemma map_prod_simp [simp, code]: "map_prod f g (a, b) = (f a, g b)"
blanchet@55932
   814
  by (simp add: map_prod_def)
haftmann@26358
   815
blanchet@55932
   816
functor map_prod: map_prod
huffman@44921
   817
  by (auto simp add: split_paired_all)
nipkow@37278
   818
wenzelm@63400
   819
lemma fst_map_prod [simp]: "fst (map_prod f g x) = f (fst x)"
haftmann@40607
   820
  by (cases x) simp_all
nipkow@37278
   821
wenzelm@63400
   822
lemma snd_map_prod [simp]: "snd (map_prod f g x) = g (snd x)"
haftmann@40607
   823
  by (cases x) simp_all
nipkow@37278
   824
wenzelm@63400
   825
lemma fst_comp_map_prod [simp]: "fst \<circ> map_prod f g = f \<circ> fst"
haftmann@40607
   826
  by (rule ext) simp_all
nipkow@37278
   827
wenzelm@63400
   828
lemma snd_comp_map_prod [simp]: "snd \<circ> map_prod f g = g \<circ> snd"
haftmann@40607
   829
  by (rule ext) simp_all
haftmann@26358
   830
wenzelm@63400
   831
lemma map_prod_compose: "map_prod (f1 \<circ> f2) (g1 \<circ> g2) = (map_prod f1 g1 \<circ> map_prod f2 g2)"
blanchet@55932
   832
  by (rule ext) (simp add: map_prod.compositionality comp_def)
haftmann@26358
   833
wenzelm@63400
   834
lemma map_prod_ident [simp]: "map_prod (\<lambda>x. x) (\<lambda>y. y) = (\<lambda>z. z)"
blanchet@55932
   835
  by (rule ext) (simp add: map_prod.identity)
haftmann@40607
   836
wenzelm@63400
   837
lemma map_prod_imageI [intro]: "(a, b) \<in> R \<Longrightarrow> (f a, g b) \<in> map_prod f g ` R"
haftmann@40607
   838
  by (rule image_eqI) simp_all
haftmann@21195
   839
haftmann@26358
   840
lemma prod_fun_imageE [elim!]:
blanchet@55932
   841
  assumes major: "c \<in> map_prod f g ` R"
haftmann@40607
   842
    and cases: "\<And>x y. c = (f x, g y) \<Longrightarrow> (x, y) \<in> R \<Longrightarrow> P"
haftmann@26358
   843
  shows P
haftmann@26358
   844
  apply (rule major [THEN imageE])
haftmann@37166
   845
  apply (case_tac x)
haftmann@26358
   846
  apply (rule cases)
wenzelm@63575
   847
   apply simp_all
haftmann@26358
   848
  done
haftmann@26358
   849
wenzelm@63400
   850
definition apfst :: "('a \<Rightarrow> 'c) \<Rightarrow> 'a \<times> 'b \<Rightarrow> 'c \<times> 'b"
wenzelm@63400
   851
  where "apfst f = map_prod f id"
haftmann@26358
   852
wenzelm@63400
   853
definition apsnd :: "('b \<Rightarrow> 'c) \<Rightarrow> 'a \<times> 'b \<Rightarrow> 'a \<times> 'c"
wenzelm@63400
   854
  where "apsnd f = map_prod id f"
haftmann@26358
   855
wenzelm@63575
   856
lemma apfst_conv [simp, code]: "apfst f (x, y) = (f x, y)"
haftmann@26358
   857
  by (simp add: apfst_def)
haftmann@26358
   858
wenzelm@63575
   859
lemma apsnd_conv [simp, code]: "apsnd f (x, y) = (x, f y)"
haftmann@26358
   860
  by (simp add: apsnd_def)
haftmann@21195
   861
wenzelm@63400
   862
lemma fst_apfst [simp]: "fst (apfst f x) = f (fst x)"
haftmann@33594
   863
  by (cases x) simp
haftmann@33594
   864
wenzelm@63400
   865
lemma fst_comp_apfst [simp]: "fst \<circ> apfst f = f \<circ> fst"
haftmann@51173
   866
  by (simp add: fun_eq_iff)
haftmann@51173
   867
wenzelm@63400
   868
lemma fst_apsnd [simp]: "fst (apsnd f x) = fst x"
haftmann@33594
   869
  by (cases x) simp
haftmann@33594
   870
wenzelm@63400
   871
lemma fst_comp_apsnd [simp]: "fst \<circ> apsnd f = fst"
haftmann@51173
   872
  by (simp add: fun_eq_iff)
haftmann@51173
   873
wenzelm@63400
   874
lemma snd_apfst [simp]: "snd (apfst f x) = snd x"
haftmann@33594
   875
  by (cases x) simp
haftmann@33594
   876
wenzelm@63400
   877
lemma snd_comp_apfst [simp]: "snd \<circ> apfst f = snd"
haftmann@51173
   878
  by (simp add: fun_eq_iff)
haftmann@51173
   879
wenzelm@63400
   880
lemma snd_apsnd [simp]: "snd (apsnd f x) = f (snd x)"
haftmann@33594
   881
  by (cases x) simp
haftmann@33594
   882
wenzelm@63400
   883
lemma snd_comp_apsnd [simp]: "snd \<circ> apsnd f = f \<circ> snd"
haftmann@51173
   884
  by (simp add: fun_eq_iff)
haftmann@51173
   885
wenzelm@63400
   886
lemma apfst_compose: "apfst f (apfst g x) = apfst (f \<circ> g) x"
haftmann@33594
   887
  by (cases x) simp
haftmann@33594
   888
wenzelm@63400
   889
lemma apsnd_compose: "apsnd f (apsnd g x) = apsnd (f \<circ> g) x"
haftmann@33594
   890
  by (cases x) simp
haftmann@33594
   891
wenzelm@63400
   892
lemma apfst_apsnd [simp]: "apfst f (apsnd g x) = (f (fst x), g (snd x))"
haftmann@33594
   893
  by (cases x) simp
haftmann@33594
   894
wenzelm@63400
   895
lemma apsnd_apfst [simp]: "apsnd f (apfst g x) = (g (fst x), f (snd x))"
haftmann@33594
   896
  by (cases x) simp
haftmann@33594
   897
wenzelm@63400
   898
lemma apfst_id [simp]: "apfst id = id"
nipkow@39302
   899
  by (simp add: fun_eq_iff)
haftmann@33594
   900
wenzelm@63400
   901
lemma apsnd_id [simp]: "apsnd id = id"
nipkow@39302
   902
  by (simp add: fun_eq_iff)
haftmann@33594
   903
wenzelm@63400
   904
lemma apfst_eq_conv [simp]: "apfst f x = apfst g x \<longleftrightarrow> f (fst x) = g (fst x)"
haftmann@33594
   905
  by (cases x) simp
haftmann@33594
   906
wenzelm@63400
   907
lemma apsnd_eq_conv [simp]: "apsnd f x = apsnd g x \<longleftrightarrow> f (snd x) = g (snd x)"
haftmann@33594
   908
  by (cases x) simp
haftmann@33594
   909
wenzelm@63400
   910
lemma apsnd_apfst_commute: "apsnd f (apfst g p) = apfst g (apsnd f p)"
hoelzl@33638
   911
  by simp
haftmann@21195
   912
haftmann@56626
   913
context
haftmann@56626
   914
begin
haftmann@56626
   915
wenzelm@60758
   916
local_setup \<open>Local_Theory.map_background_naming (Name_Space.mandatory_path "prod")\<close>
haftmann@56626
   917
haftmann@56545
   918
definition swap :: "'a \<times> 'b \<Rightarrow> 'b \<times> 'a"
wenzelm@63400
   919
  where "swap p = (snd p, fst p)"
haftmann@56545
   920
haftmann@56626
   921
end
haftmann@56626
   922
wenzelm@63400
   923
lemma swap_simp [simp]: "prod.swap (x, y) = (y, x)"
haftmann@56626
   924
  by (simp add: prod.swap_def)
haftmann@56545
   925
wenzelm@63400
   926
lemma swap_swap [simp]: "prod.swap (prod.swap p) = p"
haftmann@58195
   927
  by (cases p) simp
haftmann@58195
   928
wenzelm@63400
   929
lemma swap_comp_swap [simp]: "prod.swap \<circ> prod.swap = id"
haftmann@58195
   930
  by (simp add: fun_eq_iff)
haftmann@58195
   931
wenzelm@63400
   932
lemma pair_in_swap_image [simp]: "(y, x) \<in> prod.swap ` A \<longleftrightarrow> (x, y) \<in> A"
haftmann@56545
   933
  by (auto intro!: image_eqI)
haftmann@56545
   934
wenzelm@63400
   935
lemma inj_swap [simp]: "inj_on prod.swap A"
haftmann@56626
   936
  by (rule inj_onI) auto
haftmann@56626
   937
wenzelm@63400
   938
lemma swap_inj_on: "inj_on (\<lambda>(i, j). (j, i)) A"
haftmann@56626
   939
  by (rule inj_onI) auto
haftmann@56545
   940
wenzelm@63400
   941
lemma surj_swap [simp]: "surj prod.swap"
haftmann@58195
   942
  by (rule surjI [of _ prod.swap]) simp
haftmann@58195
   943
wenzelm@63400
   944
lemma bij_swap [simp]: "bij prod.swap"
haftmann@58195
   945
  by (simp add: bij_def)
haftmann@58195
   946
wenzelm@63400
   947
lemma case_swap [simp]: "(case prod.swap p of (y, x) \<Rightarrow> f x y) = (case p of (x, y) \<Rightarrow> f x y)"
haftmann@56545
   948
  by (cases p) simp
haftmann@56545
   949
Andreas@62139
   950
lemma fst_swap [simp]: "fst (prod.swap x) = snd x"
wenzelm@63400
   951
  by (cases x) simp
Andreas@62139
   952
Andreas@62139
   953
lemma snd_swap [simp]: "snd (prod.swap x) = fst x"
wenzelm@63400
   954
  by (cases x) simp
Andreas@62139
   955
wenzelm@63400
   956
text \<open>Disjoint union of a family of sets -- Sigma.\<close>
haftmann@26358
   957
wenzelm@63400
   958
definition Sigma :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> ('a \<times> 'b) set"
wenzelm@63400
   959
  where "Sigma A B \<equiv> \<Union>x\<in>A. \<Union>y\<in>B x. {Pair x y}"
haftmann@26358
   960
wenzelm@63400
   961
abbreviation Times :: "'a set \<Rightarrow> 'b set \<Rightarrow> ('a \<times> 'b) set"  (infixr "\<times>" 80)
wenzelm@63400
   962
  where "A \<times> B \<equiv> Sigma A (\<lambda>_. B)"
berghofe@15394
   963
nipkow@45662
   964
hide_const (open) Times
nipkow@45662
   965
lp15@68467
   966
bundle no_Set_Product_syntax begin
lp15@68467
   967
no_notation Product_Type.Times (infixr "\<times>" 80)
lp15@68467
   968
end
lp15@68467
   969
bundle Set_Product_syntax begin
lp15@68467
   970
notation Product_Type.Times (infixr "\<times>" 80)
lp15@68467
   971
end
lp15@68467
   972
haftmann@26358
   973
syntax
wenzelm@63400
   974
  "_Sigma" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b set \<Rightarrow> ('a \<times> 'b) set"  ("(3SIGMA _:_./ _)" [0, 0, 10] 10)
haftmann@26358
   975
translations
wenzelm@63400
   976
  "SIGMA x:A. B" \<rightleftharpoons> "CONST Sigma A (\<lambda>x. B)"
haftmann@26358
   977
wenzelm@63400
   978
lemma SigmaI [intro!]: "a \<in> A \<Longrightarrow> b \<in> B a \<Longrightarrow> (a, b) \<in> Sigma A B"
wenzelm@63400
   979
  unfolding Sigma_def by blast
wenzelm@63400
   980
wenzelm@63400
   981
lemma SigmaE [elim!]: "c \<in> Sigma A B \<Longrightarrow> (\<And>x y. x \<in> A \<Longrightarrow> y \<in> B x \<Longrightarrow> c = (x, y) \<Longrightarrow> P) \<Longrightarrow> P"
wenzelm@61799
   982
  \<comment> \<open>The general elimination rule.\<close>
wenzelm@63400
   983
  unfolding Sigma_def by blast
haftmann@20588
   984
wenzelm@60758
   985
text \<open>
wenzelm@69593
   986
  Elimination of \<^term>\<open>(a, b) \<in> A \<times> B\<close> -- introduces no
haftmann@26358
   987
  eigenvariables.
wenzelm@60758
   988
\<close>
haftmann@26358
   989
wenzelm@63400
   990
lemma SigmaD1: "(a, b) \<in> Sigma A B \<Longrightarrow> a \<in> A"
haftmann@26358
   991
  by blast
haftmann@26358
   992
wenzelm@63400
   993
lemma SigmaD2: "(a, b) \<in> Sigma A B \<Longrightarrow> b \<in> B a"
haftmann@26358
   994
  by blast
haftmann@26358
   995
wenzelm@63400
   996
lemma SigmaE2: "(a, b) \<in> Sigma A B \<Longrightarrow> (a \<in> A \<Longrightarrow> b \<in> B a \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@26358
   997
  by blast
haftmann@20588
   998
wenzelm@63400
   999
lemma Sigma_cong: "A = B \<Longrightarrow> (\<And>x. x \<in> B \<Longrightarrow> C x = D x) \<Longrightarrow> (SIGMA x:A. C x) = (SIGMA x:B. D x)"
haftmann@26358
  1000
  by auto
haftmann@26358
  1001
wenzelm@63400
  1002
lemma Sigma_mono: "A \<subseteq> C \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> B x \<subseteq> D x) \<Longrightarrow> Sigma A B \<subseteq> Sigma C D"
haftmann@26358
  1003
  by blast
haftmann@26358
  1004
haftmann@26358
  1005
lemma Sigma_empty1 [simp]: "Sigma {} B = {}"
haftmann@26358
  1006
  by blast
haftmann@26358
  1007
wenzelm@61943
  1008
lemma Sigma_empty2 [simp]: "A \<times> {} = {}"
haftmann@26358
  1009
  by blast
haftmann@26358
  1010
wenzelm@61943
  1011
lemma UNIV_Times_UNIV [simp]: "UNIV \<times> UNIV = UNIV"
haftmann@26358
  1012
  by auto
haftmann@21908
  1013
wenzelm@61943
  1014
lemma Compl_Times_UNIV1 [simp]: "- (UNIV \<times> A) = UNIV \<times> (-A)"
haftmann@26358
  1015
  by auto
haftmann@26358
  1016
wenzelm@61943
  1017
lemma Compl_Times_UNIV2 [simp]: "- (A \<times> UNIV) = (-A) \<times> UNIV"
haftmann@26358
  1018
  by auto
haftmann@26358
  1019
wenzelm@63400
  1020
lemma mem_Sigma_iff [iff]: "(a, b) \<in> Sigma A B \<longleftrightarrow> a \<in> A \<and> b \<in> B a"
haftmann@26358
  1021
  by blast
haftmann@26358
  1022
hoelzl@62101
  1023
lemma mem_Times_iff: "x \<in> A \<times> B \<longleftrightarrow> fst x \<in> A \<and> snd x \<in> B"
hoelzl@62101
  1024
  by (induct x) simp
hoelzl@62101
  1025
hoelzl@59000
  1026
lemma Sigma_empty_iff: "(SIGMA i:I. X i) = {} \<longleftrightarrow> (\<forall>i\<in>I. X i = {})"
hoelzl@59000
  1027
  by auto
hoelzl@59000
  1028
wenzelm@63400
  1029
lemma Times_subset_cancel2: "x \<in> C \<Longrightarrow> A \<times> C \<subseteq> B \<times> C \<longleftrightarrow> A \<subseteq> B"
haftmann@26358
  1030
  by blast
haftmann@26358
  1031
wenzelm@63400
  1032
lemma Times_eq_cancel2: "x \<in> C \<Longrightarrow> A \<times> C = B \<times> C \<longleftrightarrow> A = B"
wenzelm@63400
  1033
  by (blast elim: equalityE)
wenzelm@63400
  1034
wenzelm@63400
  1035
lemma Collect_case_prod_Sigma: "{(x, y). P x \<and> Q x y} = (SIGMA x:Collect P. Collect (Q x))"
wenzelm@63400
  1036
  by blast
wenzelm@63400
  1037
wenzelm@63400
  1038
lemma Collect_case_prod [simp]: "{(a, b). P a \<and> Q b} = Collect P \<times> Collect Q "
haftmann@61424
  1039
  by (fact Collect_case_prod_Sigma)
haftmann@26358
  1040
wenzelm@63400
  1041
lemma Collect_case_prodD: "x \<in> Collect (case_prod A) \<Longrightarrow> A (fst x) (snd x)"
haftmann@61422
  1042
  by auto
haftmann@61422
  1043
wenzelm@63400
  1044
lemma Collect_case_prod_mono: "A \<le> B \<Longrightarrow> Collect (case_prod A) \<subseteq> Collect (case_prod B)"
haftmann@61422
  1045
  by auto (auto elim!: le_funE)
haftmann@61422
  1046
wenzelm@63575
  1047
lemma Collect_split_mono_strong:
haftmann@61422
  1048
  "X = fst ` A \<Longrightarrow> Y = snd ` A \<Longrightarrow> \<forall>a\<in>X. \<forall>b \<in> Y. P a b \<longrightarrow> Q a b
haftmann@61424
  1049
    \<Longrightarrow> A \<subseteq> Collect (case_prod P) \<Longrightarrow> A \<subseteq> Collect (case_prod Q)"
haftmann@61422
  1050
  by fastforce
wenzelm@63575
  1051
haftmann@69275
  1052
lemma UN_Times_distrib: "(\<Union>(a, b)\<in>A \<times> B. E a \<times> F b) = \<Union>(E ` A) \<times> \<Union>(F ` B)"
wenzelm@61799
  1053
  \<comment> \<open>Suggested by Pierre Chartier\<close>
haftmann@26358
  1054
  by blast
haftmann@26358
  1055
wenzelm@63400
  1056
lemma split_paired_Ball_Sigma [simp, no_atp]: "(\<forall>z\<in>Sigma A B. P z) \<longleftrightarrow> (\<forall>x\<in>A. \<forall>y\<in>B x. P (x, y))"
haftmann@26358
  1057
  by blast
haftmann@26358
  1058
wenzelm@63400
  1059
lemma split_paired_Bex_Sigma [simp, no_atp]: "(\<exists>z\<in>Sigma A B. P z) \<longleftrightarrow> (\<exists>x\<in>A. \<exists>y\<in>B x. P (x, y))"
haftmann@61127
  1060
  by blast
haftmann@61127
  1061
wenzelm@63400
  1062
lemma Sigma_Un_distrib1: "Sigma (I \<union> J) C = Sigma I C \<union> Sigma J C"
haftmann@26358
  1063
  by blast
haftmann@21908
  1064
wenzelm@63400
  1065
lemma Sigma_Un_distrib2: "(SIGMA i:I. A i \<union> B i) = Sigma I A \<union> Sigma I B"
haftmann@26358
  1066
  by blast
haftmann@26358
  1067
wenzelm@63400
  1068
lemma Sigma_Int_distrib1: "Sigma (I \<inter> J) C = Sigma I C \<inter> Sigma J C"
haftmann@26358
  1069
  by blast
haftmann@26358
  1070
wenzelm@63400
  1071
lemma Sigma_Int_distrib2: "(SIGMA i:I. A i \<inter> B i) = Sigma I A \<inter> Sigma I B"
haftmann@26358
  1072
  by blast
haftmann@26358
  1073
wenzelm@63400
  1074
lemma Sigma_Diff_distrib1: "Sigma (I - J) C = Sigma I C - Sigma J C"
haftmann@26358
  1075
  by blast
haftmann@26358
  1076
wenzelm@63400
  1077
lemma Sigma_Diff_distrib2: "(SIGMA i:I. A i - B i) = Sigma I A - Sigma I B"
haftmann@26358
  1078
  by blast
haftmann@21908
  1079
wenzelm@63400
  1080
lemma Sigma_Union: "Sigma (\<Union>X) B = (\<Union>A\<in>X. Sigma A B)"
haftmann@26358
  1081
  by blast
haftmann@26358
  1082
Andreas@61630
  1083
lemma Pair_vimage_Sigma: "Pair x -` Sigma A f = (if x \<in> A then f x else {})"
Andreas@61630
  1084
  by auto
Andreas@61630
  1085
wenzelm@60758
  1086
text \<open>
haftmann@26358
  1087
  Non-dependent versions are needed to avoid the need for higher-order
haftmann@26358
  1088
  matching, especially when the rules are re-oriented.
wenzelm@60758
  1089
\<close>
haftmann@21908
  1090
wenzelm@63400
  1091
lemma Times_Un_distrib1: "(A \<union> B) \<times> C = A \<times> C \<union> B \<times> C "
haftmann@56545
  1092
  by (fact Sigma_Un_distrib1)
haftmann@26358
  1093
wenzelm@63400
  1094
lemma Times_Int_distrib1: "(A \<inter> B) \<times> C = A \<times> C \<inter> B \<times> C "
haftmann@56545
  1095
  by (fact Sigma_Int_distrib1)
haftmann@26358
  1096
wenzelm@63400
  1097
lemma Times_Diff_distrib1: "(A - B) \<times> C = A \<times> C - B \<times> C "
haftmann@56545
  1098
  by (fact Sigma_Diff_distrib1)
haftmann@26358
  1099
wenzelm@63400
  1100
lemma Times_empty [simp]: "A \<times> B = {} \<longleftrightarrow> A = {} \<or> B = {}"
hoelzl@36622
  1101
  by auto
hoelzl@36622
  1102
lp15@69144
  1103
lemma times_subset_iff: "A \<times> C \<subseteq> B \<times> D \<longleftrightarrow> A={} \<or> C={} \<or> A \<subseteq> B \<and> C \<subseteq> D"
lp15@69144
  1104
  by blast
lp15@69144
  1105
wenzelm@63400
  1106
lemma times_eq_iff: "A \<times> B = C \<times> D \<longleftrightarrow> A = C \<and> B = D \<or> (A = {} \<or> B = {}) \<and> (C = {} \<or> D = {})"
hoelzl@50104
  1107
  by auto
hoelzl@50104
  1108
wenzelm@63400
  1109
lemma fst_image_times [simp]: "fst ` (A \<times> B) = (if B = {} then {} else A)"
huffman@44921
  1110
  by force
hoelzl@36622
  1111
wenzelm@63400
  1112
lemma snd_image_times [simp]: "snd ` (A \<times> B) = (if A = {} then {} else B)"
huffman@44921
  1113
  by force
hoelzl@36622
  1114
wenzelm@63400
  1115
lemma fst_image_Sigma: "fst ` (Sigma A B) = {x \<in> A. B(x) \<noteq> {}}"
lp15@62379
  1116
  by force
lp15@62379
  1117
wenzelm@63400
  1118
lemma snd_image_Sigma: "snd ` (Sigma A B) = (\<Union> x \<in> A. B x)"
lp15@62379
  1119
  by force
lp15@62379
  1120
wenzelm@63400
  1121
lemma vimage_fst: "fst -` A = A \<times> UNIV"
haftmann@56545
  1122
  by auto
haftmann@56545
  1123
wenzelm@63400
  1124
lemma vimage_snd: "snd -` A = UNIV \<times> A"
haftmann@56545
  1125
  by auto
haftmann@56545
  1126
wenzelm@63400
  1127
lemma insert_times_insert [simp]:
wenzelm@63400
  1128
  "insert a A \<times> insert b B = insert (a,b) (A \<times> insert b B \<union> insert a A \<times> B)"
haftmann@61127
  1129
  by blast
haftmann@26358
  1130
wenzelm@63400
  1131
lemma vimage_Times: "f -` (A \<times> B) = (fst \<circ> f) -` A \<inter> (snd \<circ> f) -` B"
haftmann@61127
  1132
proof (rule set_eqI)
wenzelm@63400
  1133
  show "x \<in> f -` (A \<times> B) \<longleftrightarrow> x \<in> (fst \<circ> f) -` A \<inter> (snd \<circ> f) -` B" for x
haftmann@61127
  1134
    by (cases "f x") (auto split: prod.split)
haftmann@61127
  1135
qed
paulson@33271
  1136
wenzelm@63400
  1137
lemma times_Int_times: "A \<times> B \<inter> C \<times> D = (A \<inter> C) \<times> (B \<inter> D)"
hoelzl@50104
  1138
  by auto
hoelzl@50104
  1139
wenzelm@63400
  1140
lemma product_swap: "prod.swap ` (A \<times> B) = B \<times> A"
haftmann@56626
  1141
  by (auto simp add: set_eq_iff)
haftmann@35822
  1142
wenzelm@63400
  1143
lemma swap_product: "(\<lambda>(i, j). (j, i)) ` (A \<times> B) = B \<times> A"
haftmann@56626
  1144
  by (auto simp add: set_eq_iff)
haftmann@35822
  1145
wenzelm@63400
  1146
lemma image_split_eq_Sigma: "(\<lambda>x. (f x, g x)) ` A = Sigma (f ` A) (\<lambda>x. g ` (f -` {x} \<inter> A))"
haftmann@46128
  1147
proof (safe intro!: imageI)
wenzelm@63400
  1148
  fix a b
wenzelm@63400
  1149
  assume *: "a \<in> A" "b \<in> A" and eq: "f a = f b"
hoelzl@36622
  1150
  show "(f b, g a) \<in> (\<lambda>x. (f x, g x)) ` A"
hoelzl@36622
  1151
    using * eq[symmetric] by auto
hoelzl@36622
  1152
qed simp_all
haftmann@35822
  1153
lp15@63007
  1154
lemma subset_fst_snd: "A \<subseteq> (fst ` A \<times> snd ` A)"
lp15@63007
  1155
  by force
lp15@63007
  1156
Andreas@60057
  1157
lemma inj_on_apfst [simp]: "inj_on (apfst f) (A \<times> UNIV) \<longleftrightarrow> inj_on f A"
wenzelm@63400
  1158
  by (auto simp add: inj_on_def)
Andreas@60057
  1159
Andreas@60057
  1160
lemma inj_apfst [simp]: "inj (apfst f) \<longleftrightarrow> inj f"
wenzelm@63400
  1161
  using inj_on_apfst[of f UNIV] by simp
Andreas@60057
  1162
Andreas@60057
  1163
lemma inj_on_apsnd [simp]: "inj_on (apsnd f) (UNIV \<times> A) \<longleftrightarrow> inj_on f A"
wenzelm@63400
  1164
  by (auto simp add: inj_on_def)
Andreas@60057
  1165
Andreas@60057
  1166
lemma inj_apsnd [simp]: "inj (apsnd f) \<longleftrightarrow> inj f"
wenzelm@63400
  1167
  using inj_on_apsnd[of f UNIV] by simp
Andreas@60057
  1168
haftmann@61127
  1169
context
haftmann@61127
  1170
begin
haftmann@61127
  1171
wenzelm@63575
  1172
qualified definition product :: "'a set \<Rightarrow> 'b set \<Rightarrow> ('a \<times> 'b) set"
wenzelm@63575
  1173
  where [code_abbrev]: "product A B = A \<times> B"
haftmann@46128
  1174
wenzelm@63400
  1175
lemma member_product: "x \<in> Product_Type.product A B \<longleftrightarrow> x \<in> A \<times> B"
wenzelm@63400
  1176
  by (simp add: product_def)
haftmann@46128
  1177
haftmann@61127
  1178
end
wenzelm@63575
  1179
wenzelm@69593
  1180
text \<open>The following \<^const>\<open>map_prod\<close> lemmas are due to Joachim Breitner:\<close>
haftmann@40607
  1181
blanchet@55932
  1182
lemma map_prod_inj_on:
wenzelm@63575
  1183
  assumes "inj_on f A"
wenzelm@63575
  1184
    and "inj_on g B"
blanchet@55932
  1185
  shows "inj_on (map_prod f g) (A \<times> B)"
haftmann@40607
  1186
proof (rule inj_onI)
wenzelm@63400
  1187
  fix x :: "'a \<times> 'c"
wenzelm@63400
  1188
  fix y :: "'a \<times> 'c"
wenzelm@63400
  1189
  assume "x \<in> A \<times> B"
wenzelm@63400
  1190
  then have "fst x \<in> A" and "snd x \<in> B" by auto
wenzelm@63400
  1191
  assume "y \<in> A \<times> B"
wenzelm@63400
  1192
  then have "fst y \<in> A" and "snd y \<in> B" by auto
blanchet@55932
  1193
  assume "map_prod f g x = map_prod f g y"
wenzelm@63400
  1194
  then have "fst (map_prod f g x) = fst (map_prod f g y)" by auto
wenzelm@63400
  1195
  then have "f (fst x) = f (fst y)" by (cases x, cases y) auto
wenzelm@63400
  1196
  with \<open>inj_on f A\<close> and \<open>fst x \<in> A\<close> and \<open>fst y \<in> A\<close> have "fst x = fst y"
wenzelm@63400
  1197
    by (auto dest: inj_onD)
wenzelm@60758
  1198
  moreover from \<open>map_prod f g x = map_prod f g y\<close>
wenzelm@63400
  1199
  have "snd (map_prod f g x) = snd (map_prod f g y)" by auto
wenzelm@63400
  1200
  then have "g (snd x) = g (snd y)" by (cases x, cases y) auto
wenzelm@63400
  1201
  with \<open>inj_on g B\<close> and \<open>snd x \<in> B\<close> and \<open>snd y \<in> B\<close> have "snd x = snd y"
wenzelm@63400
  1202
    by (auto dest: inj_onD)
wenzelm@63400
  1203
  ultimately show "x = y" by (rule prod_eqI)
haftmann@40607
  1204
qed
haftmann@40607
  1205
blanchet@55932
  1206
lemma map_prod_surj:
wenzelm@63400
  1207
  fixes f :: "'a \<Rightarrow> 'b"
wenzelm@63400
  1208
    and g :: "'c \<Rightarrow> 'd"
haftmann@40607
  1209
  assumes "surj f" and "surj g"
blanchet@55932
  1210
  shows "surj (map_prod f g)"
wenzelm@63400
  1211
  unfolding surj_def
haftmann@40607
  1212
proof
haftmann@40607
  1213
  fix y :: "'b \<times> 'd"
wenzelm@63400
  1214
  from \<open>surj f\<close> obtain a where "fst y = f a"
wenzelm@63400
  1215
    by (auto elim: surjE)
haftmann@40607
  1216
  moreover
wenzelm@63400
  1217
  from \<open>surj g\<close> obtain b where "snd y = g b"
wenzelm@63400
  1218
    by (auto elim: surjE)
wenzelm@63400
  1219
  ultimately have "(fst y, snd y) = map_prod f g (a,b)"
wenzelm@63400
  1220
    by auto
wenzelm@63400
  1221
  then show "\<exists>x. y = map_prod f g x"
wenzelm@63400
  1222
    by auto
haftmann@40607
  1223
qed
haftmann@40607
  1224
blanchet@55932
  1225
lemma map_prod_surj_on:
haftmann@40607
  1226
  assumes "f ` A = A'" and "g ` B = B'"
blanchet@55932
  1227
  shows "map_prod f g ` (A \<times> B) = A' \<times> B'"
wenzelm@63400
  1228
  unfolding image_def
wenzelm@63400
  1229
proof (rule set_eqI, rule iffI)
haftmann@40607
  1230
  fix x :: "'a \<times> 'c"
wenzelm@61076
  1231
  assume "x \<in> {y::'a \<times> 'c. \<exists>x::'b \<times> 'd\<in>A \<times> B. y = map_prod f g x}"
wenzelm@63400
  1232
  then obtain y where "y \<in> A \<times> B" and "x = map_prod f g y"
wenzelm@63400
  1233
    by blast
wenzelm@63400
  1234
  from \<open>image f A = A'\<close> and \<open>y \<in> A \<times> B\<close> have "f (fst y) \<in> A'"
wenzelm@63400
  1235
    by auto
wenzelm@63400
  1236
  moreover from \<open>image g B = B'\<close> and \<open>y \<in> A \<times> B\<close> have "g (snd y) \<in> B'"
wenzelm@63400
  1237
    by auto
wenzelm@63400
  1238
  ultimately have "(f (fst y), g (snd y)) \<in> (A' \<times> B')"
wenzelm@63400
  1239
    by auto
wenzelm@63400
  1240
  with \<open>x = map_prod f g y\<close> show "x \<in> A' \<times> B'"
wenzelm@63400
  1241
    by (cases y) auto
haftmann@40607
  1242
next
haftmann@40607
  1243
  fix x :: "'a \<times> 'c"
wenzelm@63400
  1244
  assume "x \<in> A' \<times> B'"
wenzelm@63400
  1245
  then have "fst x \<in> A'" and "snd x \<in> B'"
wenzelm@63400
  1246
    by auto
wenzelm@63400
  1247
  from \<open>image f A = A'\<close> and \<open>fst x \<in> A'\<close> have "fst x \<in> image f A"
wenzelm@63400
  1248
    by auto
wenzelm@63400
  1249
  then obtain a where "a \<in> A" and "fst x = f a"
wenzelm@63400
  1250
    by (rule imageE)
wenzelm@63400
  1251
  moreover from \<open>image g B = B'\<close> and \<open>snd x \<in> B'\<close> obtain b where "b \<in> B" and "snd x = g b"
wenzelm@63400
  1252
    by auto
wenzelm@63400
  1253
  ultimately have "(fst x, snd x) = map_prod f g (a, b)"
wenzelm@63400
  1254
    by auto
wenzelm@63400
  1255
  moreover from \<open>a \<in> A\<close> and  \<open>b \<in> B\<close> have "(a , b) \<in> A \<times> B"
wenzelm@63400
  1256
    by auto
wenzelm@63400
  1257
  ultimately have "\<exists>y \<in> A \<times> B. x = map_prod f g y"
wenzelm@63400
  1258
    by auto
wenzelm@63400
  1259
  then show "x \<in> {x. \<exists>y \<in> A \<times> B. x = map_prod f g y}"
wenzelm@63400
  1260
    by auto
haftmann@40607
  1261
qed
haftmann@40607
  1262
haftmann@21908
  1263
wenzelm@60758
  1264
subsection \<open>Simproc for rewriting a set comprehension into a pointfree expression\<close>
bulwahn@49764
  1265
wenzelm@69605
  1266
ML_file \<open>Tools/set_comprehension_pointfree.ML\<close>
bulwahn@49764
  1267
wenzelm@60758
  1268
setup \<open>
wenzelm@51717
  1269
  Code_Preproc.map_pre (fn ctxt => ctxt addsimprocs
wenzelm@69593
  1270
    [Simplifier.make_simproc \<^context> "set comprehension"
wenzelm@69593
  1271
      {lhss = [\<^term>\<open>Collect P\<close>],
wenzelm@62913
  1272
       proc = K Set_Comprehension_Pointfree.code_simproc}])
wenzelm@60758
  1273
\<close>
bulwahn@49764
  1274
bulwahn@49764
  1275
wenzelm@60758
  1276
subsection \<open>Inductively defined sets\<close>
berghofe@15394
  1277
wenzelm@56512
  1278
(* simplify {(x1, ..., xn). (x1, ..., xn) : S} to S *)
wenzelm@60758
  1279
simproc_setup Collect_mem ("Collect t") = \<open>
wenzelm@56512
  1280
  fn _ => fn ctxt => fn ct =>
wenzelm@59582
  1281
    (case Thm.term_of ct of
wenzelm@69593
  1282
      S as Const (\<^const_name>\<open>Collect\<close>, Type (\<^type_name>\<open>fun\<close>, [_, T])) $ t =>
haftmann@61424
  1283
        let val (u, _, ps) = HOLogic.strip_ptupleabs t in
wenzelm@56512
  1284
          (case u of
wenzelm@69593
  1285
            (c as Const (\<^const_name>\<open>Set.member\<close>, _)) $ q $ S' =>
wenzelm@56512
  1286
              (case try (HOLogic.strip_ptuple ps) q of
wenzelm@56512
  1287
                NONE => NONE
wenzelm@56512
  1288
              | SOME ts =>
wenzelm@56512
  1289
                  if not (Term.is_open S') andalso
wenzelm@56512
  1290
                    ts = map Bound (length ps downto 0)
wenzelm@56512
  1291
                  then
wenzelm@56512
  1292
                    let val simp =
wenzelm@56512
  1293
                      full_simp_tac (put_simpset HOL_basic_ss ctxt
haftmann@61424
  1294
                        addsimps [@{thm split_paired_all}, @{thm case_prod_conv}]) 1
wenzelm@56512
  1295
                    in
wenzelm@56512
  1296
                      SOME (Goal.prove ctxt [] []
wenzelm@69593
  1297
                        (Const (\<^const_name>\<open>Pure.eq\<close>, T --> T --> propT) $ S $ S')
wenzelm@56512
  1298
                        (K (EVERY
wenzelm@59498
  1299
                          [resolve_tac ctxt [eq_reflection] 1,
wenzelm@59498
  1300
                           resolve_tac ctxt @{thms subset_antisym} 1,
wenzelm@63399
  1301
                           resolve_tac ctxt @{thms subsetI} 1,
wenzelm@63399
  1302
                           dresolve_tac ctxt @{thms CollectD} 1, simp,
wenzelm@63399
  1303
                           resolve_tac ctxt @{thms subsetI} 1,
wenzelm@63399
  1304
                           resolve_tac ctxt @{thms CollectI} 1, simp])))
wenzelm@56512
  1305
                    end
wenzelm@56512
  1306
                  else NONE)
wenzelm@56512
  1307
          | _ => NONE)
wenzelm@56512
  1308
        end
wenzelm@56512
  1309
    | _ => NONE)
wenzelm@60758
  1310
\<close>
blanchet@58389
  1311
wenzelm@69605
  1312
ML_file \<open>Tools/inductive_set.ML\<close>
haftmann@24699
  1313
haftmann@37166
  1314
wenzelm@60758
  1315
subsection \<open>Legacy theorem bindings and duplicates\<close>
haftmann@37166
  1316
blanchet@55393
  1317
lemmas fst_conv = prod.sel(1)
blanchet@55393
  1318
lemmas snd_conv = prod.sel(2)
haftmann@61032
  1319
lemmas split_def = case_prod_unfold
haftmann@61424
  1320
lemmas split_beta' = case_prod_beta'
haftmann@61424
  1321
lemmas split_beta = prod.case_eq_if
haftmann@61424
  1322
lemmas split_conv = case_prod_conv
haftmann@61424
  1323
lemmas split = case_prod_conv
huffman@44066
  1324
huffman@45204
  1325
hide_const (open) prod
huffman@45204
  1326
nipkow@10213
  1327
end