author | paulson |
Fri, 19 Sep 1997 16:12:21 +0200 | |
changeset 3685 | 5b8c0c8f576e |
parent 3615 | e5322197cfea |
child 3768 | 67f4ac759100 |
permissions | -rw-r--r-- |
923 | 1 |
(* Title: HOL/datatype.ML |
2 |
ID: $Id$ |
|
1668 | 3 |
Author: Max Breitling, Carsten Clasohm, Tobias Nipkow, Norbert Voelker, |
4 |
Konrad Slind |
|
923 | 5 |
Copyright 1995 TU Muenchen |
6 |
*) |
|
7 |
||
3615
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
8 |
(** Information about datatypes **) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
9 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
10 |
(* Retrieve information for a specific datatype *) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
11 |
fun datatype_info thy tname = |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
12 |
case get_thydata (thyname_of_sign (sign_of thy)) "datatypes" of |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
13 |
None => None |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
14 |
| Some (DT_DATA ds) => assoc (ds, tname); |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
15 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
16 |
fun match_info thy tname = |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
17 |
case datatype_info thy tname of |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
18 |
Some {case_const, constructors, ...} => |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
19 |
{case_const=case_const, constructors=constructors} |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
20 |
| None => error ("No datatype \"" ^ tname ^ "\" defined in this theory."); |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
21 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
22 |
fun induct_info thy tname = |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
23 |
case datatype_info thy tname of |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
24 |
Some {constructors, nchotomy, ...} => |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
25 |
{constructors=constructors, nchotomy=nchotomy} |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
26 |
| None => error ("No datatype \"" ^ tname ^ "\" defined in this theory."); |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
27 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
28 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
29 |
(* Retrieve information for all datatypes defined in a theory and its |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
30 |
ancestors *) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
31 |
fun extract_info thy = |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
32 |
let val (congs, rewrites) = |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
33 |
case get_thydata (thyname_of_sign (sign_of thy)) "datatypes" of |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
34 |
None => ([], []) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
35 |
| Some (DT_DATA ds) => |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
36 |
let val info = map snd ds |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
37 |
in (map #case_cong info, flat (map #case_rewrites info)) end; |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
38 |
in {case_congs = congs, case_rewrites = rewrites} end; |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
39 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
40 |
local |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
41 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
42 |
fun find_tname var Bi = |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
43 |
let val frees = map dest_Free (term_frees Bi) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
44 |
val params = Logic.strip_params Bi; |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
45 |
in case assoc (frees@params, var) of |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
46 |
None => error("No such variable in subgoal: " ^ quote var) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
47 |
| Some(Type(tn,_)) => tn |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
48 |
| _ => error("Cannot induct on type of " ^ quote var) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
49 |
end; |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
50 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
51 |
fun get_dt_info sign tn = |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
52 |
case get_thydata (thyname_of_sign sign) "datatypes" of |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
53 |
None => error ("No such datatype: " ^ quote tn) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
54 |
| Some (DT_DATA ds) => |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
55 |
case assoc (ds, tn) of |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
56 |
Some info => info |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
57 |
| None => error ("Not a datatype: " ^ quote tn) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
58 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
59 |
fun infer_tname state sign i aterm = |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
60 |
let val (_, _, Bi, _) = dest_state (state, i) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
61 |
val params = Logic.strip_params Bi (*params of subgoal i*) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
62 |
val params = rev(rename_wrt_term Bi params) (*as they are printed*) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
63 |
val (types,sorts) = types_sorts state |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
64 |
fun types'(a,~1) = (case assoc(params,a) of None => types(a,~1) | sm => sm) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
65 |
| types'(ixn) = types ixn; |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
66 |
val (ct,_) = read_def_cterm (sign,types',sorts) [] false |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
67 |
(aterm,TVar(("",0),[])); |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
68 |
in case #T(rep_cterm ct) of |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
69 |
Type(tn,_) => tn |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
70 |
| _ => error("Cannot induct on type of " ^ quote aterm) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
71 |
end; |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
72 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
73 |
in |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
74 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
75 |
(* generic induction tactic for datatypes *) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
76 |
fun induct_tac var i state = state |> |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
77 |
let val (_, _, Bi, _) = dest_state (state, i) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
78 |
val sign = #sign(rep_thm state) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
79 |
val tn = find_tname var Bi |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
80 |
val ind_tac = #induct_tac(get_dt_info sign tn) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
81 |
in ind_tac var i end; |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
82 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
83 |
(* generic exhaustion tactic for datatypes *) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
84 |
fun exhaust_tac aterm i state = state |> |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
85 |
let val sign = #sign(rep_thm state) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
86 |
val tn = infer_tname state sign i aterm |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
87 |
val exh_tac = #exhaust_tac(get_dt_info sign tn) |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
88 |
in exh_tac aterm i end; |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
89 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
90 |
end; |
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
91 |
|
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3564
diff
changeset
|
92 |
|
3292 | 93 |
(* should go into Pure *) |
3538 | 94 |
fun ALLNEWSUBGOALS tac tacf i st0 = st0 |> |
95 |
(tac i THEN |
|
96 |
(fn st1 => st1 |> |
|
97 |
let val d = nprems_of st1 - nprems_of st0 |
|
98 |
in EVERY(map tacf ((i+d) downto i)) end)); |
|
923 | 99 |
|
100 |
(*used for constructor parameters*) |
|
101 |
datatype dt_type = dtVar of string | |
|
102 |
dtTyp of dt_type list * string | |
|
103 |
dtRek of dt_type list * string; |
|
104 |
||
105 |
structure Datatype = |
|
106 |
struct |
|
107 |
local |
|
108 |
||
109 |
val mysort = sort; |
|
110 |
open ThyParse HOLogic; |
|
111 |
exception Impossible; |
|
112 |
exception RecError of string; |
|
113 |
||
114 |
val is_dtRek = (fn dtRek _ => true | _ => false); |
|
115 |
fun opt_parens s = if s = "" then "" else enclose "(" ")" s; |
|
116 |
||
117 |
(* ----------------------------------------------------------------------- *) |
|
118 |
(* Derivation of the primrec combinator application from the equations *) |
|
119 |
||
120 |
(* substitute fname(ls,xk,rs) by yk(ls,rs) in t for (xk,yk) in pairs *) |
|
121 |
||
122 |
fun subst_apps (_,_) [] t = t |
|
123 |
| subst_apps (fname,rpos) pairs t = |
|
124 |
let |
|
125 |
fun subst (Abs(a,T,t)) = Abs(a,T,subst t) |
|
126 |
| subst (funct $ body) = |
|
1465 | 127 |
let val (f,b) = strip_comb (funct$body) |
128 |
in |
|
129 |
if is_Const f andalso fst(dest_Const f) = fname |
|
130 |
then |
|
131 |
let val (ls,rest) = (take(rpos,b), drop(rpos,b)); |
|
132 |
val (xk,rs) = (hd rest,tl rest) |
|
133 |
handle LIST _ => raise RecError "not enough arguments \ |
|
134 |
\ in recursive application on rhs" |
|
923 | 135 |
in |
1465 | 136 |
(case assoc (pairs,xk) of |
1574
5a63ab90ee8a
modified primrec so it can be used in MiniML/Type.thy
clasohm
parents:
1465
diff
changeset
|
137 |
None => list_comb(f, map subst b) |
5a63ab90ee8a
modified primrec so it can be used in MiniML/Type.thy
clasohm
parents:
1465
diff
changeset
|
138 |
| Some U => list_comb(U, map subst (ls @ rs))) |
1465 | 139 |
end |
140 |
else list_comb(f, map subst b) |
|
141 |
end |
|
923 | 142 |
| subst(t) = t |
143 |
in subst t end; |
|
144 |
||
145 |
(* abstract rhs *) |
|
146 |
||
147 |
fun abst_rec (fname,rpos,tc,ls,cargs,rs,rhs) = |
|
2270 | 148 |
let val rargs = (map #1 o |
1465 | 149 |
(filter (fn (a,T) => is_dtRek T))) (cargs ~~ tc); |
923 | 150 |
val subs = map (fn (s,T) => (s,dummyT)) |
1465 | 151 |
(rev(rename_wrt_term rhs rargs)); |
923 | 152 |
val subst_rhs = subst_apps (fname,rpos) |
1465 | 153 |
(map Free rargs ~~ map Free subs) rhs; |
923 | 154 |
in |
155 |
list_abs_free (cargs @ subs @ ls @ rs, subst_rhs) |
|
156 |
end; |
|
157 |
||
158 |
(* parsing the prim rec equations *) |
|
159 |
||
160 |
fun dest_eq ( Const("Trueprop",_) $ (Const ("op =",_) $ lhs $ rhs)) |
|
161 |
= (lhs, rhs) |
|
162 |
| dest_eq _ = raise RecError "not a proper equation"; |
|
163 |
||
164 |
fun dest_rec eq = |
|
165 |
let val (lhs,rhs) = dest_eq eq; |
|
166 |
val (name,args) = strip_comb lhs; |
|
167 |
val (ls',rest) = take_prefix is_Free args; |
|
168 |
val (middle,rs') = take_suffix is_Free rest; |
|
169 |
val rpos = length ls'; |
|
170 |
val (c,cargs') = strip_comb (hd middle) |
|
171 |
handle LIST "hd" => raise RecError "constructor missing"; |
|
172 |
val (ls,cargs,rs) = (map dest_Free ls', map dest_Free cargs' |
|
1465 | 173 |
, map dest_Free rs') |
923 | 174 |
handle TERM ("dest_Free",_) => |
1465 | 175 |
raise RecError "constructor has illegal argument in pattern"; |
923 | 176 |
in |
177 |
if length middle > 1 then |
|
178 |
raise RecError "more than one non-variable in pattern" |
|
179 |
else if not(null(findrep (map fst (ls @ rs @ cargs)))) then |
|
180 |
raise RecError "repeated variable name in pattern" |
|
1465 | 181 |
else (fst(dest_Const name) handle TERM _ => |
182 |
raise RecError "function is not declared as constant in theory" |
|
183 |
,rpos,ls,fst( dest_Const c),cargs,rs,rhs) |
|
923 | 184 |
end; |
185 |
||
186 |
(* check function specified for all constructors and sort function terms *) |
|
187 |
||
188 |
fun check_and_sort (n,its) = |
|
189 |
if length its = n |
|
190 |
then map snd (mysort (fn ((i : int,_),(j,_)) => i<j) its) |
|
191 |
else raise error "Primrec definition error:\n\ |
|
192 |
\Please give an equation for every constructor"; |
|
193 |
||
194 |
(* translate rec equations into function arguments suitable for rec comb *) |
|
195 |
(* theory parameter needed for printing error messages *) |
|
196 |
||
197 |
fun trans_recs _ _ [] = error("No primrec equations.") |
|
198 |
| trans_recs thy cs' (eq1::eqs) = |
|
199 |
let val (name1,rpos1,ls1,_,_,_,_) = dest_rec eq1 |
|
200 |
handle RecError s => |
|
1465 | 201 |
error("Primrec definition error: " ^ s ^ ":\n" |
202 |
^ " " ^ Sign.string_of_term (sign_of thy) eq1); |
|
923 | 203 |
val tcs = map (fn (_,c,T,_,_) => (c,T)) cs'; |
204 |
val cs = map fst tcs; |
|
205 |
fun trans_recs' _ [] = [] |
|
206 |
| trans_recs' cis (eq::eqs) = |
|
1465 | 207 |
let val (name,rpos,ls,c,cargs,rs,rhs) = dest_rec eq; |
208 |
val tc = assoc(tcs,c); |
|
209 |
val i = (1 + find (c,cs)) handle LIST "find" => 0; |
|
210 |
in |
|
211 |
if name <> name1 then |
|
212 |
raise RecError "function names inconsistent" |
|
213 |
else if rpos <> rpos1 then |
|
214 |
raise RecError "position of rec. argument inconsistent" |
|
215 |
else if i = 0 then |
|
216 |
raise RecError "illegal argument in pattern" |
|
217 |
else if i mem cis then |
|
218 |
raise RecError "constructor already occured as pattern " |
|
219 |
else (i,abst_rec (name,rpos,the tc,ls,cargs,rs,rhs)) |
|
220 |
:: trans_recs' (i::cis) eqs |
|
221 |
end |
|
222 |
handle RecError s => |
|
223 |
error("Primrec definition error\n" ^ s ^ "\n" |
|
224 |
^ " " ^ Sign.string_of_term (sign_of thy) eq); |
|
923 | 225 |
in ( name1, ls1 |
1465 | 226 |
, check_and_sort (length cs, trans_recs' [] (eq1::eqs))) |
923 | 227 |
end ; |
228 |
||
229 |
in |
|
230 |
fun add_datatype (typevars, tname, cons_list') thy = |
|
231 |
let |
|
3308
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
232 |
val dummy = require_thy thy "Arith" "datatype definitions"; |
2880 | 233 |
|
923 | 234 |
fun typid(dtRek(_,id)) = id |
235 |
| typid(dtVar s) = implode (tl (explode s)) |
|
236 |
| typid(dtTyp(_,id)) = id; |
|
237 |
||
238 |
fun index_vnames(vn::vns,tab) = |
|
239 |
(case assoc(tab,vn) of |
|
240 |
None => if vn mem vns |
|
241 |
then (vn^"1") :: index_vnames(vns,(vn,2)::tab) |
|
242 |
else vn :: index_vnames(vns,tab) |
|
243 |
| Some(i) => (vn^(string_of_int i)) :: |
|
244 |
index_vnames(vns,(vn,i+1)::tab)) |
|
245 |
| index_vnames([],tab) = []; |
|
246 |
||
247 |
fun mk_var_names types = index_vnames(map typid types,[]); |
|
248 |
||
249 |
(*search for free type variables and convert recursive *) |
|
250 |
fun analyse_types (cons, types, syn) = |
|
1465 | 251 |
let fun analyse(t as dtVar v) = |
923 | 252 |
if t mem typevars then t |
253 |
else error ("Free type variable " ^ v ^ " on rhs.") |
|
1465 | 254 |
| analyse(dtTyp(typl,s)) = |
255 |
if tname <> s then dtTyp(analyses typl, s) |
|
923 | 256 |
else if typevars = typl then dtRek(typl, s) |
257 |
else error (s ^ " used in different ways") |
|
1465 | 258 |
| analyse(dtRek _) = raise Impossible |
259 |
and analyses ts = map analyse ts; |
|
260 |
in (cons, Syntax.const_name cons syn, analyses types, |
|
923 | 261 |
mk_var_names types, syn) |
262 |
end; |
|
263 |
||
264 |
(*test if all elements are recursive, i.e. if the type is empty*) |
|
265 |
||
266 |
fun non_empty (cs : ('a * 'b * dt_type list * 'c *'d) list) = |
|
1465 | 267 |
not(forall (exists is_dtRek o #3) cs) orelse |
268 |
error("Empty datatype not allowed!"); |
|
923 | 269 |
|
270 |
val cons_list = map analyse_types cons_list'; |
|
271 |
val dummy = non_empty cons_list; |
|
272 |
val num_of_cons = length cons_list; |
|
273 |
||
274 |
(* Auxiliary functions to construct argument and equation lists *) |
|
275 |
||
276 |
(*generate 'var_n, ..., var_m'*) |
|
277 |
fun Args(var, delim, n, m) = |
|
1465 | 278 |
space_implode delim (map (fn n => var^string_of_int(n)) (n upto m)); |
923 | 279 |
|
280 |
fun C_exp name vns = name ^ opt_parens(space_implode ") (" vns); |
|
281 |
||
282 |
(*Arg_eqs([x1,...,xn],[y1,...,yn]) = "x1 = y1 & ... & xn = yn" *) |
|
283 |
fun arg_eqs vns vns' = |
|
284 |
let fun mkeq(x,x') = x ^ "=" ^ x' |
|
2270 | 285 |
in space_implode " & " (ListPair.map mkeq (vns,vns')) end; |
923 | 286 |
|
287 |
(*Pretty printers for type lists; |
|
288 |
pp_typlist1: parentheses, pp_typlist2: brackets*) |
|
1279
f59b4f9f2cdc
All constants introduced by datatype now operate on class term explicitly.
nipkow
parents:
980
diff
changeset
|
289 |
fun pp_typ (dtVar s) = "(" ^ s ^ "::term)" |
923 | 290 |
| pp_typ (dtTyp (typvars, id)) = |
1465 | 291 |
if null typvars then id else (pp_typlist1 typvars) ^ id |
923 | 292 |
| pp_typ (dtRek (typvars, id)) = (pp_typlist1 typvars) ^ id |
293 |
and |
|
1465 | 294 |
pp_typlist' ts = commas (map pp_typ ts) |
923 | 295 |
and |
1465 | 296 |
pp_typlist1 ts = if null ts then "" else parens (pp_typlist' ts); |
923 | 297 |
|
298 |
fun pp_typlist2 ts = if null ts then "" else brackets (pp_typlist' ts); |
|
299 |
||
300 |
(* Generate syntax translation for case rules *) |
|
301 |
fun calc_xrules c_nr y_nr ((_, name, _, vns, _) :: cs) = |
|
1465 | 302 |
let val arity = length vns; |
303 |
val body = "z" ^ string_of_int(c_nr); |
|
304 |
val args1 = if arity=0 then "" |
|
305 |
else " " ^ Args ("y", " ", y_nr, y_nr+arity-1); |
|
306 |
val args2 = if arity=0 then "" |
|
307 |
else "(% " ^ Args ("y", " ", y_nr, y_nr+arity-1) |
|
308 |
^ ". "; |
|
309 |
val (rest1,rest2) = |
|
310 |
if null cs then ("","") |
|
311 |
else let val (h1, h2) = calc_xrules (c_nr+1) (y_nr+arity) cs |
|
312 |
in (" | " ^ h1, " " ^ h2) end; |
|
313 |
in (name ^ args1 ^ " => " ^ body ^ rest1, |
|
964 | 314 |
args2 ^ body ^ (if args2 = "" then "" else ")") ^ rest2) |
923 | 315 |
end |
316 |
| calc_xrules _ _ [] = raise Impossible; |
|
317 |
||
318 |
val xrules = |
|
1465 | 319 |
let val (first_part, scnd_part) = calc_xrules 1 1 cons_list |
3534 | 320 |
in [Syntax.ParsePrintRule (("logic", "case x of " ^ first_part), |
2031 | 321 |
("logic", tname ^ "_case " ^ scnd_part ^ " x"))] |
1465 | 322 |
end; |
923 | 323 |
|
324 |
(*type declarations for constructors*) |
|
325 |
fun const_type (id, _, typlist, _, syn) = |
|
1465 | 326 |
(id, |
327 |
(if null typlist then "" else pp_typlist2 typlist ^ " => ") ^ |
|
328 |
pp_typlist1 typevars ^ tname, syn); |
|
923 | 329 |
|
330 |
||
331 |
fun assumpt (dtRek _ :: ts, v :: vs ,found) = |
|
1465 | 332 |
let val h = if found then ";P(" ^ v ^ ")" else "[| P(" ^ v ^ ")" |
333 |
in h ^ (assumpt (ts, vs, true)) end |
|
923 | 334 |
| assumpt (t :: ts, v :: vs, found) = assumpt (ts, vs, found) |
335 |
| assumpt ([], [], found) = if found then "|] ==>" else "" |
|
336 |
| assumpt _ = raise Impossible; |
|
337 |
||
338 |
fun t_inducting ((_, name, types, vns, _) :: cs) = |
|
1465 | 339 |
let |
340 |
val h = if null types then " P(" ^ name ^ ")" |
|
341 |
else " !!" ^ (space_implode " " vns) ^ "." ^ |
|
342 |
(assumpt (types, vns, false)) ^ |
|
923 | 343 |
"P(" ^ C_exp name vns ^ ")"; |
1465 | 344 |
val rest = t_inducting cs; |
345 |
in if rest = "" then h else h ^ "; " ^ rest end |
|
923 | 346 |
| t_inducting [] = ""; |
347 |
||
348 |
fun t_induct cl typ_name = |
|
349 |
"[|" ^ t_inducting cl ^ "|] ==> P(" ^ typ_name ^ ")"; |
|
350 |
||
351 |
fun gen_typlist typevar f ((_, _, ts, _, _) :: cs) = |
|
1465 | 352 |
let val h = if (length ts) > 0 |
353 |
then pp_typlist2(f ts) ^ "=>" |
|
354 |
else "" |
|
355 |
in h ^ typevar ^ "," ^ (gen_typlist typevar f cs) end |
|
923 | 356 |
| gen_typlist _ _ [] = ""; |
357 |
||
358 |
||
359 |
(* -------------------------------------------------------------------- *) |
|
1465 | 360 |
(* The case constant and rules *) |
361 |
||
923 | 362 |
val t_case = tname ^ "_case"; |
363 |
||
364 |
fun case_rule n (id, name, _, vns, _) = |
|
1465 | 365 |
let val args = if vns = [] then "" else " " ^ space_implode " " vns |
366 |
in (t_case ^ "_" ^ id, |
|
367 |
t_case ^ " " ^ Args("f", " ", 1, num_of_cons) |
|
368 |
^ " (" ^ name ^ args ^ ") = f"^string_of_int(n) ^ args) |
|
369 |
end |
|
923 | 370 |
|
371 |
fun case_rules n (c :: cs) = case_rule n c :: case_rules(n+1) cs |
|
372 |
| case_rules _ [] = []; |
|
373 |
||
374 |
val datatype_arity = length typevars; |
|
375 |
||
376 |
val types = [(tname, datatype_arity, NoSyn)]; |
|
377 |
||
378 |
val arities = |
|
379 |
let val term_list = replicate datatype_arity termS; |
|
380 |
in [(tname, term_list, termS)] |
|
1465 | 381 |
end; |
923 | 382 |
|
383 |
val datatype_name = pp_typlist1 typevars ^ tname; |
|
384 |
||
385 |
val new_tvar_name = variant (map (fn dtVar s => s) typevars) "'z"; |
|
386 |
||
387 |
val case_const = |
|
1465 | 388 |
(t_case, |
389 |
"[" ^ gen_typlist new_tvar_name I cons_list |
|
390 |
^ pp_typlist1 typevars ^ tname ^ "] =>" ^ new_tvar_name^"::term", |
|
391 |
NoSyn); |
|
923 | 392 |
|
393 |
val rules_case = case_rules 1 cons_list; |
|
394 |
||
395 |
(* -------------------------------------------------------------------- *) |
|
1465 | 396 |
(* The prim-rec combinator *) |
923 | 397 |
|
398 |
val t_rec = tname ^ "_rec" |
|
399 |
||
400 |
(* adding type variables for dtRek types to end of list of dt_types *) |
|
401 |
||
402 |
fun add_reks ts = |
|
1465 | 403 |
ts @ map (fn _ => dtVar new_tvar_name) (filter is_dtRek ts); |
923 | 404 |
|
405 |
(* positions of the dtRek types in a list of dt_types, starting from 1 *) |
|
2270 | 406 |
fun rek_vars ts vns = map #2 (filter (is_dtRek o fst) (ts ~~ vns)) |
923 | 407 |
|
408 |
fun rec_rule n (id,name,ts,vns,_) = |
|
1465 | 409 |
let val args = opt_parens(space_implode ") (" vns) |
410 |
val fargs = opt_parens(Args("f", ") (", 1, num_of_cons)) |
|
411 |
fun rarg vn = t_rec ^ fargs ^ " (" ^ vn ^ ")" |
|
412 |
val rargs = opt_parens(space_implode ") (" |
|
964 | 413 |
(map rarg (rek_vars ts vns))) |
1465 | 414 |
in |
415 |
(t_rec ^ "_" ^ id, |
|
416 |
t_rec ^ fargs ^ " (" ^ name ^ args ^ ") = f" |
|
417 |
^ string_of_int(n) ^ args ^ rargs) |
|
418 |
end |
|
923 | 419 |
|
420 |
fun rec_rules n (c::cs) = rec_rule n c :: rec_rules (n+1) cs |
|
1465 | 421 |
| rec_rules _ [] = []; |
923 | 422 |
|
423 |
val rec_const = |
|
1465 | 424 |
(t_rec, |
425 |
"[" ^ (gen_typlist new_tvar_name add_reks cons_list) |
|
426 |
^ (pp_typlist1 typevars) ^ tname ^ "] =>" ^ new_tvar_name^"::term", |
|
427 |
NoSyn); |
|
923 | 428 |
|
429 |
val rules_rec = rec_rules 1 cons_list |
|
430 |
||
431 |
(* -------------------------------------------------------------------- *) |
|
3308
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
432 |
(* The size function *) |
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
433 |
|
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
434 |
fun size_eqn(_,name,types,vns,_) = |
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
435 |
let fun sum((T,vn)::args) = |
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
436 |
if is_dtRek T then "size(" ^ vn ^ ") + " ^ sum(args) |
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
437 |
else sum args |
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
438 |
| sum [] = "1" |
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
439 |
val rhs = if exists is_dtRek types then sum(types~~vns) else "0" |
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
440 |
in ("", "size(" ^ C_exp name vns ^ ") = " ^ rhs) end; |
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
441 |
|
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
442 |
val size_eqns = map size_eqn cons_list; |
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
443 |
|
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
444 |
(* -------------------------------------------------------------------- *) |
923 | 445 |
val consts = |
1465 | 446 |
map const_type cons_list |
447 |
@ (if num_of_cons < dtK then [] |
|
448 |
else [(tname ^ "_ord", datatype_name ^ "=>nat", NoSyn)]) |
|
449 |
@ [case_const,rec_const]; |
|
923 | 450 |
|
451 |
||
452 |
fun Ci_ing ((id, name, _, vns, _) :: cs) = |
|
1465 | 453 |
if null vns then Ci_ing cs |
454 |
else let val vns' = variantlist(vns,vns) |
|
923 | 455 |
in ("inject_" ^ id, |
1465 | 456 |
"(" ^ (C_exp name vns) ^ "=" ^ (C_exp name vns') |
457 |
^ ") = (" ^ (arg_eqs vns vns') ^ ")") :: (Ci_ing cs) |
|
923 | 458 |
end |
1465 | 459 |
| Ci_ing [] = []; |
923 | 460 |
|
461 |
fun Ci_negOne (id1,name1,_,vns1,_) (id2,name2,_,vns2,_) = |
|
462 |
let val vns2' = variantlist(vns2,vns1) |
|
463 |
val ax = C_exp name1 vns1 ^ "~=" ^ C_exp name2 vns2' |
|
1465 | 464 |
in (id1 ^ "_not_" ^ id2, ax) end; |
923 | 465 |
|
466 |
fun Ci_neg1 [] = [] |
|
1465 | 467 |
| Ci_neg1 (c1::cs) = (map (Ci_negOne c1) cs) @ Ci_neg1 cs; |
923 | 468 |
|
469 |
fun suc_expr n = |
|
1465 | 470 |
if n=0 then "0" else "Suc(" ^ suc_expr(n-1) ^ ")"; |
923 | 471 |
|
472 |
fun Ci_neg2() = |
|
1465 | 473 |
let val ord_t = tname ^ "_ord"; |
2270 | 474 |
val cis = ListPair.zip (cons_list, 0 upto (num_of_cons - 1)) |
1465 | 475 |
fun Ci_neg2equals ((id, name, _, vns, _), n) = |
476 |
let val ax = ord_t ^ "(" ^ (C_exp name vns) ^ ") = " ^ (suc_expr n) |
|
477 |
in (ord_t ^ "_" ^ id, ax) end |
|
478 |
in (ord_t ^ "_distinct", ord_t^"(x) ~= "^ord_t^"(y) ==> x ~= y") :: |
|
479 |
(map Ci_neg2equals cis) |
|
480 |
end; |
|
923 | 481 |
|
482 |
val rules_distinct = if num_of_cons < dtK then Ci_neg1 cons_list |
|
1465 | 483 |
else Ci_neg2(); |
923 | 484 |
|
485 |
val rules_inject = Ci_ing cons_list; |
|
486 |
||
487 |
val rule_induct = (tname ^ "_induct", t_induct cons_list tname); |
|
488 |
||
489 |
val rules = rule_induct :: |
|
1465 | 490 |
(rules_inject @ rules_distinct @ rules_case @ rules_rec); |
923 | 491 |
|
492 |
fun add_primrec eqns thy = |
|
1465 | 493 |
let val rec_comb = Const(t_rec,dummyT) |
494 |
val teqns = map (fn neq => snd(read_axm (sign_of thy) neq)) eqns |
|
495 |
val (fname,ls,fns) = trans_recs thy cons_list teqns |
|
496 |
val rhs = |
|
497 |
list_abs_free |
|
498 |
(ls @ [(tname,dummyT)] |
|
499 |
,list_comb(rec_comb |
|
500 |
, fns @ map Bound (0 ::(length ls downto 1)))); |
|
923 | 501 |
val sg = sign_of thy; |
1574
5a63ab90ee8a
modified primrec so it can be used in MiniML/Type.thy
clasohm
parents:
1465
diff
changeset
|
502 |
val defpair = (fname ^ "_" ^ tname ^ "_def", |
5a63ab90ee8a
modified primrec so it can be used in MiniML/Type.thy
clasohm
parents:
1465
diff
changeset
|
503 |
Logic.mk_equals (Const(fname,dummyT), rhs)) |
1465 | 504 |
val defpairT as (_, _ $ Const(_,T) $ _ ) = inferT_axm sg defpair; |
505 |
val varT = Type.varifyT T; |
|
923 | 506 |
val ftyp = the (Sign.const_type sg fname); |
1574
5a63ab90ee8a
modified primrec so it can be used in MiniML/Type.thy
clasohm
parents:
1465
diff
changeset
|
507 |
in add_defs_i [defpairT] thy end; |
923 | 508 |
|
1360 | 509 |
in |
510 |
(thy |> add_types types |
|
511 |
|> add_arities arities |
|
512 |
|> add_consts consts |
|
513 |
|> add_trrules xrules |
|
3308
da002cef7090
Added overloaded function `size' for all datatypes.
nipkow
parents:
3292
diff
changeset
|
514 |
|> add_axioms rules, add_primrec, size_eqns) |
923 | 515 |
end |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
2880
diff
changeset
|
516 |
|
3564
f886dbd91ee5
Now Datatype.occs_in_prems prints the necessary warning ITSELF.
paulson
parents:
3538
diff
changeset
|
517 |
(*Warn if the (induction) variable occurs Free among the premises, which |
f886dbd91ee5
Now Datatype.occs_in_prems prints the necessary warning ITSELF.
paulson
parents:
3538
diff
changeset
|
518 |
usually signals a mistake. But calls the tactic either way!*) |
f886dbd91ee5
Now Datatype.occs_in_prems prints the necessary warning ITSELF.
paulson
parents:
3538
diff
changeset
|
519 |
fun occs_in_prems tacf a = |
f886dbd91ee5
Now Datatype.occs_in_prems prints the necessary warning ITSELF.
paulson
parents:
3538
diff
changeset
|
520 |
SUBGOAL (fn (Bi,i) => |
f886dbd91ee5
Now Datatype.occs_in_prems prints the necessary warning ITSELF.
paulson
parents:
3538
diff
changeset
|
521 |
(if exists (fn Free(a',_) => a=a') |
f886dbd91ee5
Now Datatype.occs_in_prems prints the necessary warning ITSELF.
paulson
parents:
3538
diff
changeset
|
522 |
(foldr add_term_frees (#2 (strip_context Bi), [])) |
f886dbd91ee5
Now Datatype.occs_in_prems prints the necessary warning ITSELF.
paulson
parents:
3538
diff
changeset
|
523 |
then warning "Induction variable occurs also among premises!" |
f886dbd91ee5
Now Datatype.occs_in_prems prints the necessary warning ITSELF.
paulson
parents:
3538
diff
changeset
|
524 |
else (); |
f886dbd91ee5
Now Datatype.occs_in_prems prints the necessary warning ITSELF.
paulson
parents:
3538
diff
changeset
|
525 |
tacf a i)); |
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
2880
diff
changeset
|
526 |
|
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
2880
diff
changeset
|
527 |
end; |
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
2880
diff
changeset
|
528 |
|
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
2880
diff
changeset
|
529 |
end; |
923 | 530 |
|
531 |
(* |
|
532 |
Informal description of functions used in datatype.ML for the Isabelle/HOL |
|
533 |
implementation of prim. rec. function definitions. (N. Voelker, Feb. 1995) |
|
534 |
||
535 |
* subst_apps (fname,rpos) pairs t: |
|
536 |
substitute the term |
|
537 |
fname(ls,xk,rs) |
|
538 |
by |
|
539 |
yk(ls,rs) |
|
540 |
in t for (xk,yk) in pairs, where rpos = length ls. |
|
541 |
Applied with : |
|
542 |
fname = function name |
|
543 |
rpos = position of recursive argument |
|
544 |
pairs = list of pairs (xk,yk), where |
|
545 |
xk are the rec. arguments of the constructor in the pattern, |
|
546 |
yk is a variable with name derived from xk |
|
547 |
t = rhs of equation |
|
548 |
||
549 |
* abst_rec (fname,rpos,tc,ls,cargs,rs,rhs) |
|
550 |
- filter recursive arguments from constructor arguments cargs, |
|
551 |
- perform substitutions on rhs, |
|
552 |
- derive list subs of new variable names yk for use in subst_apps, |
|
553 |
- abstract rhs with respect to cargs, subs, ls and rs. |
|
554 |
||
555 |
* dest_eq t |
|
556 |
destruct a term denoting an equation into lhs and rhs. |
|
557 |
||
558 |
* dest_req eq |
|
559 |
destruct an equation of the form |
|
560 |
name (vl1..vlrpos, Ci(vi1..vin), vr1..vrn) = rhs |
|
561 |
into |
|
562 |
- function name (name) |
|
563 |
- position of the first non-variable parameter (rpos) |
|
564 |
- the list of first rpos parameters (ls = [vl1..vlrpos]) |
|
565 |
- the constructor (fst( dest_Const c) = Ci) |
|
566 |
- the arguments of the constructor (cargs = [vi1..vin]) |
|
567 |
- the rest of the variables in the pattern (rs = [vr1..vrn]) |
|
568 |
- the right hand side of the equation (rhs). |
|
569 |
||
570 |
* check_and_sort (n,its) |
|
571 |
check that n = length its holds, and sort elements of its by |
|
572 |
first component. |
|
573 |
||
574 |
* trans_recs thy cs' (eq1::eqs) |
|
575 |
destruct eq1 into name1, rpos1, ls1, etc.. |
|
576 |
get constructor list with and without type (tcs resp. cs) from cs', |
|
577 |
for every equation: |
|
578 |
destruct it into (name,rpos,ls,c,cargs,rs,rhs) |
|
579 |
get typed constructor tc from c and tcs |
|
580 |
determine the index i of the constructor |
|
581 |
check function name and position of rec. argument by comparison |
|
582 |
with first equation |
|
583 |
check for repeated variable names in pattern |
|
584 |
derive function term f_i which is used as argument of the rec. combinator |
|
585 |
sort the terms f_i according to i and return them together |
|
586 |
with the function name and the parameter of the definition (ls). |
|
587 |
||
588 |
* Application: |
|
589 |
||
590 |
The rec. combinator is applied to the function terms resulting from |
|
591 |
trans_rec. This results in a function which takes the recursive arg. |
|
592 |
as first parameter and then the arguments corresponding to ls. The |
|
593 |
order of parameters is corrected by setting the rhs equal to |
|
594 |
||
595 |
list_abs_free |
|
1465 | 596 |
(ls @ [(tname,dummyT)] |
597 |
,list_comb(rec_comb |
|
598 |
, fns @ map Bound (0 ::(length ls downto 1)))); |
|
923 | 599 |
|
600 |
Note the de-Bruijn indices counting the number of lambdas between the |
|
601 |
variable and its binding. |
|
602 |
*) |
|
1668 | 603 |
|
604 |
||
605 |
||
606 |
(* ----------------------------------------------- *) |
|
607 |
(* The following has been written by Konrad Slind. *) |
|
608 |
||
609 |
||
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
2880
diff
changeset
|
610 |
(* type dtype_info is defined in simpdata.ML *) |
1668 | 611 |
|
612 |
signature Dtype_sig = |
|
613 |
sig |
|
614 |
val build_case_cong: Sign.sg -> thm list -> cterm |
|
615 |
val build_nchotomy: Sign.sg -> thm list -> cterm |
|
616 |
||
617 |
val prove_case_cong: thm -> thm list -> cterm -> thm |
|
1690 | 618 |
val prove_nchotomy: (string -> int -> tactic) -> cterm -> thm |
1668 | 619 |
|
620 |
val case_thms : Sign.sg -> thm list -> (string -> int -> tactic) |
|
621 |
-> {nchotomy:thm, case_cong:thm} |
|
622 |
||
623 |
val build_record : (theory * (string * string list) |
|
624 |
* (string -> int -> tactic)) |
|
625 |
-> (string * dtype_info) |
|
626 |
||
627 |
end; |
|
628 |
||
629 |
||
630 |
(*--------------------------------------------------------------------------- |
|
631 |
* This structure is support for the Isabelle datatype package. It provides |
|
632 |
* entrypoints for 1) building and proving the case congruence theorem for |
|
633 |
* a datatype and 2) building and proving the "exhaustion" theorem for |
|
634 |
* a datatype (I have called this theorem "nchotomy" for no good reason). |
|
635 |
* |
|
636 |
* It also brings all these together in the function "build_record", which |
|
637 |
* is probably what will be used. |
|
638 |
* |
|
639 |
* Since these routines are required in order to support TFL, they have |
|
640 |
* been written so they will compile "stand-alone", i.e., in Isabelle-HOL |
|
641 |
* without any TFL code around. |
|
642 |
*---------------------------------------------------------------------------*) |
|
643 |
structure Dtype : Dtype_sig = |
|
644 |
struct |
|
645 |
||
646 |
exception DTYPE_ERR of {func:string, mesg:string}; |
|
647 |
||
648 |
(*--------------------------------------------------------------------------- |
|
649 |
* General support routines |
|
650 |
*---------------------------------------------------------------------------*) |
|
651 |
fun itlist f L base_value = |
|
652 |
let fun it [] = base_value |
|
653 |
| it (a::rst) = f a (it rst) |
|
654 |
in it L |
|
655 |
end; |
|
656 |
||
657 |
fun end_itlist f = |
|
658 |
let fun endit [] = raise DTYPE_ERR{func="end_itlist", mesg="list too short"} |
|
659 |
| endit alist = |
|
660 |
let val (base::ralist) = rev alist |
|
661 |
in itlist f (rev ralist) base end |
|
662 |
in endit |
|
663 |
end; |
|
664 |
||
665 |
fun unzip L = itlist (fn (x,y) => fn (l1,l2) =>((x::l1),(y::l2))) L ([],[]); |
|
666 |
||
667 |
||
668 |
(*--------------------------------------------------------------------------- |
|
669 |
* Miscellaneous Syntax manipulation |
|
670 |
*---------------------------------------------------------------------------*) |
|
671 |
val mk_var = Free; |
|
672 |
val mk_const = Const |
|
673 |
fun mk_comb(Rator,Rand) = Rator $ Rand; |
|
674 |
fun mk_abs(r as (Var((s,_),ty),_)) = Abs(s,ty,abstract_over r) |
|
675 |
| mk_abs(r as (Free(s,ty),_)) = Abs(s,ty,abstract_over r) |
|
676 |
| mk_abs _ = raise DTYPE_ERR{func="mk_abs", mesg="1st not a variable"}; |
|
677 |
||
678 |
fun dest_var(Var((s,i),ty)) = (s,ty) |
|
679 |
| dest_var(Free(s,ty)) = (s,ty) |
|
680 |
| dest_var _ = raise DTYPE_ERR{func="dest_var", mesg="not a variable"}; |
|
681 |
||
682 |
fun dest_const(Const p) = p |
|
683 |
| dest_const _ = raise DTYPE_ERR{func="dest_const", mesg="not a constant"}; |
|
684 |
||
685 |
fun dest_comb(t1 $ t2) = (t1,t2) |
|
686 |
| dest_comb _ = raise DTYPE_ERR{func = "dest_comb", mesg = "not a comb"}; |
|
687 |
val rand = #2 o dest_comb; |
|
688 |
val rator = #1 o dest_comb; |
|
689 |
||
690 |
fun dest_abs(a as Abs(s,ty,M)) = |
|
691 |
let val v = Free(s, ty) |
|
692 |
in (v, betapply (a,v)) end |
|
693 |
| dest_abs _ = raise DTYPE_ERR{func="dest_abs", mesg="not an abstraction"}; |
|
694 |
||
695 |
||
696 |
val bool = Type("bool",[]) |
|
697 |
and prop = Type("prop",[]); |
|
698 |
||
699 |
fun mk_eq(lhs,rhs) = |
|
700 |
let val ty = type_of lhs |
|
701 |
val c = mk_const("op =", ty --> ty --> bool) |
|
702 |
in list_comb(c,[lhs,rhs]) |
|
703 |
end |
|
704 |
||
705 |
fun dest_eq(Const("op =",_) $ M $ N) = (M, N) |
|
706 |
| dest_eq _ = raise DTYPE_ERR{func="dest_eq", mesg="not an equality"}; |
|
707 |
||
708 |
fun mk_disj(disj1,disj2) = |
|
709 |
let val c = Const("op |", bool --> bool --> bool) |
|
710 |
in list_comb(c,[disj1,disj2]) |
|
711 |
end; |
|
712 |
||
713 |
fun mk_forall (r as (Bvar,_)) = |
|
714 |
let val ty = type_of Bvar |
|
715 |
val c = Const("All", (ty --> bool) --> bool) |
|
716 |
in mk_comb(c, mk_abs r) |
|
717 |
end; |
|
718 |
||
719 |
fun mk_exists (r as (Bvar,_)) = |
|
720 |
let val ty = type_of Bvar |
|
721 |
val c = Const("Ex", (ty --> bool) --> bool) |
|
722 |
in mk_comb(c, mk_abs r) |
|
723 |
end; |
|
724 |
||
725 |
fun mk_prop (tm as Const("Trueprop",_) $ _) = tm |
|
726 |
| mk_prop tm = mk_comb(Const("Trueprop", bool --> prop),tm); |
|
727 |
||
728 |
fun drop_prop (Const("Trueprop",_) $ X) = X |
|
729 |
| drop_prop X = X; |
|
730 |
||
731 |
fun mk_all (r as (Bvar,_)) = mk_comb(all (type_of Bvar), mk_abs r); |
|
732 |
fun list_mk_all(V,t) = itlist(fn v => fn b => mk_all(v,b)) V t; |
|
733 |
fun list_mk_exists(V,t) = itlist(fn v => fn b => mk_exists(v,b)) V t; |
|
734 |
val list_mk_disj = end_itlist(fn d1 => fn tm => mk_disj(d1,tm)) |
|
735 |
||
736 |
||
737 |
fun dest_thm thm = |
|
738 |
let val {prop,hyps,...} = rep_thm thm |
|
739 |
in (map drop_prop hyps, drop_prop prop) |
|
740 |
end; |
|
741 |
||
742 |
val concl = #2 o dest_thm; |
|
743 |
||
744 |
||
745 |
(*--------------------------------------------------------------------------- |
|
746 |
* Names of all variables occurring in a term, including bound ones. These |
|
747 |
* are added into the second argument. |
|
3265
8358e19d0d4c
Replaced Konrad's own add_term_names by the predefined one.
nipkow
parents:
3197
diff
changeset
|
748 |
*--------------------------------------------------------------------------- |
1668 | 749 |
fun add_term_names tm = |
750 |
let fun insert (x:string) = |
|
751 |
let fun canfind[] = [x] |
|
752 |
| canfind(alist as (y::rst)) = |
|
753 |
if (x<y) then x::alist |
|
754 |
else if (x=y) then y::rst |
|
755 |
else y::canfind rst |
|
756 |
in canfind end |
|
757 |
fun add (Free(s,_)) V = insert s V |
|
758 |
| add (Var((s,_),_)) V = insert s V |
|
759 |
| add (Abs(s,_,body)) V = add body (insert s V) |
|
760 |
| add (f$t) V = add t (add f V) |
|
761 |
| add _ V = V |
|
762 |
in add tm |
|
763 |
end; |
|
3265
8358e19d0d4c
Replaced Konrad's own add_term_names by the predefined one.
nipkow
parents:
3197
diff
changeset
|
764 |
Why bound ones??? |
8358e19d0d4c
Replaced Konrad's own add_term_names by the predefined one.
nipkow
parents:
3197
diff
changeset
|
765 |
*) |
1668 | 766 |
|
767 |
(*--------------------------------------------------------------------------- |
|
768 |
* We need to make everything free, so that we can put the term into a |
|
769 |
* goalstack, or submit it as an argument to prove_goalw_cterm. |
|
770 |
*---------------------------------------------------------------------------*) |
|
771 |
fun make_free_ty(Type(s,alist)) = Type(s,map make_free_ty alist) |
|
772 |
| make_free_ty(TVar((s,i),srt)) = TFree(s,srt) |
|
773 |
| make_free_ty x = x; |
|
774 |
||
775 |
fun make_free (Var((s,_),ty)) = Free(s,make_free_ty ty) |
|
776 |
| make_free (Abs(s,x,body)) = Abs(s,make_free_ty x, make_free body) |
|
777 |
| make_free (f$t) = (make_free f $ make_free t) |
|
778 |
| make_free (Const(s,ty)) = Const(s, make_free_ty ty) |
|
779 |
| make_free (Free(s,ty)) = Free(s, make_free_ty ty) |
|
780 |
| make_free b = b; |
|
781 |
||
782 |
||
783 |
(*--------------------------------------------------------------------------- |
|
784 |
* Structure of case congruence theorem looks like this: |
|
785 |
* |
|
786 |
* (M = M') |
|
787 |
* ==> (!!x1,...,xk. (M' = C1 x1..xk) ==> (f1 x1..xk = f1' x1..xk)) |
|
788 |
* ==> ... |
|
789 |
* ==> (!!x1,...,xj. (M' = Cn x1..xj) ==> (fn x1..xj = fn' x1..xj)) |
|
790 |
* ==> |
|
791 |
* (ty_case f1..fn M = ty_case f1'..fn' m') |
|
792 |
* |
|
793 |
* The input is the list of rules for the case construct for the type, i.e., |
|
794 |
* that found in the "ty.cases" field of a theory where datatype "ty" is |
|
795 |
* defined. |
|
796 |
*---------------------------------------------------------------------------*) |
|
797 |
||
798 |
fun build_case_cong sign case_rewrites = |
|
799 |
let val clauses = map concl case_rewrites |
|
800 |
val clause1 = hd clauses |
|
801 |
val left = (#1 o dest_eq) clause1 |
|
802 |
val ty = type_of ((#2 o dest_comb) left) |
|
3265
8358e19d0d4c
Replaced Konrad's own add_term_names by the predefined one.
nipkow
parents:
3197
diff
changeset
|
803 |
val varnames = foldr add_term_names (clauses, []) |
1668 | 804 |
val M = variant varnames "M" |
805 |
val Mvar = Free(M, ty) |
|
806 |
val M' = variant (M::varnames) M |
|
807 |
val M'var = Free(M', ty) |
|
808 |
fun mk_clause clause = |
|
809 |
let val (lhs,rhs) = dest_eq clause |
|
810 |
val func = (#1 o strip_comb) rhs |
|
811 |
val (constr,xbar) = strip_comb(rand lhs) |
|
812 |
val (Name,Ty) = dest_var func |
|
813 |
val func'name = variant (M::M'::varnames) (Name^"a") |
|
814 |
val func' = mk_var(func'name,Ty) |
|
815 |
in (func', list_mk_all |
|
816 |
(xbar, Logic.mk_implies |
|
817 |
(mk_prop(mk_eq(M'var, list_comb(constr,xbar))), |
|
818 |
mk_prop(mk_eq(list_comb(func, xbar), |
|
819 |
list_comb(func',xbar)))))) end |
|
820 |
val (funcs',clauses') = unzip (map mk_clause clauses) |
|
821 |
val lhsM = mk_comb(rator left, Mvar) |
|
822 |
val c = #1(strip_comb left) |
|
823 |
in |
|
824 |
cterm_of sign |
|
825 |
(make_free |
|
826 |
(Logic.list_implies(mk_prop(mk_eq(Mvar, M'var))::clauses', |
|
827 |
mk_prop(mk_eq(lhsM, list_comb(c,(funcs'@[M'var]))))))) |
|
828 |
end |
|
829 |
handle _ => raise DTYPE_ERR{func="build_case_cong",mesg="failed"}; |
|
830 |
||
831 |
||
832 |
(*--------------------------------------------------------------------------- |
|
833 |
* Proves the result of "build_case_cong". |
|
1897
71e51870cc9a
Replaced prove_case_cong by Konrad Slinds optimized version.
berghofe
parents:
1810
diff
changeset
|
834 |
* This one solves it a disjunct at a time, and builds the ss only once. |
1668 | 835 |
*---------------------------------------------------------------------------*) |
836 |
fun prove_case_cong nchotomy case_rewrites ctm = |
|
837 |
let val {sign,t,...} = rep_cterm ctm |
|
838 |
val (Const("==>",_) $ tm $ _) = t |
|
839 |
val (Const("Trueprop",_) $ (Const("op =",_) $ _ $ Ma)) = tm |
|
840 |
val (Free(str,_)) = Ma |
|
841 |
val thm = prove_goalw_cterm[] ctm |
|
1897
71e51870cc9a
Replaced prove_case_cong by Konrad Slinds optimized version.
berghofe
parents:
1810
diff
changeset
|
842 |
(fn prems => |
71e51870cc9a
Replaced prove_case_cong by Konrad Slinds optimized version.
berghofe
parents:
1810
diff
changeset
|
843 |
let val simplify = asm_simp_tac(HOL_ss addsimps (prems@case_rewrites)) |
71e51870cc9a
Replaced prove_case_cong by Konrad Slinds optimized version.
berghofe
parents:
1810
diff
changeset
|
844 |
in [simp_tac (HOL_ss addsimps [hd prems]) 1, |
71e51870cc9a
Replaced prove_case_cong by Konrad Slinds optimized version.
berghofe
parents:
1810
diff
changeset
|
845 |
cut_inst_tac [("x",str)] (nchotomy RS spec) 1, |
71e51870cc9a
Replaced prove_case_cong by Konrad Slinds optimized version.
berghofe
parents:
1810
diff
changeset
|
846 |
REPEAT (etac disjE 1 THEN REPEAT (etac exE 1) THEN simplify 1), |
71e51870cc9a
Replaced prove_case_cong by Konrad Slinds optimized version.
berghofe
parents:
1810
diff
changeset
|
847 |
REPEAT (etac exE 1) THEN simplify 1 (* Get last disjunct *)] |
71e51870cc9a
Replaced prove_case_cong by Konrad Slinds optimized version.
berghofe
parents:
1810
diff
changeset
|
848 |
end) |
1668 | 849 |
in standard (thm RS eq_reflection) |
850 |
end |
|
851 |
handle _ => raise DTYPE_ERR{func="prove_case_cong",mesg="failed"}; |
|
852 |
||
853 |
||
854 |
(*--------------------------------------------------------------------------- |
|
855 |
* Structure of exhaustion theorem looks like this: |
|
856 |
* |
|
857 |
* !v. (EX y1..yi. v = C1 y1..yi) | ... | (EX y1..yj. v = Cn y1..yj) |
|
858 |
* |
|
859 |
* As for "build_case_cong", the input is the list of rules for the case |
|
860 |
* construct (the case "rewrites"). |
|
861 |
*---------------------------------------------------------------------------*) |
|
862 |
fun build_nchotomy sign case_rewrites = |
|
863 |
let val clauses = map concl case_rewrites |
|
864 |
val C_ybars = map (rand o #1 o dest_eq) clauses |
|
3265
8358e19d0d4c
Replaced Konrad's own add_term_names by the predefined one.
nipkow
parents:
3197
diff
changeset
|
865 |
val varnames = foldr add_term_names (C_ybars, []) |
1668 | 866 |
val vname = variant varnames "v" |
867 |
val ty = type_of (hd C_ybars) |
|
868 |
val v = mk_var(vname,ty) |
|
869 |
fun mk_disj C_ybar = |
|
870 |
let val ybar = #2(strip_comb C_ybar) |
|
871 |
in list_mk_exists(ybar, mk_eq(v,C_ybar)) |
|
872 |
end |
|
873 |
in |
|
874 |
cterm_of sign |
|
875 |
(make_free(mk_prop (mk_forall(v, list_mk_disj (map mk_disj C_ybars))))) |
|
876 |
end |
|
877 |
handle _ => raise DTYPE_ERR{func="build_nchotomy",mesg="failed"}; |
|
878 |
||
879 |
||
880 |
(*--------------------------------------------------------------------------- |
|
881 |
* Takes the induction tactic for the datatype, and the result from |
|
1690 | 882 |
* "build_nchotomy" |
883 |
* |
|
884 |
* !v. (EX y1..yi. v = C1 y1..yi) | ... | (EX y1..yj. v = Cn y1..yj) |
|
885 |
* |
|
886 |
* and proves the theorem. The proof works along a diagonal: the nth |
|
887 |
* disjunct in the nth subgoal is easy to solve. Thus this routine depends |
|
888 |
* on the order of goals arising out of the application of the induction |
|
889 |
* tactic. A more general solution would have to use injectiveness and |
|
890 |
* distinctness rewrite rules. |
|
1668 | 891 |
*---------------------------------------------------------------------------*) |
1690 | 892 |
fun prove_nchotomy induct_tac ctm = |
893 |
let val (Const ("Trueprop",_) $ g) = #t(rep_cterm ctm) |
|
1668 | 894 |
val (Const ("All",_) $ Abs (v,_,_)) = g |
1690 | 895 |
(* For goal i, select the correct disjunct to attack, then prove it *) |
896 |
fun tac i 0 = (rtac disjI1 i ORELSE all_tac) THEN |
|
897 |
REPEAT (rtac exI i) THEN (rtac refl i) |
|
898 |
| tac i n = rtac disjI2 i THEN tac i (n-1) |
|
1668 | 899 |
in |
900 |
prove_goalw_cterm[] ctm |
|
901 |
(fn _ => [rtac allI 1, |
|
902 |
induct_tac v 1, |
|
1690 | 903 |
ALLGOALS (fn i => tac i (i-1))]) |
1668 | 904 |
end |
905 |
handle _ => raise DTYPE_ERR {func="prove_nchotomy", mesg="failed"}; |
|
906 |
||
3282
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
907 |
(*--------------------------------------------------------------------------- |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
908 |
* Turn nchotomy into exhaustion: |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
909 |
* [| !!y1..yi. v = C1 y1..yi ==> P; ...; !!y1..yj. v = Cn y1..yj ==> P |] |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
910 |
* ==> P |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
911 |
*---------------------------------------------------------------------------*) |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
912 |
fun mk_exhaust nchotomy = |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
913 |
let val tac = rtac impI 1 THEN |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
914 |
REPEAT(SOMEGOAL(eresolve_tac [disjE,exE])) |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
915 |
in standard(rule_by_tactic tac (nchotomy RS spec RS rev_mp)) end; |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
916 |
|
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
917 |
(* find name of v in exhaustion: *) |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
918 |
fun exhaust_var thm = |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
919 |
let val _ $ ( _ $ Var((x,_),_) $ _ ) = |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
920 |
hd(Logic.strip_assums_hyp(hd(prems_of thm))) |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
921 |
in x end; |
1668 | 922 |
|
923 |
(*--------------------------------------------------------------------------- |
|
924 |
* Brings the preceeding functions together. |
|
925 |
*---------------------------------------------------------------------------*) |
|
926 |
fun case_thms sign case_rewrites induct_tac = |
|
1690 | 927 |
let val nchotomy = prove_nchotomy induct_tac |
928 |
(build_nchotomy sign case_rewrites) |
|
1668 | 929 |
val cong = prove_case_cong nchotomy case_rewrites |
930 |
(build_case_cong sign case_rewrites) |
|
931 |
in {nchotomy=nchotomy, case_cong=cong} |
|
932 |
end; |
|
933 |
||
1690 | 934 |
|
1668 | 935 |
(*--------------------------------------------------------------------------- |
936 |
* Tests |
|
937 |
* |
|
938 |
* |
|
939 |
Dtype.case_thms (sign_of List.thy) List.list.cases List.list.induct_tac; |
|
940 |
Dtype.case_thms (sign_of Prod.thy) [split] |
|
941 |
(fn s => res_inst_tac [("p",s)] PairE_lemma); |
|
942 |
Dtype.case_thms (sign_of Nat.thy) [nat_case_0, nat_case_Suc] nat_ind_tac; |
|
943 |
||
944 |
* |
|
945 |
*---------------------------------------------------------------------------*) |
|
946 |
||
947 |
||
948 |
(*--------------------------------------------------------------------------- |
|
949 |
* Given a theory and the name (and constructors) of a datatype declared in |
|
950 |
* an ancestor of that theory and an induction tactic for that datatype, |
|
951 |
* return the information that TFL needs. This should only be called once for |
|
952 |
* a datatype, because "build_record" proves various facts, and thus is slow. |
|
953 |
* It fails on the datatype of pairs, which must be included for TFL to work. |
|
954 |
* The test shows how to build the record for pairs. |
|
955 |
*---------------------------------------------------------------------------*) |
|
956 |
||
957 |
local fun mk_rw th = (th RS eq_reflection) handle _ => th |
|
958 |
fun get_fact thy s = (get_axiom thy s handle _ => get_thm thy s) |
|
959 |
in |
|
960 |
fun build_record (thy,(ty,cl),itac) = |
|
961 |
let val sign = sign_of thy |
|
962 |
fun const s = Const(s, the(Sign.const_type sign s)) |
|
963 |
val case_rewrites = map (fn c => get_fact thy (ty^"_case_"^c)) cl |
|
964 |
val {nchotomy,case_cong} = case_thms sign case_rewrites itac |
|
3282
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
965 |
val exhaustion = mk_exhaust nchotomy |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
966 |
val exh_var = exhaust_var exhaustion; |
3292 | 967 |
fun exhaust_tac a = |
968 |
ALLNEWSUBGOALS (res_inst_tac [(exh_var,a)] exhaustion) |
|
969 |
(rotate_tac ~1); |
|
3564
f886dbd91ee5
Now Datatype.occs_in_prems prints the necessary warning ITSELF.
paulson
parents:
3538
diff
changeset
|
970 |
val induct_tac = Datatype.occs_in_prems itac |
1668 | 971 |
in |
972 |
(ty, {constructors = map(fn s => const s handle _ => const("op "^s)) cl, |
|
973 |
case_const = const (ty^"_case"), |
|
974 |
case_rewrites = map mk_rw case_rewrites, |
|
3040
7d48671753da
Introduced a generic "induct_tac" which picks up the right induction scheme
nipkow
parents:
2880
diff
changeset
|
975 |
induct_tac = induct_tac, |
1668 | 976 |
nchotomy = nchotomy, |
3282
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
977 |
exhaustion = exhaustion, |
c31e6239d4c9
Added exhaustion thm and exhaust_tac for each datatype.
nipkow
parents:
3265
diff
changeset
|
978 |
exhaust_tac = exhaust_tac, |
1668 | 979 |
case_cong = case_cong}) |
980 |
end |
|
981 |
end; |
|
982 |
||
983 |
||
984 |
(*--------------------------------------------------------------------------- |
|
985 |
* Test |
|
986 |
* |
|
987 |
* |
|
988 |
map Dtype.build_record |
|
989 |
[(Nat.thy, ("nat",["0", "Suc"]), nat_ind_tac), |
|
990 |
(List.thy,("list",["[]", "#"]), List.list.induct_tac)] |
|
991 |
@ |
|
992 |
[let val prod_case_thms = Dtype.case_thms (sign_of Prod.thy) [split] |
|
993 |
(fn s => res_inst_tac [("p",s)] PairE_lemma) |
|
994 |
fun const s = Const(s, the(Sign.const_type (sign_of Prod.thy) s)) |
|
995 |
in ("*", |
|
996 |
{constructors = [const "Pair"], |
|
997 |
case_const = const "split", |
|
998 |
case_rewrites = [split RS eq_reflection], |
|
999 |
case_cong = #case_cong prod_case_thms, |
|
1000 |
nchotomy = #nchotomy prod_case_thms}) end]; |
|
1001 |
||
1002 |
* |
|
1003 |
*---------------------------------------------------------------------------*) |
|
1004 |
||
1005 |
end; |