author | wenzelm |
Mon, 12 Nov 2001 20:22:23 +0100 | |
changeset 12160 | a5cf3ea0685d |
parent 12134 | 7049eead7a50 |
child 12175 | 5cf58a1799a7 |
permissions | -rw-r--r-- |
516 | 1 |
(* Title: ZF/Datatype.ML |
0 | 2 |
ID: $Id$ |
516 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
0 | 4 |
Copyright 1993 University of Cambridge |
5 |
||
120 | 6 |
(Co)Datatype Definitions for Zermelo-Fraenkel Set Theory |
0 | 7 |
*) |
8 |
||
9 |
||
6053
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
10 |
(*Typechecking rules for most datatypes involving univ*) |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
11 |
structure Data_Arg = |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
12 |
struct |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
13 |
val intrs = |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
14 |
[SigmaI, InlI, InrI, |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
15 |
Pair_in_univ, Inl_in_univ, Inr_in_univ, |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
16 |
zero_in_univ, A_into_univ, nat_into_univ, UnCI]; |
0 | 17 |
|
6112 | 18 |
|
19 |
val elims = [make_elim InlD, make_elim InrD, (*for mutual recursion*) |
|
12134 | 20 |
SigmaE, sumE]; (*allows * and + in spec*) |
516 | 21 |
end; |
22 |
||
23 |
||
6053
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
24 |
structure Data_Package = |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
25 |
Add_datatype_def_Fun |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
26 |
(structure Fp=Lfp and Pr=Standard_Prod and CP=Standard_CP |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
27 |
and Su=Standard_Sum |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
28 |
and Ind_Package = Ind_Package |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
29 |
and Datatype_Arg = Data_Arg); |
516 | 30 |
|
31 |
||
6053
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
32 |
(*Typechecking rules for most codatatypes involving quniv*) |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
33 |
structure CoData_Arg = |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
34 |
struct |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
35 |
val intrs = |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
36 |
[QSigmaI, QInlI, QInrI, |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
37 |
QPair_in_quniv, QInl_in_quniv, QInr_in_quniv, |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
38 |
zero_in_quniv, A_into_quniv, nat_into_quniv, UnCI]; |
516 | 39 |
|
6112 | 40 |
val elims = [make_elim QInlD, make_elim QInrD, (*for mutual recursion*) |
12134 | 41 |
QSigmaE, qsumE]; (*allows * and + in spec*) |
6053
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
42 |
end; |
516 | 43 |
|
6053
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
44 |
structure CoData_Package = |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
45 |
Add_datatype_def_Fun(structure Fp=Gfp and Pr=Quine_Prod and CP=Quine_CP |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
1461
diff
changeset
|
46 |
and Su=Quine_Sum |
12134 | 47 |
and Ind_Package = CoInd_Package |
48 |
and Datatype_Arg = CoData_Arg); |
|
516 | 49 |
|
6141 | 50 |
|
51 |
||
52 |
(*Simproc for freeness reasoning: compare datatype constructors for equality*) |
|
53 |
structure DataFree = |
|
54 |
struct |
|
55 |
val trace = ref false; |
|
56 |
||
57 |
fun mk_new ([],[]) = Const("True",FOLogic.oT) |
|
58 |
| mk_new (largs,rargs) = |
|
12134 | 59 |
fold_bal FOLogic.mk_conj |
60 |
(map FOLogic.mk_eq (ListPair.zip (largs,rargs))); |
|
6141 | 61 |
|
62 |
||
63 |
fun proc sg _ old = |
|
64 |
let val _ = if !trace then writeln ("data_free: OLD = " ^ |
|
12134 | 65 |
string_of_cterm (cterm_of sg old)) |
66 |
else () |
|
6141 | 67 |
val (lhs,rhs) = FOLogic.dest_eq old |
68 |
val (lhead, largs) = strip_comb lhs |
|
69 |
and (rhead, rargs) = strip_comb rhs |
|
70 |
val lname = #1 (dest_Const lhead) |
|
71 |
and rname = #1 (dest_Const rhead) |
|
72 |
val lcon_info = the (Symtab.lookup (ConstructorsData.get_sg sg, lname)) |
|
73 |
and rcon_info = the (Symtab.lookup (ConstructorsData.get_sg sg, rname)) |
|
74 |
val new = |
|
12134 | 75 |
if #big_rec_name lcon_info = #big_rec_name rcon_info |
76 |
andalso not (null (#free_iffs lcon_info)) then |
|
77 |
if lname = rname then mk_new (largs, rargs) |
|
78 |
else Const("False",FOLogic.oT) |
|
79 |
else raise Match |
|
6141 | 80 |
val _ = if !trace then |
12134 | 81 |
writeln ("NEW = " ^ string_of_cterm (Thm.cterm_of sg new)) |
82 |
else (); |
|
83 |
val goal = Logic.mk_equals (old, new) |
|
84 |
val thm = Tactic.prove sg [] [] goal (fn _ => rtac iff_reflection 1 THEN |
|
85 |
simp_tac (simpset_of Datatype.thy addsimps #free_iffs lcon_info) 1) |
|
86 |
handle ERROR => |
|
87 |
error ("data_free simproc:\nfailed to prove " ^ Sign.string_of_term sg goal) |
|
6141 | 88 |
in Some thm end |
89 |
handle _ => None; |
|
90 |
||
91 |
||
92 |
val conv = |
|
93 |
Simplifier.mk_simproc "data_free" |
|
94 |
[Thm.read_cterm (sign_of ZF.thy) ("(x::i) = y", FOLogic.oT)] |
|
95 |
proc; |
|
96 |
end; |
|
97 |
||
98 |
||
99 |
Addsimprocs [DataFree.conv]; |