author | wenzelm |
Fri, 13 Mar 1998 18:15:14 +0100 | |
changeset 4744 | 4469d498cd48 |
parent 4352 | 7ac9f3e8a97d |
child 4804 | 02b7c759159b |
permissions | -rw-r--r-- |
1461 | 1 |
(* Title: ZF/ind-syntax.ML |
0 | 2 |
ID: $Id$ |
1461 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
0 | 4 |
Copyright 1993 University of Cambridge |
5 |
||
6 |
Abstract Syntax functions for Inductive Definitions |
|
7 |
*) |
|
8 |
||
516 | 9 |
(*The structure protects these items from redeclaration (somewhat!). The |
10 |
datatype definitions in theory files refer to these items by name! |
|
11 |
*) |
|
12 |
structure Ind_Syntax = |
|
13 |
struct |
|
0 | 14 |
|
4352
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
15 |
(** Abstract syntax definitions for ZF **) |
0 | 16 |
|
4352
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
17 |
val iT = Type("i",[]); |
0 | 18 |
|
4352
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
19 |
val mem_const = Const("op :", [iT,iT]--->FOLogic.oT); |
0 | 20 |
|
21 |
(*Creates All(%v.v:A --> P(v)) rather than Ball(A,P) *) |
|
22 |
fun mk_all_imp (A,P) = |
|
4352
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
23 |
FOLogic.all_const iT $ |
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
24 |
Abs("v", iT, FOLogic.imp $ (mem_const $ Bound 0 $ A) $ (P $ Bound 0)); |
0 | 25 |
|
26 |
val Part_const = Const("Part", [iT,iT-->iT]--->iT); |
|
27 |
||
4352
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
28 |
val Collect_const = Const("Collect", [iT, iT-->FOLogic.oT] ---> iT); |
0 | 29 |
fun mk_Collect (a,D,t) = Collect_const $ D $ absfree(a, iT, t); |
30 |
||
516 | 31 |
(*simple error-checking in the premises of an inductive definition*) |
32 |
fun chk_prem rec_hd (Const("op &",_) $ _ $ _) = |
|
1461 | 33 |
error"Premises may not be conjuctive" |
516 | 34 |
| chk_prem rec_hd (Const("op :",_) $ t $ X) = |
1461 | 35 |
deny (Logic.occs(rec_hd,t)) "Recursion term on left of member symbol" |
516 | 36 |
| chk_prem rec_hd t = |
1461 | 37 |
deny (Logic.occs(rec_hd,t)) "Recursion term in side formula"; |
516 | 38 |
|
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
39 |
(*Return the conclusion of a rule, of the form t:X*) |
0 | 40 |
fun rule_concl rl = |
435 | 41 |
let val Const("Trueprop",_) $ (Const("op :",_) $ t $ X) = |
1461 | 42 |
Logic.strip_imp_concl rl |
435 | 43 |
in (t,X) end; |
44 |
||
45 |
(*As above, but return error message if bad*) |
|
46 |
fun rule_concl_msg sign rl = rule_concl rl |
|
47 |
handle Bind => error ("Ill-formed conclusion of introduction rule: " ^ |
|
1461 | 48 |
Sign.string_of_term sign rl); |
0 | 49 |
|
50 |
(*For deriving cases rules. CollectD2 discards the domain, which is redundant; |
|
51 |
read_instantiate replaces a propositional variable by a formula variable*) |
|
52 |
val equals_CollectD = |
|
53 |
read_instantiate [("W","?Q")] |
|
54 |
(make_elim (equalityD1 RS subsetD RS CollectD2)); |
|
55 |
||
56 |
||
516 | 57 |
(** For datatype definitions **) |
58 |
||
59 |
fun dest_mem (Const("op :",_) $ x $ A) = (x,A) |
|
60 |
| dest_mem _ = error "Constructor specifications must have the form x:A"; |
|
61 |
||
62 |
(*read a constructor specification*) |
|
63 |
fun read_construct sign (id, sprems, syn) = |
|
4352
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
64 |
let val prems = map (readtm sign FOLogic.oT) sprems |
1461 | 65 |
val args = map (#1 o dest_mem) prems |
66 |
val T = (map (#2 o dest_Free) args) ---> iT |
|
67 |
handle TERM _ => error |
|
68 |
"Bad variable in constructor specification" |
|
568 | 69 |
val name = Syntax.const_name id syn (*handle infix constructors*) |
516 | 70 |
in ((id,T,syn), name, args, prems) end; |
71 |
||
72 |
val read_constructs = map o map o read_construct; |
|
0 | 73 |
|
516 | 74 |
(*convert constructor specifications into introduction rules*) |
3925
90f499226ab9
(co) inductive / datatype package adapted to qualified names;
wenzelm
parents:
2266
diff
changeset
|
75 |
fun mk_intr_tms sg (rec_tm, constructs) = |
90f499226ab9
(co) inductive / datatype package adapted to qualified names;
wenzelm
parents:
2266
diff
changeset
|
76 |
let |
90f499226ab9
(co) inductive / datatype package adapted to qualified names;
wenzelm
parents:
2266
diff
changeset
|
77 |
fun mk_intr ((id,T,syn), name, args, prems) = |
90f499226ab9
(co) inductive / datatype package adapted to qualified names;
wenzelm
parents:
2266
diff
changeset
|
78 |
Logic.list_implies |
4352
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
79 |
(map FOLogic.mk_Trueprop prems, |
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
80 |
FOLogic.mk_Trueprop |
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
81 |
(mem_const $ list_comb (Const (Sign.full_name sg name, T), args) |
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
82 |
$ rec_tm)) |
516 | 83 |
in map mk_intr constructs end; |
84 |
||
3925
90f499226ab9
(co) inductive / datatype package adapted to qualified names;
wenzelm
parents:
2266
diff
changeset
|
85 |
fun mk_all_intr_tms sg arg = List.concat (ListPair.map (mk_intr_tms sg) arg); |
0 | 86 |
|
1461 | 87 |
val Un = Const("op Un", [iT,iT]--->iT) |
88 |
and empty = Const("0", iT) |
|
89 |
and univ = Const("univ", iT-->iT) |
|
90 |
and quniv = Const("quniv", iT-->iT); |
|
0 | 91 |
|
516 | 92 |
(*Make a datatype's domain: form the union of its set parameters*) |
93 |
fun union_params rec_tm = |
|
94 |
let val (_,args) = strip_comb rec_tm |
|
95 |
in case (filter (fn arg => type_of arg = iT) args) of |
|
96 |
[] => empty |
|
97 |
| iargs => fold_bal (app Un) iargs |
|
98 |
end; |
|
99 |
||
742
faa3efc1d130
data_domain,Codata_domain: removed replicate; now return one
lcp
parents:
578
diff
changeset
|
100 |
(*Previously these both did replicate (length rec_tms); however now |
faa3efc1d130
data_domain,Codata_domain: removed replicate; now return one
lcp
parents:
578
diff
changeset
|
101 |
[q]univ itself constitutes the sum domain for mutual recursion!*) |
faa3efc1d130
data_domain,Codata_domain: removed replicate; now return one
lcp
parents:
578
diff
changeset
|
102 |
fun data_domain rec_tms = univ $ union_params (hd rec_tms); |
faa3efc1d130
data_domain,Codata_domain: removed replicate; now return one
lcp
parents:
578
diff
changeset
|
103 |
fun Codata_domain rec_tms = quniv $ union_params (hd rec_tms); |
0 | 104 |
|
105 |
(*Could go to FOL, but it's hardly general*) |
|
516 | 106 |
val def_swap_iff = prove_goal IFOL.thy "a==b ==> a=c <-> c=b" |
107 |
(fn [def] => [(rewtac def), (rtac iffI 1), (REPEAT (etac sym 1))]); |
|
0 | 108 |
|
109 |
val def_trans = prove_goal IFOL.thy "[| f==g; g(a)=b |] ==> f(a)=b" |
|
110 |
(fn [rew,prem] => [ rewtac rew, rtac prem 1 ]); |
|
111 |
||
55 | 112 |
(*Delete needless equality assumptions*) |
113 |
val refl_thin = prove_goal IFOL.thy "!!P. [| a=a; P |] ==> P" |
|
114 |
(fn _ => [assume_tac 1]); |
|
0 | 115 |
|
1418
f5f97ee67cbb
Improving space efficiency of inductive/datatype definitions.
paulson
parents:
742
diff
changeset
|
116 |
(*Includes rules for succ and Pair since they are common constructions*) |
f5f97ee67cbb
Improving space efficiency of inductive/datatype definitions.
paulson
parents:
742
diff
changeset
|
117 |
val elim_rls = [asm_rl, FalseE, succ_neq_0, sym RS succ_neq_0, |
1461 | 118 |
Pair_neq_0, sym RS Pair_neq_0, Pair_inject, |
119 |
make_elim succ_inject, |
|
120 |
refl_thin, conjE, exE, disjE]; |
|
1418
f5f97ee67cbb
Improving space efficiency of inductive/datatype definitions.
paulson
parents:
742
diff
changeset
|
121 |
|
f5f97ee67cbb
Improving space efficiency of inductive/datatype definitions.
paulson
parents:
742
diff
changeset
|
122 |
(*Turns iff rules into safe elimination rules*) |
f5f97ee67cbb
Improving space efficiency of inductive/datatype definitions.
paulson
parents:
742
diff
changeset
|
123 |
fun mk_free_SEs iffs = map (gen_make_elim [conjE,FalseE]) (iffs RL [iffD1]); |
f5f97ee67cbb
Improving space efficiency of inductive/datatype definitions.
paulson
parents:
742
diff
changeset
|
124 |
|
516 | 125 |
end; |
126 |