author | wenzelm |
Wed, 28 Oct 2009 18:02:06 +0100 | |
changeset 33284 | b5347c65bcab |
parent 32960 | 69916a850301 |
child 33317 | b4534348b8fd |
permissions | -rw-r--r-- |
12243 | 1 |
(* Title: ZF/ind_syntax.ML |
1461 | 2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
0 | 3 |
Copyright 1993 University of Cambridge |
4 |
||
12243 | 5 |
Abstract Syntax functions for Inductive Definitions. |
0 | 6 |
*) |
7 |
||
516 | 8 |
structure Ind_Syntax = |
9 |
struct |
|
0 | 10 |
|
4804
02b7c759159b
Fixed bug in inductive sections to allow disjunctive premises;
paulson
parents:
4352
diff
changeset
|
11 |
(*Print tracing messages during processing of "inductive" theory sections*) |
32740 | 12 |
val trace = Unsynchronized.ref false; |
4804
02b7c759159b
Fixed bug in inductive sections to allow disjunctive premises;
paulson
parents:
4352
diff
changeset
|
13 |
|
26189 | 14 |
fun traceIt msg thy t = |
26939
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26189
diff
changeset
|
15 |
if !trace then (tracing (msg ^ Syntax.string_of_term_global thy t); t) |
17988 | 16 |
else t; |
17 |
||
6053
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
4972
diff
changeset
|
18 |
|
4352
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
19 |
(** Abstract syntax definitions for ZF **) |
0 | 20 |
|
4352
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
21 |
val iT = Type("i",[]); |
0 | 22 |
|
23 |
(*Creates All(%v.v:A --> P(v)) rather than Ball(A,P) *) |
|
26189 | 24 |
fun mk_all_imp (A,P) = |
25 |
FOLogic.all_const iT $ |
|
26 |
Abs("v", iT, FOLogic.imp $ (@{const mem} $ Bound 0 $ A) $ |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32957
diff
changeset
|
27 |
Term.betapply(P, Bound 0)); |
0 | 28 |
|
26189 | 29 |
fun mk_Collect (a, D, t) = @{const Collect} $ D $ absfree (a, iT, t); |
0 | 30 |
|
516 | 31 |
(*simple error-checking in the premises of an inductive definition*) |
26189 | 32 |
fun chk_prem rec_hd (Const (@{const_name "op &"}, _) $ _ $ _) = |
1461 | 33 |
error"Premises may not be conjuctive" |
26189 | 34 |
| chk_prem rec_hd (Const (@{const_name mem}, _) $ t $ X) = |
22567
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
wenzelm
parents:
21539
diff
changeset
|
35 |
(Logic.occs(rec_hd,t) andalso error "Recursion term on left of member symbol"; ()) |
26189 | 36 |
| chk_prem rec_hd t = |
22567
1565d476a9e2
removed assert/deny (avoid clash with Alice keywords and confusion due to strict evaluation);
wenzelm
parents:
21539
diff
changeset
|
37 |
(Logic.occs(rec_hd,t) andalso error "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*) |
26189 | 40 |
fun rule_concl rl = |
41 |
let val Const (@{const_name Trueprop}, _) $ (Const (@{const_name mem}, _) $ 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 |
|
26189 | 47 |
handle Bind => error ("Ill-formed conclusion of introduction rule: " ^ |
26939
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26189
diff
changeset
|
48 |
Syntax.string_of_term_global 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*) |
|
26189 | 52 |
val equals_CollectD = |
27239 | 53 |
read_instantiate @{context} [(("W", 0), "?Q")] |
24893 | 54 |
(make_elim (@{thm equalityD1} RS @{thm subsetD} RS @{thm CollectD2})); |
0 | 55 |
|
56 |
||
516 | 57 |
(** For datatype definitions **) |
58 |
||
6053
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
4972
diff
changeset
|
59 |
(*Constructor name, type, mixfix info; |
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
4972
diff
changeset
|
60 |
internal name from mixfix, datatype sets, full premises*) |
26189 | 61 |
type constructor_spec = |
62 |
(string * typ * mixfix) * string * term list * term list; |
|
6053
8a1059aa01f0
new inductive, datatype and primrec packages, etc.
paulson
parents:
4972
diff
changeset
|
63 |
|
26189 | 64 |
fun dest_mem (Const (@{const_name mem}, _) $ x $ A) = (x, A) |
516 | 65 |
| dest_mem _ = error "Constructor specifications must have the form x:A"; |
66 |
||
67 |
(*read a constructor specification*) |
|
27261
5b3101338f42
eliminated old Sign.read_term/Thm.read_cterm etc.;
wenzelm
parents:
27239
diff
changeset
|
68 |
fun read_construct ctxt (id, sprems, syn) = |
5b3101338f42
eliminated old Sign.read_term/Thm.read_cterm etc.;
wenzelm
parents:
27239
diff
changeset
|
69 |
let val prems = map (Syntax.parse_term ctxt #> TypeInfer.constrain FOLogic.oT) sprems |
5b3101338f42
eliminated old Sign.read_term/Thm.read_cterm etc.;
wenzelm
parents:
27239
diff
changeset
|
70 |
|> Syntax.check_terms ctxt |
1461 | 71 |
val args = map (#1 o dest_mem) prems |
72 |
val T = (map (#2 o dest_Free) args) ---> iT |
|
26189 | 73 |
handle TERM _ => error |
1461 | 74 |
"Bad variable in constructor specification" |
30345 | 75 |
val name = Syntax.const_name syn id |
516 | 76 |
in ((id,T,syn), name, args, prems) end; |
77 |
||
78 |
val read_constructs = map o map o read_construct; |
|
0 | 79 |
|
516 | 80 |
(*convert constructor specifications into introduction rules*) |
3925
90f499226ab9
(co) inductive / datatype package adapted to qualified names;
wenzelm
parents:
2266
diff
changeset
|
81 |
fun mk_intr_tms sg (rec_tm, constructs) = |
90f499226ab9
(co) inductive / datatype package adapted to qualified names;
wenzelm
parents:
2266
diff
changeset
|
82 |
let |
90f499226ab9
(co) inductive / datatype package adapted to qualified names;
wenzelm
parents:
2266
diff
changeset
|
83 |
fun mk_intr ((id,T,syn), name, args, prems) = |
90f499226ab9
(co) inductive / datatype package adapted to qualified names;
wenzelm
parents:
2266
diff
changeset
|
84 |
Logic.list_implies |
4352
7ac9f3e8a97d
Moved some functions from ZF/ind_syntax.ML to FOL/fologic.ML
paulson
parents:
3925
diff
changeset
|
85 |
(map FOLogic.mk_Trueprop prems, |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32957
diff
changeset
|
86 |
FOLogic.mk_Trueprop |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32957
diff
changeset
|
87 |
(@{const mem} $ list_comb (Const (Sign.full_bname sg name, T), args) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32957
diff
changeset
|
88 |
$ rec_tm)) |
516 | 89 |
in map mk_intr constructs end; |
90 |
||
32952 | 91 |
fun mk_all_intr_tms sg arg = flat (ListPair.map (mk_intr_tms sg) arg); |
0 | 92 |
|
26189 | 93 |
fun mk_Un (t1, t2) = @{const Un} $ t1 $ t2; |
0 | 94 |
|
516 | 95 |
(*Make a datatype's domain: form the union of its set parameters*) |
6112 | 96 |
fun union_params (rec_tm, cs) = |
516 | 97 |
let val (_,args) = strip_comb rec_tm |
6112 | 98 |
fun is_ind arg = (type_of arg = iT) |
15570 | 99 |
in case List.filter is_ind (args @ cs) of |
26189 | 100 |
[] => @{const 0} |
32765 | 101 |
| u_args => Balanced_Tree.make mk_Un u_args |
516 | 102 |
end; |
103 |
||
0 | 104 |
|
1418
f5f97ee67cbb
Improving space efficiency of inductive/datatype definitions.
paulson
parents:
742
diff
changeset
|
105 |
(*Includes rules for succ and Pair since they are common constructions*) |
26189 | 106 |
val elim_rls = |
107 |
[@{thm asm_rl}, @{thm FalseE}, @{thm succ_neq_0}, @{thm sym} RS @{thm succ_neq_0}, |
|
108 |
@{thm Pair_neq_0}, @{thm sym} RS @{thm Pair_neq_0}, @{thm Pair_inject}, |
|
109 |
make_elim @{thm succ_inject}, @{thm refl_thin}, @{thm conjE}, @{thm exE}, @{thm disjE}]; |
|
1418
f5f97ee67cbb
Improving space efficiency of inductive/datatype definitions.
paulson
parents:
742
diff
changeset
|
110 |
|
7694 | 111 |
|
112 |
(*From HOL/ex/meson.ML: raises exception if no rules apply -- unlike RL*) |
|
113 |
fun tryres (th, rl::rls) = (th RS rl handle THM _ => tryres(th,rls)) |
|
114 |
| tryres (th, []) = raise THM("tryres", 0, [th]); |
|
115 |
||
26189 | 116 |
fun gen_make_elim elim_rls rl = |
32957 | 117 |
Drule.standard (tryres (rl, elim_rls @ [revcut_rl])); |
7694 | 118 |
|
1418
f5f97ee67cbb
Improving space efficiency of inductive/datatype definitions.
paulson
parents:
742
diff
changeset
|
119 |
(*Turns iff rules into safe elimination rules*) |
26189 | 120 |
fun mk_free_SEs iffs = map (gen_make_elim [@{thm conjE}, @{thm FalseE}]) (iffs RL [@{thm iffD1}]); |
1418
f5f97ee67cbb
Improving space efficiency of inductive/datatype definitions.
paulson
parents:
742
diff
changeset
|
121 |
|
516 | 122 |
end; |
123 |