|
1 (* Title: HOL/BNF/Examples/Misc_Data.thy |
|
2 Author: Dmitriy Traytel, TU Muenchen |
|
3 Author: Andrei Popescu, TU Muenchen |
|
4 Copyright 2012 |
|
5 |
|
6 Miscellaneous datatype declarations. |
|
7 *) |
|
8 |
|
9 header {* Miscellaneous Datatype Declarations *} |
|
10 |
|
11 theory Misc_Data |
|
12 imports "../BNF" |
|
13 begin |
|
14 |
|
15 data simple = X1 | X2 | X3 | X4 |
|
16 |
|
17 data simple' = X1' unit | X2' unit | X3' unit | X4' unit |
|
18 |
|
19 data 'a mylist = MyNil | MyCons 'a "'a mylist" |
|
20 |
|
21 data ('b, 'c, 'd, 'e) some_passive = |
|
22 SP1 "('b, 'c, 'd, 'e) some_passive" | SP2 'b | SP3 'c | SP4 'd | SP5 'e |
|
23 |
|
24 data lambda = |
|
25 Var string | |
|
26 App lambda lambda | |
|
27 Abs string lambda | |
|
28 Let "(string \<times> lambda) fset" lambda |
|
29 |
|
30 data 'a par_lambda = |
|
31 PVar 'a | |
|
32 PApp "'a par_lambda" "'a par_lambda" | |
|
33 PAbs 'a "'a par_lambda" | |
|
34 PLet "('a \<times> 'a par_lambda) fset" "'a par_lambda" |
|
35 |
|
36 (* |
|
37 ('a, 'b1, 'b2) F1 = 'a * 'b1 + 'a * 'b2 |
|
38 ('a, 'b1, 'b2) F2 = unit + 'b1 * 'b2 |
|
39 *) |
|
40 |
|
41 data 'a I1 = I11 'a "'a I1" | I12 'a "'a I2" |
|
42 and 'a I2 = I21 | I22 "'a I1" "'a I2" |
|
43 |
|
44 data 'a tree = TEmpty | TNode 'a "'a forest" |
|
45 and 'a forest = FNil | FCons "'a tree" "'a forest" |
|
46 |
|
47 data 'a tree' = TEmpty' | TNode' "'a branch" "'a branch" |
|
48 and 'a branch = Branch 'a "'a tree'" |
|
49 |
|
50 data ('a, 'b) exp = Term "('a, 'b) trm" | Sum "('a, 'b) trm" "('a, 'b) exp" |
|
51 and ('a, 'b) trm = Factor "('a, 'b) factor" | Prod "('a, 'b) factor" "('a, 'b) trm" |
|
52 and ('a, 'b) factor = C 'a | V 'b | Paren "('a, 'b) exp" |
|
53 |
|
54 data ('a, 'b, 'c) some_killing = |
|
55 SK "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b, 'c) some_killing + ('a, 'b, 'c) in_here" |
|
56 and ('a, 'b, 'c) in_here = |
|
57 IH1 'b 'a | IH2 'c |
|
58 |
|
59 data 'b nofail1 = NF11 "'b nofail1" 'b | NF12 'b |
|
60 data 'b nofail2 = NF2 "('b nofail2 \<times> 'b \<times> 'b nofail2 \<times> 'b) list" |
|
61 data 'b nofail3 = NF3 'b "('b nofail3 \<times> 'b \<times> 'b nofail3 \<times> 'b) fset" |
|
62 data 'b nofail4 = NF4 "('b nofail4 \<times> ('b nofail4 \<times> 'b \<times> 'b nofail4 \<times> 'b) fset) list" |
|
63 |
|
64 (* |
|
65 data 'b fail = F "'b fail" 'b "'b fail" "'b list" |
|
66 data 'b fail = F "'b fail" 'b "'b fail" 'b |
|
67 data 'b fail = F1 "'b fail" 'b | F2 "'b fail" |
|
68 data 'b fail = F "'b fail" 'b |
|
69 *) |
|
70 |
|
71 data l1 = L1 "l2 list" |
|
72 and l2 = L21 "l1 fset" | L22 l2 |
|
73 |
|
74 data kk1 = KK1 kk2 |
|
75 and kk2 = KK2 kk3 |
|
76 and kk3 = KK3 "kk1 list" |
|
77 |
|
78 data t1 = T11 t3 | T12 t2 |
|
79 and t2 = T2 t1 |
|
80 and t3 = T3 |
|
81 |
|
82 data t1' = T11' t2' | T12' t3' |
|
83 and t2' = T2' t1' |
|
84 and t3' = T3' |
|
85 |
|
86 (* |
|
87 data fail1 = F1 fail2 |
|
88 and fail2 = F2 fail3 |
|
89 and fail3 = F3 fail1 |
|
90 |
|
91 data fail1 = F1 "fail2 list" fail2 |
|
92 and fail2 = F2 "fail2 fset" fail3 |
|
93 and fail3 = F3 fail1 |
|
94 |
|
95 data fail1 = F1 "fail2 list" fail2 |
|
96 and fail2 = F2 "fail1 fset" fail1 |
|
97 *) |
|
98 |
|
99 (* SLOW |
|
100 data ('a, 'c) D1 = A1 "('a, 'c) D2" | B1 "'a list" |
|
101 and ('a, 'c) D2 = A2 "('a, 'c) D3" | B2 "'c list" |
|
102 and ('a, 'c) D3 = A3 "('a, 'c) D3" | B3 "('a, 'c) D4" | C3 "('a, 'c) D4" "('a, 'c) D5" |
|
103 and ('a, 'c) D4 = A4 "('a, 'c) D5" | B4 "'a list list list" |
|
104 and ('a, 'c) D5 = A5 "('a, 'c) D6" |
|
105 and ('a, 'c) D6 = A6 "('a, 'c) D7" |
|
106 and ('a, 'c) D7 = A7 "('a, 'c) D8" |
|
107 and ('a, 'c) D8 = A8 "('a, 'c) D1 list" |
|
108 |
|
109 (*time comparison*) |
|
110 datatype ('a, 'c) D1' = A1' "('a, 'c) D2'" | B1' "'a list" |
|
111 and ('a, 'c) D2' = A2' "('a, 'c) D3'" | B2' "'c list" |
|
112 and ('a, 'c) D3' = A3' "('a, 'c) D3'" | B3' "('a, 'c) D4'" | C3' "('a, 'c) D4'" "('a, 'c) D5'" |
|
113 and ('a, 'c) D4' = A4' "('a, 'c) D5'" | B4' "'a list list list" |
|
114 and ('a, 'c) D5' = A5' "('a, 'c) D6'" |
|
115 and ('a, 'c) D6' = A6' "('a, 'c) D7'" |
|
116 and ('a, 'c) D7' = A7' "('a, 'c) D8'" |
|
117 and ('a, 'c) D8' = A8' "('a, 'c) D1' list" |
|
118 *) |
|
119 |
|
120 (* fail: |
|
121 data tt1 = TT11 tt2 tt3 | TT12 tt2 tt4 |
|
122 and tt2 = TT2 |
|
123 and tt3 = TT3 tt4 |
|
124 and tt4 = TT4 tt1 |
|
125 *) |
|
126 |
|
127 data k1 = K11 k2 k3 | K12 k2 k4 |
|
128 and k2 = K2 |
|
129 and k3 = K3 k4 |
|
130 and k4 = K4 |
|
131 |
|
132 data tt1 = TT11 tt3 tt2 | TT12 tt2 tt4 |
|
133 and tt2 = TT2 |
|
134 and tt3 = TT3 tt1 |
|
135 and tt4 = TT4 |
|
136 |
|
137 (* SLOW |
|
138 data s1 = S11 s2 s3 s4 | S12 s3 | S13 s2 s6 | S14 s4 s2 | S15 s2 s2 |
|
139 and s2 = S21 s7 s5 | S22 s5 s4 s6 |
|
140 and s3 = S31 s1 s7 s2 | S32 s3 s3 | S33 s4 s5 |
|
141 and s4 = S4 s5 |
|
142 and s5 = S5 |
|
143 and s6 = S61 s6 | S62 s1 s2 | S63 s6 |
|
144 and s7 = S71 s8 | S72 s5 |
|
145 and s8 = S8 nat |
|
146 *) |
|
147 |
|
148 data ('a, 'b) bar = Bar "'b \<Rightarrow> 'a" |
|
149 data ('a, 'b, 'c, 'd) foo = Foo "'d + 'b \<Rightarrow> 'c + 'a" |
|
150 |
|
151 data 'a dead_foo = A |
|
152 data ('a, 'b) use_dead_foo = Y "'a" "'b dead_foo" |
|
153 |
|
154 end |