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