author  wenzelm 
Sat, 25 May 2013 15:37:53 +0200  
changeset 52143  36ffe23b25f8 
parent 51717  9e7d1c139569 
child 52435  6646bb548c6b 
permissions  rwrr 
10213  1 
(* Title: HOL/Product_Type.thy 
2 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory 

3 
Copyright 1992 University of Cambridge 

11777  4 
*) 
10213  5 

11838  6 
header {* Cartesian products *} 
10213  7 

15131  8 
theory Product_Type 
33959
2afc55e8ed27
bootstrap datatype_rep_proofs in Datatype.thy (avoids unchecked dynamic name references)
haftmann
parents:
33638
diff
changeset

9 
imports Typedef Inductive Fun 
46950
d0181abdbdac
declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents:
46630
diff
changeset

10 
keywords "inductive_set" "coinductive_set" :: thy_decl 
15131  11 
begin 
11838  12 

24699
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

13 
subsection {* @{typ bool} is a datatype *} 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

14 

27104
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26975
diff
changeset

15 
rep_datatype True False by (auto intro: bool_induct) 
24699
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

16 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

17 
declare case_split [cases type: bool] 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

18 
 "prefer plain propositional version" 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

19 

28346
b8390cd56b8f
discontinued special treatment of op = vs. eq_class.eq
haftmann
parents:
28262
diff
changeset

20 
lemma 
38857
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38715
diff
changeset

21 
shows [code]: "HOL.equal False P \<longleftrightarrow> \<not> P" 
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38715
diff
changeset

22 
and [code]: "HOL.equal True P \<longleftrightarrow> P" 
46630  23 
and [code]: "HOL.equal P False \<longleftrightarrow> \<not> P" 
38857
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38715
diff
changeset

24 
and [code]: "HOL.equal P True \<longleftrightarrow> P" 
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38715
diff
changeset

25 
and [code nbe]: "HOL.equal P P \<longleftrightarrow> True" 
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38715
diff
changeset

26 
by (simp_all add: equal) 
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25511
diff
changeset

27 

43654
3f1a44c2d645
install case certificate for If after code_datatype declaration for bool
haftmann
parents:
43595
diff
changeset

28 
lemma If_case_cert: 
3f1a44c2d645
install case certificate for If after code_datatype declaration for bool
haftmann
parents:
43595
diff
changeset

29 
assumes "CASE \<equiv> (\<lambda>b. If b f g)" 
3f1a44c2d645
install case certificate for If after code_datatype declaration for bool
haftmann
parents:
43595
diff
changeset

30 
shows "(CASE True \<equiv> f) &&& (CASE False \<equiv> g)" 
3f1a44c2d645
install case certificate for If after code_datatype declaration for bool
haftmann
parents:
43595
diff
changeset

31 
using assms by simp_all 
3f1a44c2d645
install case certificate for If after code_datatype declaration for bool
haftmann
parents:
43595
diff
changeset

32 

3f1a44c2d645
install case certificate for If after code_datatype declaration for bool
haftmann
parents:
43595
diff
changeset

33 
setup {* 
3f1a44c2d645
install case certificate for If after code_datatype declaration for bool
haftmann
parents:
43595
diff
changeset

34 
Code.add_case @{thm If_case_cert} 
3f1a44c2d645
install case certificate for If after code_datatype declaration for bool
haftmann
parents:
43595
diff
changeset

35 
*} 
3f1a44c2d645
install case certificate for If after code_datatype declaration for bool
haftmann
parents:
43595
diff
changeset

36 

38857
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38715
diff
changeset

37 
code_const "HOL.equal \<Colon> bool \<Rightarrow> bool \<Rightarrow> bool" 
39272  38 
(Haskell infix 4 "==") 
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25511
diff
changeset

39 

38857
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38715
diff
changeset

40 
code_instance bool :: equal 
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25511
diff
changeset

41 
(Haskell ) 
24699
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

42 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

43 

37166  44 
subsection {* The @{text unit} type *} 
11838  45 

49834  46 
typedef unit = "{True}" 
45694
4a8743618257
prefer typedef without extra definition and alternative name;
wenzelm
parents:
45662
diff
changeset

47 
by auto 
11838  48 

45694
4a8743618257
prefer typedef without extra definition and alternative name;
wenzelm
parents:
45662
diff
changeset

49 
definition Unity :: unit ("'(')") 
4a8743618257
prefer typedef without extra definition and alternative name;
wenzelm
parents:
45662
diff
changeset

50 
where "() = Abs_unit True" 
11838  51 

35828
46cfc4b8112e
now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents:
35427
diff
changeset

52 
lemma unit_eq [no_atp]: "u = ()" 
40590  53 
by (induct u) (simp add: Unity_def) 
11838  54 

55 
text {* 

56 
Simplification procedure for @{thm [source] unit_eq}. Cannot use 

57 
this rule directly  it loops! 

58 
*} 

59 

43594  60 
simproc_setup unit_eq ("x::unit") = {* 
61 
fn _ => fn _ => fn ct => 

62 
if HOLogic.is_unit (term_of ct) then NONE 

63 
else SOME (mk_meta_eq @{thm unit_eq}) 

11838  64 
*} 
65 

27104
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26975
diff
changeset

66 
rep_datatype "()" by simp 
24699
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

67 

11838  68 
lemma unit_all_eq1: "(!!x::unit. PROP P x) == PROP P ()" 
69 
by simp 

70 

71 
lemma unit_all_eq2: "(!!x::unit. PROP P) == PROP P" 

72 
by (rule triv_forall_equality) 

73 

74 
text {* 

43594  75 
This rewrite counters the effect of simproc @{text unit_eq} on @{term 
11838  76 
[source] "%u::unit. f u"}, replacing it by @{term [source] 
77 
f} rather than by @{term [source] "%u. f ()"}. 

78 
*} 

79 

43866
8a50dc70cbff
moving UNIV = ... equations to their proper theories
haftmann
parents:
43654
diff
changeset

80 
lemma unit_abs_eta_conv [simp, no_atp]: "(%u::unit. f ()) = f" 
11838  81 
by (rule ext) simp 
10213  82 

43866
8a50dc70cbff
moving UNIV = ... equations to their proper theories
haftmann
parents:
43654
diff
changeset

83 
lemma UNIV_unit [no_atp]: 
8a50dc70cbff
moving UNIV = ... equations to their proper theories
haftmann
parents:
43654
diff
changeset

84 
"UNIV = {()}" by auto 
8a50dc70cbff
moving UNIV = ... equations to their proper theories
haftmann
parents:
43654
diff
changeset

85 

30924  86 
instantiation unit :: default 
87 
begin 

88 

89 
definition "default = ()" 

90 

91 
instance .. 

92 

93 
end 

10213  94 

28562  95 
lemma [code]: 
38857
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38715
diff
changeset

96 
"HOL.equal (u\<Colon>unit) v \<longleftrightarrow> True" unfolding equal unit_eq [of u] unit_eq [of v] by rule+ 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

97 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

98 
code_type unit 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

99 
(SML "unit") 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

100 
(OCaml "unit") 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

101 
(Haskell "()") 
34886  102 
(Scala "Unit") 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

103 

37166  104 
code_const Unity 
105 
(SML "()") 

106 
(OCaml "()") 

107 
(Haskell "()") 

108 
(Scala "()") 

109 

38857
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38715
diff
changeset

110 
code_instance unit :: equal 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

111 
(Haskell ) 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

112 

38857
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38715
diff
changeset

113 
code_const "HOL.equal \<Colon> unit \<Rightarrow> unit \<Rightarrow> bool" 
39272  114 
(Haskell infix 4 "==") 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

115 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

116 
code_reserved SML 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

117 
unit 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

118 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

119 
code_reserved OCaml 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

120 
unit 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

121 

34886  122 
code_reserved Scala 
123 
Unit 

124 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

125 

37166  126 
subsection {* The product type *} 
10213  127 

37166  128 
subsubsection {* Type definition *} 
129 

130 
definition Pair_Rep :: "'a \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool" where 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

131 
"Pair_Rep a b = (\<lambda>x y. x = a \<and> y = b)" 
10213  132 

45696  133 
definition "prod = {f. \<exists>a b. f = Pair_Rep (a\<Colon>'a) (b\<Colon>'b)}" 
134 

49834  135 
typedef ('a, 'b) prod (infixr "*" 20) = "prod :: ('a \<Rightarrow> 'b \<Rightarrow> bool) set" 
45696  136 
unfolding prod_def by auto 
10213  137 

35427  138 
type_notation (xsymbols) 
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset

139 
"prod" ("(_ \<times>/ _)" [21, 20] 20) 
35427  140 
type_notation (HTML output) 
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset

141 
"prod" ("(_ \<times>/ _)" [21, 20] 20) 
10213  142 

37389
09467cdfa198
qualified type "*"; qualified constants Pair, fst, snd, split
haftmann
parents:
37387
diff
changeset

143 
definition Pair :: "'a \<Rightarrow> 'b \<Rightarrow> 'a \<times> 'b" where 
09467cdfa198
qualified type "*"; qualified constants Pair, fst, snd, split
haftmann
parents:
37387
diff
changeset

144 
"Pair a b = Abs_prod (Pair_Rep a b)" 
37166  145 

37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset

146 
rep_datatype Pair proof  
37166  147 
fix P :: "'a \<times> 'b \<Rightarrow> bool" and p 
148 
assume "\<And>a b. P (Pair a b)" 

37389
09467cdfa198
qualified type "*"; qualified constants Pair, fst, snd, split
haftmann
parents:
37387
diff
changeset

149 
then show "P p" by (cases p) (auto simp add: prod_def Pair_def Pair_Rep_def) 
37166  150 
next 
151 
fix a c :: 'a and b d :: 'b 

152 
have "Pair_Rep a b = Pair_Rep c d \<longleftrightarrow> a = c \<and> b = d" 

39302
d7728f65b353
renamed lemmas: ext_iff > fun_eq_iff, set_ext_iff > set_eq_iff, set_ext > set_eqI
nipkow
parents:
39272
diff
changeset

153 
by (auto simp add: Pair_Rep_def fun_eq_iff) 
37389
09467cdfa198
qualified type "*"; qualified constants Pair, fst, snd, split
haftmann
parents:
37387
diff
changeset

154 
moreover have "Pair_Rep a b \<in> prod" and "Pair_Rep c d \<in> prod" 
09467cdfa198
qualified type "*"; qualified constants Pair, fst, snd, split
haftmann
parents:
37387
diff
changeset

155 
by (auto simp add: prod_def) 
37166  156 
ultimately show "Pair a b = Pair c d \<longleftrightarrow> a = c \<and> b = d" 
37389
09467cdfa198
qualified type "*"; qualified constants Pair, fst, snd, split
haftmann
parents:
37387
diff
changeset

157 
by (simp add: Pair_def Abs_prod_inject) 
37166  158 
qed 
159 

37704
c6161bee8486
adapt Nitpick to "prod_case" and "*" > "sum" renaming;
blanchet
parents:
37678
diff
changeset

160 
declare prod.simps(2) [nitpick_simp del] 
c6161bee8486
adapt Nitpick to "prod_case" and "*" > "sum" renaming;
blanchet
parents:
37678
diff
changeset

161 

40929
7ff03a5e044f
theorem names generated by the (rep_)datatype command now have mandatory qualifiers
huffman
parents:
40702
diff
changeset

162 
declare prod.weak_case_cong [cong del] 
37411
c88c44156083
removed simplifier congruence rule of "prod_case"
haftmann
parents:
37389
diff
changeset

163 

37166  164 

165 
subsubsection {* Tuple syntax *} 

166 

37591  167 
abbreviation (input) split :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'a \<times> 'b \<Rightarrow> 'c" where 
168 
"split \<equiv> prod_case" 

19535  169 

11777  170 
text {* 
171 
Patterns  extends predefined type @{typ pttrn} used in 

172 
abstractions. 

173 
*} 

10213  174 

41229
d797baa3d57c
replaced command 'nonterminals' by slightly modernized version 'nonterminal';
wenzelm
parents:
40968
diff
changeset

175 
nonterminal tuple_args and patterns 
10213  176 

177 
syntax 

178 
"_tuple" :: "'a => tuple_args => 'a * 'b" ("(1'(_,/ _'))") 

179 
"_tuple_arg" :: "'a => tuple_args" ("_") 

180 
"_tuple_args" :: "'a => tuple_args => tuple_args" ("_,/ _") 

11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

181 
"_pattern" :: "[pttrn, patterns] => pttrn" ("'(_,/ _')") 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

182 
"" :: "pttrn => patterns" ("_") 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

183 
"_patterns" :: "[pttrn, patterns] => patterns" ("_,/ _") 
10213  184 

185 
translations 

35115  186 
"(x, y)" == "CONST Pair x y" 
51392
635562bc14ef
extended set comprehension notation with {pttrn : A . P}
nipkow
parents:
51173
diff
changeset

187 
"_pattern x y" => "CONST Pair x y" 
635562bc14ef
extended set comprehension notation with {pttrn : A . P}
nipkow
parents:
51173
diff
changeset

188 
"_patterns x y" => "CONST Pair x y" 
10213  189 
"_tuple x (_tuple_args y z)" == "_tuple x (_tuple_arg (_tuple y z))" 
37591  190 
"%(x, y, zs). b" == "CONST prod_case (%x (y, zs). b)" 
191 
"%(x, y). b" == "CONST prod_case (%x y. b)" 

35115  192 
"_abs (CONST Pair x y) t" => "%(x, y). t" 
37166  193 
 {* The last rule accommodates tuples in `case C ... (x,y) ... => ...' 
194 
The (x,y) is parsed as `Pair x y' because it is logic, not pttrn *} 

10213  195 

35115  196 
(*reconstruct pattern from (nested) splits, avoiding etacontraction of body; 
197 
works best with enclosing "let", if "let" does not avoid etacontraction*) 

14359  198 
print_translation {* 
52143  199 
let 
200 
fun split_tr' [Abs (x, T, t as (Abs abs))] = 

201 
(* split (%x y. t) => %(x,y) t *) 

202 
let 

203 
val (y, t') = Syntax_Trans.atomic_abs_tr' abs; 

204 
val (x', t'') = Syntax_Trans.atomic_abs_tr' (x, T, t'); 

205 
in 

206 
Syntax.const @{syntax_const "_abs"} $ 

207 
(Syntax.const @{syntax_const "_pattern"} $ x' $ y) $ t'' 

208 
end 

209 
 split_tr' [Abs (x, T, (s as Const (@{const_syntax prod_case}, _) $ t))] = 

210 
(* split (%x. (split (%y z. t))) => %(x,y,z). t *) 

211 
let 

212 
val Const (@{syntax_const "_abs"}, _) $ 

213 
(Const (@{syntax_const "_pattern"}, _) $ y $ z) $ t' = split_tr' [t]; 

214 
val (x', t'') = Syntax_Trans.atomic_abs_tr' (x, T, t'); 

215 
in 

216 
Syntax.const @{syntax_const "_abs"} $ 

217 
(Syntax.const @{syntax_const "_pattern"} $ x' $ 

218 
(Syntax.const @{syntax_const "_patterns"} $ y $ z)) $ t'' 

219 
end 

220 
 split_tr' [Const (@{const_syntax prod_case}, _) $ t] = 

221 
(* split (split (%x y z. t)) => %((x, y), z). t *) 

222 
split_tr' [(split_tr' [t])] (* inner split_tr' creates next pattern *) 

223 
 split_tr' [Const (@{syntax_const "_abs"}, _) $ x_y $ Abs abs] = 

224 
(* split (%pttrn z. t) => %(pttrn,z). t *) 

225 
let val (z, t) = Syntax_Trans.atomic_abs_tr' abs in 

226 
Syntax.const @{syntax_const "_abs"} $ 

227 
(Syntax.const @{syntax_const "_pattern"} $ x_y $ z) $ t 

228 
end 

229 
 split_tr' _ = raise Match; 

230 
in [(@{const_syntax prod_case}, K split_tr')] end 

14359  231 
*} 
232 

15422
cbdddc0efadf
added print translation for split: split f > %(x,y). f x y
schirmer
parents:
15404
diff
changeset

233 
(* print "split f" as "\<lambda>(x,y). f x y" and "split (\<lambda>x. f x)" as "\<lambda>(x,y). f x y" *) 
cbdddc0efadf
added print translation for split: split f > %(x,y). f x y
schirmer
parents:
15404
diff
changeset

234 
typed_print_translation {* 
52143  235 
let 
236 
fun split_guess_names_tr' T [Abs (x, _, Abs _)] = raise Match 

237 
 split_guess_names_tr' T [Abs (x, xT, t)] = 

238 
(case (head_of t) of 

239 
Const (@{const_syntax prod_case}, _) => raise Match 

240 
 _ => 

241 
let 

242 
val (_ :: yT :: _) = binder_types (domain_type T) handle Bind => raise Match; 

243 
val (y, t') = Syntax_Trans.atomic_abs_tr' ("y", yT, incr_boundvars 1 t $ Bound 0); 

244 
val (x', t'') = Syntax_Trans.atomic_abs_tr' (x, xT, t'); 

245 
in 

246 
Syntax.const @{syntax_const "_abs"} $ 

247 
(Syntax.const @{syntax_const "_pattern"} $ x' $ y) $ t'' 

248 
end) 

249 
 split_guess_names_tr' T [t] = 

250 
(case head_of t of 

251 
Const (@{const_syntax prod_case}, _) => raise Match 

252 
 _ => 

253 
let 

254 
val (xT :: yT :: _) = binder_types (domain_type T) handle Bind => raise Match; 

255 
val (y, t') = 

256 
Syntax_Trans.atomic_abs_tr' ("y", yT, incr_boundvars 2 t $ Bound 1 $ Bound 0); 

257 
val (x', t'') = Syntax_Trans.atomic_abs_tr' ("x", xT, t'); 

258 
in 

259 
Syntax.const @{syntax_const "_abs"} $ 

260 
(Syntax.const @{syntax_const "_pattern"} $ x' $ y) $ t'' 

261 
end) 

262 
 split_guess_names_tr' _ _ = raise Match; 

263 
in [(@{const_syntax prod_case}, K split_guess_names_tr')] end 

15422
cbdddc0efadf
added print translation for split: split f > %(x,y). f x y
schirmer
parents:
15404
diff
changeset

264 
*} 
cbdddc0efadf
added print translation for split: split f > %(x,y). f x y
schirmer
parents:
15404
diff
changeset

265 

42059
83f3dc509068
fixed a printing problem for bounded quantifiers and bounded set operators in the case of tuples
nipkow
parents:
41792
diff
changeset

266 
(* Force etacontraction for terms of the form "Q A (%p. prod_case P p)" 
83f3dc509068
fixed a printing problem for bounded quantifiers and bounded set operators in the case of tuples
nipkow
parents:
41792
diff
changeset

267 
where Q is some bounded quantifier or set operator. 
83f3dc509068
fixed a printing problem for bounded quantifiers and bounded set operators in the case of tuples
nipkow
parents:
41792
diff
changeset

268 
Reason: the above prints as "Q p : A. case p of (x,y) \<Rightarrow> P x y" 
83f3dc509068
fixed a printing problem for bounded quantifiers and bounded set operators in the case of tuples
nipkow
parents:
41792
diff
changeset

269 
whereas we want "Q (x,y):A. P x y". 
83f3dc509068
fixed a printing problem for bounded quantifiers and bounded set operators in the case of tuples
nipkow
parents:
41792
diff
changeset

270 
Otherwise prevent etacontraction. 
83f3dc509068
fixed a printing problem for bounded quantifiers and bounded set operators in the case of tuples
nipkow
parents:
41792
diff
changeset

271 
*) 
83f3dc509068
fixed a printing problem for bounded quantifiers and bounded set operators in the case of tuples
nipkow
parents:
41792
diff
changeset

272 
print_translation {* 
52143  273 
let 
274 
fun contract Q tr ctxt ts = 

275 
(case ts of 

276 
[A, Abs (_, _, (s as Const (@{const_syntax prod_case},_) $ t) $ Bound 0)] => 

277 
if Term.is_dependent t then tr ctxt ts 

278 
else Syntax.const Q $ A $ s 

279 
 _ => tr ctxt ts); 

280 
in 

42284  281 
[Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax Ball} @{syntax_const "_Ball"}, 
282 
Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax Bex} @{syntax_const "_Bex"}, 

283 
Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax INFI} @{syntax_const "_INF"}, 

284 
Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax SUPR} @{syntax_const "_SUP"}] 

52143  285 
> map (fn (Q, tr) => (Q, contract Q tr)) 
286 
end 

42059
83f3dc509068
fixed a printing problem for bounded quantifiers and bounded set operators in the case of tuples
nipkow
parents:
41792
diff
changeset

287 
*} 
10213  288 

37166  289 
subsubsection {* Code generator setup *} 
290 

37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset

291 
code_type prod 
37166  292 
(SML infix 2 "*") 
293 
(OCaml infix 2 "*") 

294 
(Haskell "!((_),/ (_))") 

295 
(Scala "((_),/ (_))") 

296 

297 
code_const Pair 

298 
(SML "!((_),/ (_))") 

299 
(OCaml "!((_),/ (_))") 

300 
(Haskell "!((_),/ (_))") 

301 
(Scala "!((_),/ (_))") 

302 

38857
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38715
diff
changeset

303 
code_instance prod :: equal 
37166  304 
(Haskell ) 
305 

38857
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38715
diff
changeset

306 
code_const "HOL.equal \<Colon> 'a \<times> 'b \<Rightarrow> 'a \<times> 'b \<Rightarrow> bool" 
39272  307 
(Haskell infix 4 "==") 
37166  308 

309 

310 
subsubsection {* Fundamental operations and properties *} 

11838  311 

49897
cc69be3c8f87
moving Pair_inject from legacy and duplicate section to general section, as Pair_inject was considered a duplicate in e8400e31528a by mistake (cf. communication on dev mailing list)
bulwahn
parents:
49834
diff
changeset

312 
lemma Pair_inject: 
cc69be3c8f87
moving Pair_inject from legacy and duplicate section to general section, as Pair_inject was considered a duplicate in e8400e31528a by mistake (cf. communication on dev mailing list)
bulwahn
parents:
49834
diff
changeset

313 
assumes "(a, b) = (a', b')" 
cc69be3c8f87
moving Pair_inject from legacy and duplicate section to general section, as Pair_inject was considered a duplicate in e8400e31528a by mistake (cf. communication on dev mailing list)
bulwahn
parents:
49834
diff
changeset

314 
and "a = a' ==> b = b' ==> R" 
cc69be3c8f87
moving Pair_inject from legacy and duplicate section to general section, as Pair_inject was considered a duplicate in e8400e31528a by mistake (cf. communication on dev mailing list)
bulwahn
parents:
49834
diff
changeset

315 
shows R 
cc69be3c8f87
moving Pair_inject from legacy and duplicate section to general section, as Pair_inject was considered a duplicate in e8400e31528a by mistake (cf. communication on dev mailing list)
bulwahn
parents:
49834
diff
changeset

316 
using assms by simp 
cc69be3c8f87
moving Pair_inject from legacy and duplicate section to general section, as Pair_inject was considered a duplicate in e8400e31528a by mistake (cf. communication on dev mailing list)
bulwahn
parents:
49834
diff
changeset

317 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

318 
lemma surj_pair [simp]: "EX x y. p = (x, y)" 
37166  319 
by (cases p) simp 
10213  320 

37389
09467cdfa198
qualified type "*"; qualified constants Pair, fst, snd, split
haftmann
parents:
37387
diff
changeset

321 
definition fst :: "'a \<times> 'b \<Rightarrow> 'a" where 
09467cdfa198
qualified type "*"; qualified constants Pair, fst, snd, split
haftmann
parents:
37387
diff
changeset

322 
"fst p = (case p of (a, b) \<Rightarrow> a)" 
11838  323 

37389
09467cdfa198
qualified type "*"; qualified constants Pair, fst, snd, split
haftmann
parents:
37387
diff
changeset

324 
definition snd :: "'a \<times> 'b \<Rightarrow> 'b" where 
09467cdfa198
qualified type "*"; qualified constants Pair, fst, snd, split
haftmann
parents:
37387
diff
changeset

325 
"snd p = (case p of (a, b) \<Rightarrow> b)" 
11838  326 

22886  327 
lemma fst_conv [simp, code]: "fst (a, b) = a" 
37166  328 
unfolding fst_def by simp 
11838  329 

22886  330 
lemma snd_conv [simp, code]: "snd (a, b) = b" 
37166  331 
unfolding snd_def by simp 
11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

332 

37166  333 
code_const fst and snd 
334 
(Haskell "fst" and "snd") 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

335 

41792
ff3cb0c418b7
renamed "nitpick\_def" to "nitpick_unfold" to reflect its new semantics
blanchet
parents:
41505
diff
changeset

336 
lemma prod_case_unfold [nitpick_unfold]: "prod_case = (%c p. c (fst p) (snd p))" 
39302
d7728f65b353
renamed lemmas: ext_iff > fun_eq_iff, set_ext_iff > set_eq_iff, set_ext > set_eqI
nipkow
parents:
39272
diff
changeset

337 
by (simp add: fun_eq_iff split: prod.split) 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

338 

11838  339 
lemma fst_eqD: "fst (x, y) = a ==> x = a" 
340 
by simp 

341 

342 
lemma snd_eqD: "snd (x, y) = a ==> y = a" 

343 
by simp 

344 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

345 
lemma pair_collapse [simp]: "(fst p, snd p) = p" 
11838  346 
by (cases p) simp 
347 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

348 
lemmas surjective_pairing = pair_collapse [symmetric] 
11838  349 

44066
d74182c93f04
rename Pair_fst_snd_eq to prod_eq_iff (keeping old name too)
huffman
parents:
43866
diff
changeset

350 
lemma prod_eq_iff: "s = t \<longleftrightarrow> fst s = fst t \<and> snd s = snd t" 
37166  351 
by (cases s, cases t) simp 
352 

353 
lemma prod_eqI [intro?]: "fst p = fst q \<Longrightarrow> snd p = snd q \<Longrightarrow> p = q" 

44066
d74182c93f04
rename Pair_fst_snd_eq to prod_eq_iff (keeping old name too)
huffman
parents:
43866
diff
changeset

354 
by (simp add: prod_eq_iff) 
37166  355 

356 
lemma split_conv [simp, code]: "split f (a, b) = f a b" 

37591  357 
by (fact prod.cases) 
37166  358 

359 
lemma splitI: "f a b \<Longrightarrow> split f (a, b)" 

360 
by (rule split_conv [THEN iffD2]) 

361 

362 
lemma splitD: "split f (a, b) \<Longrightarrow> f a b" 

363 
by (rule split_conv [THEN iffD1]) 

364 

365 
lemma split_Pair [simp]: "(\<lambda>(x, y). (x, y)) = id" 

39302
d7728f65b353
renamed lemmas: ext_iff > fun_eq_iff, set_ext_iff > set_eq_iff, set_ext > set_eqI
nipkow
parents:
39272
diff
changeset

366 
by (simp add: fun_eq_iff split: prod.split) 
37166  367 

368 
lemma split_eta: "(\<lambda>(x, y). f (x, y)) = f" 

369 
 {* Subsumes the old @{text split_Pair} when @{term f} is the identity function. *} 

39302
d7728f65b353
renamed lemmas: ext_iff > fun_eq_iff, set_ext_iff > set_eq_iff, set_ext > set_eqI
nipkow
parents:
39272
diff
changeset

370 
by (simp add: fun_eq_iff split: prod.split) 
37166  371 

372 
lemma split_comp: "split (f \<circ> g) x = f (g (fst x)) (snd x)" 

373 
by (cases x) simp 

374 

375 
lemma split_twice: "split f (split g p) = split (\<lambda>x y. split f (g x y)) p" 

376 
by (cases p) simp 

377 

378 
lemma The_split: "The (split P) = (THE xy. P (fst xy) (snd xy))" 

37591  379 
by (simp add: prod_case_unfold) 
37166  380 

381 
lemma split_weak_cong: "p = q \<Longrightarrow> split c p = split c q" 

382 
 {* Prevents simplification of @{term c}: much faster *} 

40929
7ff03a5e044f
theorem names generated by the (rep_)datatype command now have mandatory qualifiers
huffman
parents:
40702
diff
changeset

383 
by (fact prod.weak_case_cong) 
37166  384 

385 
lemma cond_split_eta: "(!!x y. f x y = g (x, y)) ==> (%(x, y). f x y) = g" 

386 
by (simp add: split_eta) 

387 

47740
a8989fe9a3a5
added "no_atp"s for extremely prolific, useless facts for ATPs
blanchet
parents:
46950
diff
changeset

388 
lemma split_paired_all [no_atp]: "(!!x. PROP P x) == (!!a b. PROP P (a, b))" 
11820
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

389 
proof 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

390 
fix a b 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

391 
assume "!!x. PROP P x" 
19535  392 
then show "PROP P (a, b)" . 
11820
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

393 
next 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

394 
fix x 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

395 
assume "!!a b. PROP P (a, b)" 
19535  396 
from `PROP P (fst x, snd x)` show "PROP P x" by simp 
11820
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

397 
qed 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

398 

50104  399 
lemma case_prod_distrib: "f (case x of (x, y) \<Rightarrow> g x y) = (case x of (x, y) \<Rightarrow> f (g x y))" 
400 
by (cases x) simp 

401 

11838  402 
text {* 
403 
The rule @{thm [source] split_paired_all} does not work with the 

404 
Simplifier because it also affects premises in congrence rules, 

405 
where this can lead to premises of the form @{text "!!a b. ... = 

406 
?P(a, b)"} which cannot be solved by reflexivity. 

407 
*} 

408 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

409 
lemmas split_tupled_all = split_paired_all unit_all_eq2 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

410 

26480  411 
ML {* 
11838  412 
(* replace parameters of product type by individual component parameters *) 
413 
local (* filtering with exists_paired_all is an essential optimization *) 

16121  414 
fun exists_paired_all (Const ("all", _) $ Abs (_, T, t)) = 
11838  415 
can HOLogic.dest_prodT T orelse exists_paired_all t 
416 
 exists_paired_all (t $ u) = exists_paired_all t orelse exists_paired_all u 

417 
 exists_paired_all (Abs (_, _, t)) = exists_paired_all t 

418 
 exists_paired_all _ = false; 

51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

419 
val ss = 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

420 
simpset_of 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

421 
(put_simpset HOL_basic_ss @{context} 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

422 
addsimps [@{thm split_paired_all}, @{thm unit_all_eq2}, @{thm unit_abs_eta_conv}] 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

423 
addsimprocs [@{simproc unit_eq}]); 
11838  424 
in 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

425 
fun split_all_tac ctxt = SUBGOAL (fn (t, i) => 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

426 
if exists_paired_all t then safe_full_simp_tac (put_simpset ss ctxt) i else no_tac); 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

427 

9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

428 
fun unsafe_split_all_tac ctxt = SUBGOAL (fn (t, i) => 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

429 
if exists_paired_all t then full_simp_tac (put_simpset ss ctxt) i else no_tac); 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

430 

9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

431 
fun split_all ctxt th = 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

432 
if exists_paired_all (Thm.prop_of th) 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

433 
then full_simplify (put_simpset ss ctxt) th else th; 
11838  434 
end; 
26340  435 
*} 
11838  436 

51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51392
diff
changeset

437 
setup {* map_theory_claset (fn ctxt => ctxt addSbefore ("split_all_tac", split_all_tac)) *} 
11838  438 

47740
a8989fe9a3a5
added "no_atp"s for extremely prolific, useless facts for ATPs
blanchet
parents:
46950
diff
changeset

439 
lemma split_paired_All [simp, no_atp]: "(ALL x. P x) = (ALL a b. P (a, b))" 
11838  440 
 {* @{text "[iff]"} is not a good idea because it makes @{text blast} loop *} 
441 
by fast 

442 

47740
a8989fe9a3a5
added "no_atp"s for extremely prolific, useless facts for ATPs
blanchet
parents:
46950
diff
changeset

443 
lemma split_paired_Ex [simp, no_atp]: "(EX x. P x) = (EX a b. P (a, b))" 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

444 
by fast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

445 

47740
a8989fe9a3a5
added "no_atp"s for extremely prolific, useless facts for ATPs
blanchet
parents:
46950
diff
changeset

446 
lemma split_paired_The [no_atp]: "(THE x. P x) = (THE (a, b). P (a, b))" 
11838  447 
 {* Can't be added to simpset: loops! *} 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

448 
by (simp add: split_eta) 
11838  449 

450 
text {* 

451 
Simplification procedure for @{thm [source] cond_split_eta}. Using 

452 
@{thm [source] split_eta} as a rewrite rule is not general enough, 

453 
and using @{thm [source] cond_split_eta} directly would render some 

454 
existing proofs very inefficient; similarly for @{text 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

455 
split_beta}. 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

456 
*} 
11838  457 

26480  458 
ML {* 
11838  459 
local 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

460 
val cond_split_eta_ss = 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

461 
simpset_of (put_simpset HOL_basic_ss @{context} addsimps @{thms cond_split_eta}); 
35364  462 
fun Pair_pat k 0 (Bound m) = (m = k) 
463 
 Pair_pat k i (Const (@{const_name Pair}, _) $ Bound m $ t) = 

464 
i > 0 andalso m = k + i andalso Pair_pat k (i  1) t 

465 
 Pair_pat _ _ _ = false; 

466 
fun no_args k i (Abs (_, _, t)) = no_args (k + 1) i t 

467 
 no_args k i (t $ u) = no_args k i t andalso no_args k i u 

468 
 no_args k i (Bound m) = m < k orelse m > k + i 

469 
 no_args _ _ _ = true; 

470 
fun split_pat tp i (Abs (_, _, t)) = if tp 0 i t then SOME (i, t) else NONE 

37591  471 
 split_pat tp i (Const (@{const_name prod_case}, _) $ Abs (_, _, t)) = split_pat tp (i + 1) t 
35364  472 
 split_pat tp i _ = NONE; 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

473 
fun metaeq ctxt lhs rhs = mk_meta_eq (Goal.prove ctxt [] [] 
35364  474 
(HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs))) 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

475 
(K (simp_tac (put_simpset cond_split_eta_ss ctxt) 1))); 
11838  476 

35364  477 
fun beta_term_pat k i (Abs (_, _, t)) = beta_term_pat (k + 1) i t 
478 
 beta_term_pat k i (t $ u) = 

479 
Pair_pat k i (t $ u) orelse (beta_term_pat k i t andalso beta_term_pat k i u) 

480 
 beta_term_pat k i t = no_args k i t; 

481 
fun eta_term_pat k i (f $ arg) = no_args k i f andalso Pair_pat k i arg 

482 
 eta_term_pat _ _ _ = false; 

11838  483 
fun subst arg k i (Abs (x, T, t)) = Abs (x, T, subst arg (k+1) i t) 
35364  484 
 subst arg k i (t $ u) = 
485 
if Pair_pat k i (t $ u) then incr_boundvars k arg 

486 
else (subst arg k i t $ subst arg k i u) 

487 
 subst arg k i t = t; 

43595  488 
in 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

489 
fun beta_proc ctxt (s as Const (@{const_name prod_case}, _) $ Abs (_, _, t) $ arg) = 
11838  490 
(case split_pat beta_term_pat 1 t of 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

491 
SOME (i, f) => SOME (metaeq ctxt s (subst arg 0 i f)) 
15531  492 
 NONE => NONE) 
35364  493 
 beta_proc _ _ = NONE; 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

494 
fun eta_proc ctxt (s as Const (@{const_name prod_case}, _) $ Abs (_, _, t)) = 
11838  495 
(case split_pat eta_term_pat 1 t of 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

496 
SOME (_, ft) => SOME (metaeq ctxt s (let val (f $ arg) = ft in f end)) 
15531  497 
 NONE => NONE) 
35364  498 
 eta_proc _ _ = NONE; 
11838  499 
end; 
500 
*} 

51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

501 
simproc_setup split_beta ("split f z") = {* fn _ => fn ctxt => fn ct => beta_proc ctxt (term_of ct) *} 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

502 
simproc_setup split_eta ("split f") = {* fn _ => fn ctxt => fn ct => eta_proc ctxt (term_of ct) *} 
11838  503 

26798
a9134a089106
split_beta is now declared as monotonicity rule, to allow bounded
berghofe
parents:
26588
diff
changeset

504 
lemma split_beta [mono]: "(%(x, y). P x y) z = P (fst z) (snd z)" 
11838  505 
by (subst surjective_pairing, rule split_conv) 
506 

50104  507 
lemma split_beta': "(\<lambda>(x,y). f x y) = (\<lambda>x. f (fst x) (snd x))" 
508 
by (auto simp: fun_eq_iff) 

509 

510 

35828
46cfc4b8112e
now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents:
35427
diff
changeset

511 
lemma split_split [no_atp]: "R(split c p) = (ALL x y. p = (x, y) > R(c x y))" 
11838  512 
 {* For use with @{text split} and the Simplifier. *} 
15481  513 
by (insert surj_pair [of p], clarify, simp) 
11838  514 

515 
text {* 

516 
@{thm [source] split_split} could be declared as @{text "[split]"} 

517 
done after the Splitter has been speeded up significantly; 

518 
precompute the constants involved and don't do anything unless the 

519 
current goal contains one of those constants. 

520 
*} 

521 

35828
46cfc4b8112e
now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents:
35427
diff
changeset

522 
lemma split_split_asm [no_atp]: "R (split c p) = (~(EX x y. p = (x, y) & (~R (c x y))))" 
14208  523 
by (subst split_split, simp) 
11838  524 

525 
text {* 

526 
\medskip @{term split} used as a logical connective or set former. 

527 

528 
\medskip These rules are for use with @{text blast}; could instead 

40929
7ff03a5e044f
theorem names generated by the (rep_)datatype command now have mandatory qualifiers
huffman
parents:
40702
diff
changeset

529 
call @{text simp} using @{thm [source] prod.split} as rewrite. *} 
11838  530 

531 
lemma splitI2: "!!p. [ !!a b. p = (a, b) ==> c a b ] ==> split c p" 

532 
apply (simp only: split_tupled_all) 

533 
apply (simp (no_asm_simp)) 

534 
done 

535 

536 
lemma splitI2': "!!p. [ !!a b. (a, b) = p ==> c a b x ] ==> split c p x" 

537 
apply (simp only: split_tupled_all) 

538 
apply (simp (no_asm_simp)) 

539 
done 

540 

541 
lemma splitE: "split c p ==> (!!x y. p = (x, y) ==> c x y ==> Q) ==> Q" 

37591  542 
by (induct p) auto 
11838  543 

544 
lemma splitE': "split c p z ==> (!!x y. p = (x, y) ==> c x y z ==> Q) ==> Q" 

37591  545 
by (induct p) auto 
11838  546 

547 
lemma splitE2: 

548 
"[ Q (split P z); !!x y. [z = (x, y); Q (P x y)] ==> R ] ==> R" 

549 
proof  

550 
assume q: "Q (split P z)" 

551 
assume r: "!!x y. [z = (x, y); Q (P x y)] ==> R" 

552 
show R 

553 
apply (rule r surjective_pairing)+ 

554 
apply (rule split_beta [THEN subst], rule q) 

555 
done 

556 
qed 

557 

558 
lemma splitD': "split R (a,b) c ==> R a b c" 

559 
by simp 

560 

561 
lemma mem_splitI: "z: c a b ==> z: split c (a, b)" 

562 
by simp 

563 

564 
lemma mem_splitI2: "!!p. [ !!a b. p = (a, b) ==> z: c a b ] ==> z: split c p" 

14208  565 
by (simp only: split_tupled_all, simp) 
11838  566 

18372  567 
lemma mem_splitE: 
37166  568 
assumes major: "z \<in> split c p" 
569 
and cases: "\<And>x y. p = (x, y) \<Longrightarrow> z \<in> c x y \<Longrightarrow> Q" 

18372  570 
shows Q 
37591  571 
by (rule major [unfolded prod_case_unfold] cases surjective_pairing)+ 
11838  572 

573 
declare mem_splitI2 [intro!] mem_splitI [intro!] splitI2' [intro!] splitI2 [intro!] splitI [intro!] 

574 
declare mem_splitE [elim!] splitE' [elim!] splitE [elim!] 

575 

26340  576 
ML {* 
11838  577 
local (* filtering with exists_p_split is an essential optimization *) 
37591  578 
fun exists_p_split (Const (@{const_name prod_case},_) $ _ $ (Const (@{const_name Pair},_)$_$_)) = true 
11838  579 
 exists_p_split (t $ u) = exists_p_split t orelse exists_p_split u 
580 
 exists_p_split (Abs (_, _, t)) = exists_p_split t 

581 
 exists_p_split _ = false; 

582 
in 

51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

583 
fun split_conv_tac ctxt = SUBGOAL (fn (t, i) => 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

584 
if exists_p_split t 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

585 
then safe_full_simp_tac (put_simpset HOL_basic_ss ctxt addsimps @{thms split_conv}) i 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

586 
else no_tac); 
11838  587 
end; 
26340  588 
*} 
589 

11838  590 
(* This prevents applications of splitE for already splitted arguments leading 
591 
to quite timeconsuming computations (in particular for nested tuples) *) 

51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51392
diff
changeset

592 
setup {* map_theory_claset (fn ctxt => ctxt addSbefore ("split_conv_tac", split_conv_tac)) *} 
11838  593 

35828
46cfc4b8112e
now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents:
35427
diff
changeset

594 
lemma split_eta_SetCompr [simp,no_atp]: "(%u. EX x y. u = (x, y) & P (x, y)) = P" 
18372  595 
by (rule ext) fast 
11838  596 

35828
46cfc4b8112e
now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents:
35427
diff
changeset

597 
lemma split_eta_SetCompr2 [simp,no_atp]: "(%u. EX x y. u = (x, y) & P x y) = split P" 
18372  598 
by (rule ext) fast 
11838  599 

600 
lemma split_part [simp]: "(%(a,b). P & Q a b) = (%ab. P & split Q ab)" 

601 
 {* Allows simplifications of nested splits in case of independent predicates. *} 

18372  602 
by (rule ext) blast 
11838  603 

14337
e13731554e50
undid split_comp_eq[simp] because it leads to nontermination together with split_def!
nipkow
parents:
14208
diff
changeset

604 
(* Do NOT make this a simp rule as it 
e13731554e50
undid split_comp_eq[simp] because it leads to nontermination together with split_def!
nipkow
parents:
14208
diff
changeset

605 
a) only helps in special situations 
e13731554e50
undid split_comp_eq[simp] because it leads to nontermination together with split_def!
nipkow
parents:
14208
diff
changeset

606 
b) can lead to nontermination in the presence of split_def 
e13731554e50
undid split_comp_eq[simp] because it leads to nontermination together with split_def!
nipkow
parents:
14208
diff
changeset

607 
*) 
e13731554e50
undid split_comp_eq[simp] because it leads to nontermination together with split_def!
nipkow
parents:
14208
diff
changeset

608 
lemma split_comp_eq: 
20415  609 
fixes f :: "'a => 'b => 'c" and g :: "'d => 'a" 
610 
shows "(%u. f (g (fst u)) (snd u)) = (split (%x. f (g x)))" 

18372  611 
by (rule ext) auto 
14101  612 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

613 
lemma pair_imageI [intro]: "(a, b) : A ==> f a b : (%(a, b). f a b) ` A" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

614 
apply (rule_tac x = "(a, b)" in image_eqI) 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

615 
apply auto 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

616 
done 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

617 

11838  618 
lemma The_split_eq [simp]: "(THE (x',y'). x = x' & y = y') = (x, y)" 
619 
by blast 

620 

621 
(* 

622 
the following would be slightly more general, 

623 
but cannot be used as rewrite rule: 

624 
### Cannot add premise as rewrite rule because it contains (type) unknowns: 

625 
### ?y = .x 

626 
Goal "[ P y; !!x. P x ==> x = y ] ==> (@(x',y). x = x' & P y) = (x,y)" 

14208  627 
by (rtac some_equality 1) 
628 
by ( Simp_tac 1) 

629 
by (split_all_tac 1) 

630 
by (Asm_full_simp_tac 1) 

11838  631 
qed "The_split_eq"; 
632 
*) 

633 

634 
text {* 

635 
Setup of internal @{text split_rule}. 

636 
*} 

637 

45607  638 
lemmas prod_caseI = prod.cases [THEN iffD2] 
24699
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

639 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

640 
lemma prod_caseI2: "!!p. [ !!a b. p = (a, b) ==> c a b ] ==> prod_case c p" 
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset

641 
by (fact splitI2) 
24699
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

642 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

643 
lemma prod_caseI2': "!!p. [ !!a b. (a, b) = p ==> c a b x ] ==> prod_case c p x" 
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset

644 
by (fact splitI2') 
24699
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

645 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

646 
lemma prod_caseE: "prod_case c p ==> (!!x y. p = (x, y) ==> c x y ==> Q) ==> Q" 
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset

647 
by (fact splitE) 
24699
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

648 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

649 
lemma prod_caseE': "prod_case c p z ==> (!!x y. p = (x, y) ==> c x y z ==> Q) ==> Q" 
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset

650 
by (fact splitE') 
24699
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

651 

37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset

652 
declare prod_caseI [intro!] 
24699
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

653 

26143
314c0bcb7df7
Added useful general lemmas from the work with the HeapMonad
bulwahn
parents:
25885
diff
changeset

654 
lemma prod_case_beta: 
314c0bcb7df7
Added useful general lemmas from the work with the HeapMonad
bulwahn
parents:
25885
diff
changeset

655 
"prod_case f p = f (fst p) (snd p)" 
37591  656 
by (fact split_beta) 
26143
314c0bcb7df7
Added useful general lemmas from the work with the HeapMonad
bulwahn
parents:
25885
diff
changeset

657 

24699
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

658 
lemma prod_cases3 [cases type]: 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

659 
obtains (fields) a b c where "y = (a, b, c)" 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

660 
by (cases y, case_tac b) blast 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

661 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

662 
lemma prod_induct3 [case_names fields, induct type]: 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

663 
"(!!a b c. P (a, b, c)) ==> P x" 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

664 
by (cases x) blast 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

665 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

666 
lemma prod_cases4 [cases type]: 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

667 
obtains (fields) a b c d where "y = (a, b, c, d)" 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

668 
by (cases y, case_tac c) blast 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

669 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

670 
lemma prod_induct4 [case_names fields, induct type]: 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

671 
"(!!a b c d. P (a, b, c, d)) ==> P x" 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

672 
by (cases x) blast 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

673 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

674 
lemma prod_cases5 [cases type]: 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

675 
obtains (fields) a b c d e where "y = (a, b, c, d, e)" 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

676 
by (cases y, case_tac d) blast 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

677 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

678 
lemma prod_induct5 [case_names fields, induct type]: 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

679 
"(!!a b c d e. P (a, b, c, d, e)) ==> P x" 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

680 
by (cases x) blast 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

681 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

682 
lemma prod_cases6 [cases type]: 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

683 
obtains (fields) a b c d e f where "y = (a, b, c, d, e, f)" 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

684 
by (cases y, case_tac e) blast 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

685 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

686 
lemma prod_induct6 [case_names fields, induct type]: 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

687 
"(!!a b c d e f. P (a, b, c, d, e, f)) ==> P x" 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

688 
by (cases x) blast 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

689 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

690 
lemma prod_cases7 [cases type]: 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

691 
obtains (fields) a b c d e f g where "y = (a, b, c, d, e, f, g)" 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

692 
by (cases y, case_tac f) blast 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

693 

c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

694 
lemma prod_induct7 [case_names fields, induct type]: 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

695 
"(!!a b c d e f g. P (a, b, c, d, e, f, g)) ==> P x" 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

696 
by (cases x) blast 
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

697 

37166  698 
lemma split_def: 
699 
"split = (\<lambda>c p. c (fst p) (snd p))" 

37591  700 
by (fact prod_case_unfold) 
37166  701 

702 
definition internal_split :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'a \<times> 'b \<Rightarrow> 'c" where 

703 
"internal_split == split" 

704 

705 
lemma internal_split_conv: "internal_split c (a, b) = c a b" 

706 
by (simp only: internal_split_def split_conv) 

707 

48891  708 
ML_file "Tools/split_rule.ML" 
37166  709 
setup Split_Rule.setup 
710 

711 
hide_const internal_split 

712 

24699
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

713 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

714 
subsubsection {* Derived operations *} 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

715 

37387
3581483cca6c
qualified types "+" and nat; qualified constants Ball, Bex, Suc, curry; modernized some specifications
haftmann
parents:
37278
diff
changeset

716 
definition curry :: "('a \<times> 'b \<Rightarrow> 'c) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'c" where 
3581483cca6c
qualified types "+" and nat; qualified constants Ball, Bex, Suc, curry; modernized some specifications
haftmann
parents:
37278
diff
changeset

717 
"curry = (\<lambda>c x y. c (x, y))" 
37166  718 

719 
lemma curry_conv [simp, code]: "curry f a b = f (a, b)" 

720 
by (simp add: curry_def) 

721 

722 
lemma curryI [intro!]: "f (a, b) \<Longrightarrow> curry f a b" 

723 
by (simp add: curry_def) 

724 

725 
lemma curryD [dest!]: "curry f a b \<Longrightarrow> f (a, b)" 

726 
by (simp add: curry_def) 

727 

728 
lemma curryE: "curry f a b \<Longrightarrow> (f (a, b) \<Longrightarrow> Q) \<Longrightarrow> Q" 

729 
by (simp add: curry_def) 

730 

731 
lemma curry_split [simp]: "curry (split f) = f" 

732 
by (simp add: curry_def split_def) 

733 

734 
lemma split_curry [simp]: "split (curry f) = f" 

735 
by (simp add: curry_def split_def) 

736 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

737 
text {* 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

738 
The compositionuncurry combinator. 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

739 
*} 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

740 

37751  741 
notation fcomp (infixl "\<circ>>" 60) 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

742 

37751  743 
definition scomp :: "('a \<Rightarrow> 'b \<times> 'c) \<Rightarrow> ('b \<Rightarrow> 'c \<Rightarrow> 'd) \<Rightarrow> 'a \<Rightarrow> 'd" (infixl "\<circ>\<rightarrow>" 60) where 
744 
"f \<circ>\<rightarrow> g = (\<lambda>x. prod_case g (f x))" 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

745 

37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset

746 
lemma scomp_unfold: "scomp = (\<lambda>f g x. g (fst (f x)) (snd (f x)))" 
39302
d7728f65b353
renamed lemmas: ext_iff > fun_eq_iff, set_ext_iff > set_eq_iff, set_ext > set_eqI
nipkow
parents:
39272
diff
changeset

747 
by (simp add: fun_eq_iff scomp_def prod_case_unfold) 
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37591
diff
changeset

748 

37751  749 
lemma scomp_apply [simp]: "(f \<circ>\<rightarrow> g) x = prod_case g (f x)" 
750 
by (simp add: scomp_unfold prod_case_unfold) 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

751 

37751  752 
lemma Pair_scomp: "Pair x \<circ>\<rightarrow> f = f x" 
44921  753 
by (simp add: fun_eq_iff) 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

754 

37751  755 
lemma scomp_Pair: "x \<circ>\<rightarrow> Pair = x" 
44921  756 
by (simp add: fun_eq_iff) 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

757 

37751  758 
lemma scomp_scomp: "(f \<circ>\<rightarrow> g) \<circ>\<rightarrow> h = f \<circ>\<rightarrow> (\<lambda>x. g x \<circ>\<rightarrow> h)" 
39302
d7728f65b353
renamed lemmas: ext_iff > fun_eq_iff, set_ext_iff > set_eq_iff, set_ext > set_eqI
nipkow
parents:
39272
diff
changeset

759 
by (simp add: fun_eq_iff scomp_unfold) 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

760 

37751  761 
lemma scomp_fcomp: "(f \<circ>\<rightarrow> g) \<circ>> h = f \<circ>\<rightarrow> (\<lambda>x. g x \<circ>> h)" 
39302
d7728f65b353
renamed lemmas: ext_iff > fun_eq_iff, set_ext_iff > set_eq_iff, set_ext > set_eqI
nipkow
parents:
39272
diff
changeset

762 
by (simp add: fun_eq_iff scomp_unfold fcomp_def) 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

763 

37751  764 
lemma fcomp_scomp: "(f \<circ>> g) \<circ>\<rightarrow> h = f \<circ>> (g \<circ>\<rightarrow> h)" 
44921  765 
by (simp add: fun_eq_iff scomp_unfold) 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

766 

31202
52d332f8f909
pretty printing of functional combinators for evaluation code
haftmann
parents:
30924
diff
changeset

767 
code_const scomp 
52d332f8f909
pretty printing of functional combinators for evaluation code
haftmann
parents:
30924
diff
changeset

768 
(Eval infixl 3 "#>") 
52d332f8f909
pretty printing of functional combinators for evaluation code
haftmann
parents:
30924
diff
changeset

769 

37751  770 
no_notation fcomp (infixl "\<circ>>" 60) 
771 
no_notation scomp (infixl "\<circ>\<rightarrow>" 60) 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

772 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

773 
text {* 
40607  774 
@{term map_pair}  action of the product functor upon 
36664
6302f9ad7047
repaired comments where SOMEthing went utterly wrong (cf. 2b04504fcb69)
krauss
parents:
36622
diff
changeset

775 
functions. 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

776 
*} 
21195  777 

40607  778 
definition map_pair :: "('a \<Rightarrow> 'c) \<Rightarrow> ('b \<Rightarrow> 'd) \<Rightarrow> 'a \<times> 'b \<Rightarrow> 'c \<times> 'd" where 
779 
"map_pair f g = (\<lambda>(x, y). (f x, g y))" 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

780 

40607  781 
lemma map_pair_simp [simp, code]: 
782 
"map_pair f g (a, b) = (f a, g b)" 

783 
by (simp add: map_pair_def) 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

784 

41505
6d19301074cf
"enriched_type" replaces less specific "type_lifting"
haftmann
parents:
41372
diff
changeset

785 
enriched_type map_pair: map_pair 
44921  786 
by (auto simp add: split_paired_all) 
37278  787 

40607  788 
lemma fst_map_pair [simp]: 
789 
"fst (map_pair f g x) = f (fst x)" 

790 
by (cases x) simp_all 

37278  791 

40607  792 
lemma snd_prod_fun [simp]: 
793 
"snd (map_pair f g x) = g (snd x)" 

794 
by (cases x) simp_all 

37278  795 

40607  796 
lemma fst_comp_map_pair [simp]: 
797 
"fst \<circ> map_pair f g = f \<circ> fst" 

798 
by (rule ext) simp_all 

37278  799 

40607  800 
lemma snd_comp_map_pair [simp]: 
801 
"snd \<circ> map_pair f g = g \<circ> snd" 

802 
by (rule ext) simp_all 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

803 

40607  804 
lemma map_pair_compose: 
805 
"map_pair (f1 o f2) (g1 o g2) = (map_pair f1 g1 o map_pair f2 g2)" 

806 
by (rule ext) (simp add: map_pair.compositionality comp_def) 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

807 

40607  808 
lemma map_pair_ident [simp]: 
809 
"map_pair (%x. x) (%y. y) = (%z. z)" 

810 
by (rule ext) (simp add: map_pair.identity) 

811 

812 
lemma map_pair_imageI [intro]: 

813 
"(a, b) \<in> R \<Longrightarrow> (f a, g b) \<in> map_pair f g ` R" 

814 
by (rule image_eqI) simp_all 

21195  815 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

816 
lemma prod_fun_imageE [elim!]: 
40607  817 
assumes major: "c \<in> map_pair f g ` R" 
818 
and cases: "\<And>x y. c = (f x, g y) \<Longrightarrow> (x, y) \<in> R \<Longrightarrow> P" 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

819 
shows P 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

820 
apply (rule major [THEN imageE]) 
37166  821 
apply (case_tac x) 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

822 
apply (rule cases) 
40607  823 
apply simp_all 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

824 
done 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

825 

37166  826 
definition apfst :: "('a \<Rightarrow> 'c) \<Rightarrow> 'a \<times> 'b \<Rightarrow> 'c \<times> 'b" where 
40607  827 
"apfst f = map_pair f id" 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

828 

37166  829 
definition apsnd :: "('b \<Rightarrow> 'c) \<Rightarrow> 'a \<times> 'b \<Rightarrow> 'a \<times> 'c" where 
40607  830 
"apsnd f = map_pair id f" 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

831 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

832 
lemma apfst_conv [simp, code]: 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

833 
"apfst f (x, y) = (f x, y)" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

834 
by (simp add: apfst_def) 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

835 

33638
548a34929e98
Renamed upd_snd_conv to apsnd_conv to be consistent with apfst_conv; Added apsnd_apfst_commute
hoelzl
parents:
33594
diff
changeset

836 
lemma apsnd_conv [simp, code]: 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

837 
"apsnd f (x, y) = (x, f y)" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

838 
by (simp add: apsnd_def) 
21195  839 

33594  840 
lemma fst_apfst [simp]: 
841 
"fst (apfst f x) = f (fst x)" 

842 
by (cases x) simp 

843 

51173  844 
lemma fst_comp_apfst [simp]: 
845 
"fst \<circ> apfst f = f \<circ> fst" 

846 
by (simp add: fun_eq_iff) 

847 

33594  848 
lemma fst_apsnd [simp]: 
849 
"fst (apsnd f x) = fst x" 

850 
by (cases x) simp 

851 

51173  852 
lemma fst_comp_apsnd [simp]: 
853 
"fst \<circ> apsnd f = fst" 

854 
by (simp add: fun_eq_iff) 

855 

33594  856 
lemma snd_apfst [simp]: 
857 
"snd (apfst f x) = snd x" 

858 
by (cases x) simp 

859 

51173  860 
lemma snd_comp_apfst [simp]: 
861 
"snd \<circ> apfst f = snd" 

862 
by (simp add: fun_eq_iff) 

863 

33594  864 
lemma snd_apsnd [simp]: 
865 
"snd (apsnd f x) = f (snd x)" 

866 
by (cases x) simp 

867 

51173  868 
lemma snd_comp_apsnd [simp]: 
869 
"snd \<circ> apsnd f = f \<circ> snd" 

870 
by (simp add: fun_eq_iff) 

871 

33594  872 
lemma apfst_compose: 
873 
"apfst f (apfst g x) = apfst (f \<circ> g) x" 

874 
by (cases x) simp 

875 

876 
lemma apsnd_compose: 

877 
"apsnd f (apsnd g x) = apsnd (f \<circ> g) x" 

878 
by (cases x) simp 

879 

880 
lemma apfst_apsnd [simp]: 

881 
"apfst f (apsnd g x) = (f (fst x), g (snd x))" 

882 
by (cases x) simp 

883 

884 
lemma apsnd_apfst [simp]: 

885 
"apsnd f (apfst g x) = (g (fst x), f (snd x))" 

886 
by (cases x) simp 

887 

888 
lemma apfst_id [simp] : 

889 
"apfst id = id" 

39302
d7728f65b353
renamed lemmas: ext_iff > fun_eq_iff, set_ext_iff > set_eq_iff, set_ext > set_eqI
nipkow
parents:
39272
diff
changeset

890 
by (simp add: fun_eq_iff) 
33594  891 

892 
lemma apsnd_id [simp] : 

893 
"apsnd id = id" 

39302
d7728f65b353
renamed lemmas: ext_iff > fun_eq_iff, set_ext_iff > set_eq_iff, set_ext > set_eqI
nipkow
parents:
39272
diff
changeset

894 
by (simp add: fun_eq_iff) 
33594  895 

896 
lemma apfst_eq_conv [simp]: 

897 
"apfst f x = apfst g x \<longleftrightarrow> f (fst x) = g (fst x)" 

898 
by (cases x) simp 

899 

900 
lemma apsnd_eq_conv [simp]: 

901 
"apsnd f x = apsnd g x \<longleftrightarrow> f (snd x) = g (snd x)" 

902 
by (cases x) simp 

903 

33638
548a34929e98
Renamed upd_snd_conv to apsnd_conv to be consistent with apfst_conv; Added apsnd_apfst_commute
hoelzl
parents:
33594
diff
changeset

904 
lemma apsnd_apfst_commute: 
548a34929e98
Renamed upd_snd_conv to apsnd_conv to be consistent with apfst_conv; Added apsnd_apfst_commute
hoelzl
parents:
33594
diff
changeset

905 
"apsnd f (apfst g p) = apfst g (apsnd f p)" 
548a34929e98
Renamed upd_snd_conv to apsnd_conv to be consistent with apfst_conv; Added apsnd_apfst_commute
hoelzl
parents:
33594
diff
changeset

906 
by simp 
21195  907 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

908 
text {* 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

909 
Disjoint union of a family of sets  Sigma. 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

910 
*} 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

911 

45986
c9e50153e5ae
moved various set operations to theory Set (resp. Product_Type)
haftmann
parents:
45696
diff
changeset

912 
definition Sigma :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> ('a \<times> 'b) set" where 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

913 
Sigma_def: "Sigma A B == UN x:A. UN y:B x. {Pair x y}" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

914 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

915 
abbreviation 
45986
c9e50153e5ae
moved various set operations to theory Set (resp. Product_Type)
haftmann
parents:
45696
diff
changeset

916 
Times :: "'a set \<Rightarrow> 'b set \<Rightarrow> ('a \<times> 'b) set" 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

917 
(infixr "<*>" 80) where 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

918 
"A <*> B == Sigma A (%_. B)" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

919 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

920 
notation (xsymbols) 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

921 
Times (infixr "\<times>" 80) 
15394  922 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

923 
notation (HTML output) 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

924 
Times (infixr "\<times>" 80) 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

925 

45662
4f7c05990420
Hide Product_Type.Times  too precious an identifier
nipkow
parents:
45607
diff
changeset

926 
hide_const (open) Times 
4f7c05990420
Hide Product_Type.Times  too precious an identifier
nipkow
parents:
45607
diff
changeset

927 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

928 
syntax 
35115  929 
"_Sigma" :: "[pttrn, 'a set, 'b set] => ('a * 'b) set" ("(3SIGMA _:_./ _)" [0, 0, 10] 10) 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

930 
translations 
35115  931 
"SIGMA x:A. B" == "CONST Sigma A (%x. B)" 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

932 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

933 
lemma SigmaI [intro!]: "[ a:A; b:B(a) ] ==> (a,b) : Sigma A B" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

934 
by (unfold Sigma_def) blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

935 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

936 
lemma SigmaE [elim!]: 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

937 
"[ c: Sigma A B; 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

938 
!!x y.[ x:A; y:B(x); c=(x,y) ] ==> P 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

939 
] ==> P" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

940 
 {* The general elimination rule. *} 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

941 
by (unfold Sigma_def) blast 
20588  942 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

943 
text {* 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

944 
Elimination of @{term "(a, b) : A \<times> B"}  introduces no 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

945 
eigenvariables. 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

946 
*} 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

947 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

948 
lemma SigmaD1: "(a, b) : Sigma A B ==> a : A" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

949 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

950 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

951 
lemma SigmaD2: "(a, b) : Sigma A B ==> b : B a" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

952 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

953 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

954 
lemma SigmaE2: 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

955 
"[ (a, b) : Sigma A B; 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

956 
[ a:A; b:B(a) ] ==> P 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

957 
] ==> P" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

958 
by blast 
20588  959 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

960 
lemma Sigma_cong: 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

961 
"\<lbrakk>A = B; !!x. x \<in> B \<Longrightarrow> C x = D x\<rbrakk> 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

962 
\<Longrightarrow> (SIGMA x: A. C x) = (SIGMA x: B. D x)" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

963 
by auto 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

964 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

965 
lemma Sigma_mono: "[ A <= C; !!x. x:A ==> B x <= D x ] ==> Sigma A B <= Sigma C D" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

966 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

967 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

968 
lemma Sigma_empty1 [simp]: "Sigma {} B = {}" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

969 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

970 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

971 
lemma Sigma_empty2 [simp]: "A <*> {} = {}" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

972 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

973 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

974 
lemma UNIV_Times_UNIV [simp]: "UNIV <*> UNIV = UNIV" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

975 
by auto 
21908  976 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

977 
lemma Compl_Times_UNIV1 [simp]: " (UNIV <*> A) = UNIV <*> (A)" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

978 
by auto 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

979 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

980 
lemma Compl_Times_UNIV2 [simp]: " (A <*> UNIV) = (A) <*> UNIV" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

981 
by auto 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

982 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

983 
lemma mem_Sigma_iff [iff]: "((a,b): Sigma A B) = (a:A & b:B(a))" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

984 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

985 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

986 
lemma Times_subset_cancel2: "x:C ==> (A <*> C <= B <*> C) = (A <= B)" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

987 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

988 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

989 
lemma Times_eq_cancel2: "x:C ==> (A <*> C = B <*> C) = (A = B)" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

990 
by (blast elim: equalityE) 
20588  991 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

992 
lemma SetCompr_Sigma_eq: 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

993 
"Collect (split (%x y. P x & Q x y)) = (SIGMA x:Collect P. Collect (Q x))" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

994 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

995 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

996 
lemma Collect_split [simp]: "{(a,b). P a & Q b} = Collect P <*> Collect Q" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

997 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

998 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

999 
lemma UN_Times_distrib: 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1000 
"(UN (a,b):(A <*> B). E a <*> F b) = (UNION A E) <*> (UNION B F)" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1001 
 {* Suggested by Pierre Chartier *} 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1002 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1003 

47740
a8989fe9a3a5
added "no_atp"s for extremely prolific, useless facts for ATPs
blanchet
parents:
46950
diff
changeset

1004 
lemma split_paired_Ball_Sigma [simp, no_atp]: 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1005 
"(ALL z: Sigma A B. P z) = (ALL x:A. ALL y: B x. P(x,y))" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1006 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1007 

47740
a8989fe9a3a5
added "no_atp"s for extremely prolific, useless facts for ATPs
blanchet
parents:
46950
diff
changeset

1008 
lemma split_paired_Bex_Sigma [simp, no_atp]: 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1009 
"(EX z: Sigma A B. P z) = (EX x:A. EX y: B x. P(x,y))" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1010 
by blast 
21908  1011 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1012 
lemma Sigma_Un_distrib1: "(SIGMA i:I Un J. C(i)) = (SIGMA i:I. C(i)) Un (SIGMA j:J. C(j))" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1013 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1014 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1015 
lemma Sigma_Un_distrib2: "(SIGMA i:I. A(i) Un B(i)) = (SIGMA i:I. A(i)) Un (SIGMA i:I. B(i))" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1016 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1017 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1018 
lemma Sigma_Int_distrib1: "(SIGMA i:I Int J. C(i)) = (SIGMA i:I. C(i)) Int (SIGMA j:J. C(j))" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1019 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1020 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1021 
lemma Sigma_Int_distrib2: "(SIGMA i:I. A(i) Int B(i)) = (SIGMA i:I. A(i)) Int (SIGMA i:I. B(i))" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1022 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1023 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1024 
lemma Sigma_Diff_distrib1: "(SIGMA i:I  J. C(i)) = (SIGMA i:I. C(i))  (SIGMA j:J. C(j))" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1025 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1026 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1027 
lemma Sigma_Diff_distrib2: "(SIGMA i:I. A(i)  B(i)) = (SIGMA i:I. A(i))  (SIGMA i:I. B(i))" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1028 
by blast 
21908  1029 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1030 
lemma Sigma_Union: "Sigma (Union X) B = (UN A:X. Sigma A B)" 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1031 
by blast 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1032 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1033 
text {* 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1034 
Nondependent versions are needed to avoid the need for higherorder 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1035 
matching, especially when the rules are reoriented. 
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1036 
*} 
21908  1037 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1038 
lemma Times_Un_distrib1: "(A Un B) <*> C = (A <*> C) Un (B <*> C)" 
28719  1039 
by blast 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1040 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1041 
lemma Times_Int_distrib1: "(A Int B) <*> C = (A <*> C) Int (B <*> C)" 
28719  1042 
by blast 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1043 

d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1044 
lemma Times_Diff_distrib1: "(A  B) <*> C = (A <*> C)  (B <*> C)" 
28719  1045 
by blast 
26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1046 

36622
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1047 
lemma Times_empty[simp]: "A \<times> B = {} \<longleftrightarrow> A = {} \<or> B = {}" 
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1048 
by auto 
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1049 

50104  1050 
lemma times_eq_iff: "A \<times> B = C \<times> D \<longleftrightarrow> A = C \<and> B = D \<or> ((A = {} \<or> B = {}) \<and> (C = {} \<or> D = {}))" 
1051 
by auto 

1052 

36622
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1053 
lemma fst_image_times[simp]: "fst ` (A \<times> B) = (if B = {} then {} else A)" 
44921  1054 
by force 
36622
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1055 

e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1056 
lemma snd_image_times[simp]: "snd ` (A \<times> B) = (if A = {} then {} else B)" 
44921  1057 
by force 
36622
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1058 

28719  1059 
lemma insert_times_insert[simp]: 
1060 
"insert a A \<times> insert b B = 

1061 
insert (a,b) (A \<times> insert b B \<union> insert a A \<times> B)" 

1062 
by blast 

26358
d6a508c16908
Product_Type.apfst and Product_Type.apsnd; mbind combinator; tuned
haftmann
parents:
26340
diff
changeset

1063 

33271
7be66dee1a5a
New theory Probability, which contains a development of measure theory
paulson
parents:
33089
diff
changeset

1064 
lemma vimage_Times: "f ` (A \<times> B) = ((fst \<circ> f) ` A) \<inter> ((snd \<circ> f) ` B)" 
47988  1065 
apply auto 
1066 
apply (case_tac "f x") 

1067 
apply auto 

1068 
done 

33271
7be66dee1a5a
New theory Probability, which contains a development of measure theory
paulson
parents:
33089
diff
changeset

1069 

50104  1070 
lemma times_Int_times: "A \<times> B \<inter> C \<times> D = (A \<inter> C) \<times> (B \<inter> D)" 
1071 
by auto 

1072 

35822  1073 
lemma swap_inj_on: 
36622
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1074 
"inj_on (\<lambda>(i, j). (j, i)) A" 
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1075 
by (auto intro!: inj_onI) 
35822  1076 

1077 
lemma swap_product: 

1078 
"(%(i, j). (j, i)) ` (A \<times> B) = B \<times> A" 

1079 
by (simp add: split_def image_def) blast 

1080 

36622
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1081 
lemma image_split_eq_Sigma: 
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1082 
"(\<lambda>x. (f x, g x)) ` A = Sigma (f ` A) (\<lambda>x. g ` (f ` {x} \<inter> A))" 
46128
53e7cc599f58
interaction of set operations for execution and membership predicate
haftmann
parents:
46028
diff
changeset

1083 
proof (safe intro!: imageI) 
36622
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1084 
fix a b assume *: "a \<in> A" "b \<in> A" and eq: "f a = f b" 
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1085 
show "(f b, g a) \<in> (\<lambda>x. (f x, g x)) ` A" 
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1086 
using * eq[symmetric] by auto 
e393a91f86df
Generalize swap_inj_on; add simps for Times; add Ex_list_of_length, log_inj; Added missing locale edges for linordered semiring with 1.
hoelzl
parents:
36176
diff
changeset

1087 
qed simp_all 
35822  1088 

46128
53e7cc599f58
interaction of set operations for execution and membership predicate
haftmann
parents:
46028
diff
changeset

1089 
definition product :: "'a set \<Rightarrow> 'b set \<Rightarrow> ('a \<times> 'b) set" where 
53e7cc599f58
interaction of set operations for execution and membership predicate
haftmann
parents:
46028
diff
changeset

1090 
[code_abbrev]: "product A B = A \<times> B" 
53e7cc599f58
interaction of set operations for execution and membership predicate
haftmann
parents:
46028
diff
changeset

1091 

53e7cc599f58
interaction of set operations for execution and membership predicate
haftmann
parents:
46028
diff
changeset

1092 
hide_const (open) product 
53e7cc599f58
interaction of set operations for execution and membership predicate
haftmann
parents:
46028
diff
changeset

1093 

53e7cc599f58
interaction of set operations for execution and membership predicate
haftmann
parents:
46028
diff
changeset

1094 
lemma member_product: 
53e7cc599f58
interaction of set operations for execution and membership predicate
haftmann
parents:
46028
diff
changeset

1095 
"x \<in> Product_Type.product A B \<longleftrightarrow> x \<in> A \<times> B" 
53e7cc599f58
interaction of set operations for execution and membership predicate
haftmann
parents:
46028
diff
changeset

1096 
by (simp add: product_def) 
53e7cc599f58
interaction of set operations for execution and membership predicate
haftmann
parents:
46028
diff
changeset

1097 

40607  1098 
text {* The following @{const map_pair} lemmas are due to Joachim Breitner: *} 
1099 

1100 
lemma map_pair_inj_on: 

1101 
assumes "inj_on f A" and "inj_on g B" 

1102 
shows "inj_on (map_pair f g) (A \<times> B)" 

1103 
proof (rule inj_onI) 

1104 
fix x :: "'a \<times> 'c" and y :: "'a \<times> 'c" 

1105 
assume "x \<in> A \<times> B" hence "fst x \<in> A" and "snd x \<in> B" by auto 

1106 
assume "y \<in> A \<times> B" hence "fst y \<in> A" and "snd y \<in> B" by auto 

1107 
assume "map_pair f g x = map_pair f g y" 

1108 
hence "fst (map_pair f g x) = fst (map_pair f g y)" by (auto) 

1109 
hence "f (fst x) = f (fst y)" by (cases x,cases y,auto) 

1110 
with `inj_on f A` and `fst x \<in> A` and `fst y \<in> A` 

1111 
have "fst x = fst y" by (auto dest:dest:inj_onD) 

1112 
moreover from `map_pair f g x = map_pair f g y` 

1113 
have "snd (map_pair f g x) = snd (map_pair f g y)" by (auto) 

1114 
hence "g (snd x) = g (snd y)" by (cases x,cases y,auto) 

1115 
with `inj_on g B` and `snd x \<in> B` and `snd y \<in> B` 

1116 
have "snd x = snd y" by (auto dest:dest:inj_onD) 

1117 
ultimately show "x = y" by(rule prod_eqI) 

1118 
qed 

1119 

1120 
lemma map_pair_surj: 

40702  1121 
fixes f :: "'a \<Rightarrow> 'b" and g :: "'c \<Rightarrow> 'd" 
40607  1122 
assumes "surj f" and "surj g" 
1123 
shows "surj (map_pair f g)" 

1124 
unfolding surj_def 

1125 
proof 

1126 
fix y :: "'b \<times> 'd" 

1127 
from `surj f` obtain a where "fst y = f a" by (auto elim:surjE) 

1128 
moreover 

1129 
from `surj g` obtain b where "snd y = g b" by (auto elim:surjE) 

1130 
ultimately have "(fst y, snd y) = map_pair f g (a,b)" by auto 

1131 
thus "\<exists>x. y = map_pair f g x" by auto 

1132 
qed 

1133 

1134 
lemma map_pair_surj_on: 

1135 
assumes "f ` A = A'" and "g ` B = B'" 

1136 
shows "map_pair f g ` (A \<times> B) = A' \<times> B'" 

1137 
unfolding image_def 

1138 
proof(rule set_eqI,rule iffI) 

1139 
fix x :: "'a \<times> 'c" 

1140 
assume "x \<in> {y\<Colon>'a \<times> 'c. \<exists>x\<Colon>'b \<times> 'd\<in>A \<times> B. y = map_pair f g x}" 

1141 
then obtain y where "y \<in> A \<times> B" and "x = map_pair f g y" by blast 

1142 
from `image f A = A'` and `y \<in> A \<times> B` have "f (fst y) \<in> A'" by auto 

1143 
moreover from `image g B = B'` and `y \<in> A \<times> B` have "g (snd y) \<in> B'" by auto 

1144 
ultimately have "(f (fst y), g (snd y)) \<in> (A' \<times> B')" by auto 

1145 
with `x = map_pair f g y` show "x \<in> A' \<times> B'" by (cases y, auto) 

1146 
next 

1147 
fix x :: "'a \<times> 'c" 

1148 
assume "x \<in> A' \<times> B'" hence "fst x \<in> A'" and "snd x \<in> B'" by auto 

1149 
from `image f A = A'` and `fst x \<in> A'` have "fst x \<in> image f A" by auto 

1150 
then obtain a where "a \<in> A" and "fst x = f a" by (rule imageE) 

1151 
moreover from `image g B = B'` and `snd x \<in> B'` 

1152 
obtain b where "b \<in> B" and "snd x = g b" by auto 

1153 
ultimately have "(fst x, snd x) = map_pair f g (a,b)" by auto 

1154 
moreover from `a \<in> A` and `b \<in> B` have "(a , b) \<in> A \<times> B" by auto 

1155 
ultimately have "\<exists>y \<in> A \<times> B. x = map_pair f g y" by auto 

1156 
thus "x \<in> {x. \<exists>y \<in> A \<times> B. x = map_pair f g y}" by auto 

1157 
qed 

1158 

21908  1159 

49764
9979d64b8016
moving simproc from Finite_Set to more appropriate Product_Type theory
bulwahn
parents:
48891
diff
changeset

1160 
subsection {* Simproc for rewriting a set comprehension into a pointfree expression *} 
9979d64b8016
moving simproc from Finite_Set to more appropriate Product_Type theory
bulwahn
parents:
48891
diff
changeset

1161 

9979d64b8016
moving simproc from Finite_Set to more appropriate Product_Type theory
bulwahn
parents:
48891
diff
changeset

1162 
ML_file "Tools/set_comprehension_pointfree.ML" 
9979d64b8016
moving simproc from Finite_Set to more appropriate Product_Type theory
bulwahn
parents:
48891
diff
changeset

1163 

9979d64b8016
moving simproc from Finite_Set to more appropriate Product_Type theory
bulwahn
parents:
48891
diff
changeset

1164 
setup {* 
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset

1165 
Code_Preproc.map_pre (fn ctxt => ctxt addsimprocs 
49764
9979d64b8016
moving simproc from Finite_Set to more appropriate Product_Type theory
bulwahn
parents:
48891
diff
changeset

1166 
[Raw_Simplifier.make_simproc {name = "set comprehension", lhss = [@{cpat "Collect ?P"}], 
9979d64b8016
moving simproc from Finite_Set to more appropriate Product_Type theory
bulwahn
parents:
48891
diff
changeset

1167 
proc = K Set_Comprehension_Pointfree.code_simproc, identifier = []}]) 
9979d64b8016
moving simproc from Finite_Set to more appropriate Product_Type theory
bulwahn
parents:
48891
diff
changeset

1168 
*} 
9979d64b8016
moving simproc from Finite_Set to more appropriate Product_Type theory
bulwahn
parents:
48891
diff
changeset

1169 

9979d64b8016
moving simproc from Finite_Set to more appropriate Product_Type theory
bulwahn
parents:
48891
diff
changeset

1170 

37166  1171 
subsection {* Inductively defined sets *} 
15394  1172 

48891  1173 
ML_file "Tools/inductive_set.ML" 
31723
f5cafe803b55
discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents:
31667
diff
changeset

1174 
setup Inductive_Set.setup 
24699
c6674504103f
datatype interpretators for size and datatype_realizer
haftmann
parents:
24286
diff
changeset

1175 

37166  1176 

1177 
subsection {* Legacy theorem bindings and duplicates *} 

1178 

1179 
lemma PairE: 

1180 
obtains x y where "p = (x, y)" 

1181 
by (fact prod.exhaust) 

1182 

1183 
lemmas Pair_eq = prod.inject 

1184 

1185 
lemmas split = split_conv  {* for backwards compatibility *} 

1186 

44066
d74182c93f04
rename Pair_fst_snd_eq to prod_eq_iff (keeping old name too)
huffman
parents:
43866
diff
changeset

1187 
lemmas Pair_fst_snd_eq = prod_eq_iff 
d74182c93f04
rename Pair_fst_snd_eq to prod_eq_iff (keeping old name too)
huffman
parents:
43866
diff
changeset

1188 

45204
5e4a1270c000
hide typedefgenerated constants Product_Type.prod and Sum_Type.sum
huffman
parents:
44921
diff
changeset

1189 
hide_const (open) prod 
5e4a1270c000
hide typedefgenerated constants Product_Type.prod and Sum_Type.sum
huffman
parents:
44921
diff
changeset

1190 

10213  1191 
end 