src/ZF/ind_syntax.ML
author lcp
Fri, 12 Aug 1994 12:51:34 +0200
changeset 516 1957113f0d7d
parent 466 08d1cce222e1
child 543 e961b2092869
permissions -rw-r--r--
installation of new inductive/datatype sections
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     1
(*  Title: 	ZF/ind-syntax.ML
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
Abstract Syntax functions for Inductive Definitions
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
     9
(*The structure protects these items from redeclaration (somewhat!).  The 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    10
  datatype definitions in theory files refer to these items by name!
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    11
*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    12
structure Ind_Syntax =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    13
struct
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    14
(*Make a definition lhs==rhs, checking that vars on lhs contain those of rhs*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    15
fun mk_defpair (lhs, rhs) = 
454
0d19ab250cc9 removed flatten_term and replaced add_axioms by add_axioms_i
clasohm
parents: 444
diff changeset
    16
  let val Const(name, _) = head_of lhs
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
      val dummy = assert (term_vars rhs subset term_vars lhs
454
0d19ab250cc9 removed flatten_term and replaced add_axioms by add_axioms_i
clasohm
parents: 444
diff changeset
    18
		          andalso
0d19ab250cc9 removed flatten_term and replaced add_axioms by add_axioms_i
clasohm
parents: 444
diff changeset
    19
		          term_frees rhs subset term_frees lhs
0d19ab250cc9 removed flatten_term and replaced add_axioms by add_axioms_i
clasohm
parents: 444
diff changeset
    20
		          andalso
0d19ab250cc9 removed flatten_term and replaced add_axioms by add_axioms_i
clasohm
parents: 444
diff changeset
    21
		          term_tvars rhs subset term_tvars lhs
0d19ab250cc9 removed flatten_term and replaced add_axioms by add_axioms_i
clasohm
parents: 444
diff changeset
    22
		          andalso
0d19ab250cc9 removed flatten_term and replaced add_axioms by add_axioms_i
clasohm
parents: 444
diff changeset
    23
		          term_tfrees rhs subset term_tfrees lhs)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
	          ("Extra variables on RHS in definition of " ^ name)
454
0d19ab250cc9 removed flatten_term and replaced add_axioms by add_axioms_i
clasohm
parents: 444
diff changeset
    25
  in (name ^ "_def", Logic.mk_equals (lhs, rhs)) end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    27
fun get_def thy s = get_axiom thy (s^"_def");
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    28
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
fun lookup_const sign a = Symtab.lookup(#const_tab (Sign.rep_sg sign), a);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
(*export to Pure/library?  *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
fun assert_all pred l msg_fn = 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
  let fun asl [] = ()
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
	| asl (x::xs) = if pred x then asl xs
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
	                else error (msg_fn x)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
  in  asl l  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
(** Abstract syntax definitions for FOL and ZF **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    41
val iT = Type("i",[])
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
and oT = Type("o",[]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    44
fun ap t u = t$u;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
fun app t (u1,u2) = t $ u1 $ u2;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    47
(*Given u expecting arguments of types [T1,...,Tn], create term of 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
  type T1*...*Tn => i using split*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
fun ap_split split u [ ]   = Abs("null", iT, u)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
  | ap_split split u [_]   = u
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    51
  | ap_split split u [_,_] = split $ u
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
  | ap_split split u (T::Ts) = 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
      split $ (Abs("v", T, ap_split split (u $ Bound(length Ts - 2)) Ts));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    54
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    55
val conj = Const("op &", [oT,oT]--->oT)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    56
and disj = Const("op |", [oT,oT]--->oT)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
and imp = Const("op -->", [oT,oT]--->oT);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    59
val eq_const = Const("op =", [iT,iT]--->oT);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    60
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
val mem_const = Const("op :", [iT,iT]--->oT);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
val exists_const = Const("Ex", [iT-->oT]--->oT);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
fun mk_exists (Free(x,T),P) = exists_const $ (absfree (x,T,P));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
val all_const = Const("All", [iT-->oT]--->oT);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
fun mk_all (Free(x,T),P) = all_const $ (absfree (x,T,P));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
(*Creates All(%v.v:A --> P(v)) rather than Ball(A,P) *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    70
fun mk_all_imp (A,P) = 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
    all_const $ Abs("v", iT, imp $ (mem_const $ Bound 0 $ A) $ (P $ Bound 0));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    73
val Part_const = Const("Part", [iT,iT-->iT]--->iT);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
val Collect_const = Const("Collect", [iT,iT-->oT]--->iT);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
fun mk_Collect (a,D,t) = Collect_const $ D $ absfree(a, iT, t);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    77
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    78
val Trueprop = Const("Trueprop",oT-->propT);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
fun mk_tprop P = Trueprop $ P;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    80
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
(*Prove a goal stated as a term, with exception handling*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
fun prove_term sign defs (P,tacsf) = 
231
cb6a24451544 Updated refs to old Sign functions
lcp
parents: 202
diff changeset
    83
    let val ct = cterm_of sign P
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    84
    in  prove_goalw_cterm defs ct tacsf
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    85
	handle e => (writeln ("Exception in proof of\n" ^
231
cb6a24451544 Updated refs to old Sign functions
lcp
parents: 202
diff changeset
    86
			       string_of_cterm ct); 
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    87
		     raise e)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
    end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    89
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
(*Read an assumption in the given theory*)
231
cb6a24451544 Updated refs to old Sign functions
lcp
parents: 202
diff changeset
    91
fun assume_read thy a = assume (read_cterm (sign_of thy) (a,propT));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    92
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    93
fun readtm sign T a = 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    94
    read_cterm sign (a,T) |> term_of
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    95
    handle ERROR => error ("The error above occurred for " ^ a);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    96
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    97
(*Skipping initial blanks, find the first identifier*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    98
fun scan_to_id s = 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
    99
    s |> explode |> take_prefix is_blank |> #2 |> Lexicon.scan_id |> #1
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   100
    handle LEXICAL_ERROR => error ("Expected to find an identifier in " ^ s);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   101
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   102
fun is_backslash c = c = "\\";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   103
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   104
(*Apply string escapes to a quoted string; see Def of Standard ML, page 3
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   105
  Does not handle the \ddd form;  no error checking*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   106
fun escape [] = []
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   107
  | escape cs = (case take_prefix (not o is_backslash) cs of
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   108
	 (front, []) => front
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   109
       | (front, _::"n"::rest) => front @ ("\n" :: escape rest)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   110
       | (front, _::"t"::rest) => front @ ("\t" :: escape rest)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   111
       | (front, _::"^"::c::rest) => front @ (chr(ord(c)-64) :: escape rest)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   112
       | (front, _::"\""::rest) => front @ ("\"" :: escape rest)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   113
       | (front, _::"\\"::rest) => front @ ("\\" :: escape rest)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   114
       | (front, b::c::rest) => 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   115
	   if is_blank c   (*remove any further blanks and the following \ *)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   116
	   then front @ escape (tl (snd (take_prefix is_blank rest)))
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   117
	   else error ("Unrecognized string escape: " ^ implode(b::c::rest)));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   118
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   119
(*Remove the first and last charaters -- presumed to be quotes*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   120
val trim = implode o escape o rev o tl o rev o tl o explode;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   121
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   122
(*simple error-checking in the premises of an inductive definition*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   123
fun chk_prem rec_hd (Const("op &",_) $ _ $ _) =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   124
	error"Premises may not be conjuctive"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   125
  | chk_prem rec_hd (Const("op :",_) $ t $ X) = 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   126
	deny (Logic.occs(rec_hd,t)) "Recursion term on left of member symbol"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   127
  | chk_prem rec_hd t = 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   128
	deny (Logic.occs(rec_hd,t)) "Recursion term in side formula";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   129
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   130
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   131
(*Inverse of varifyT.  Move to Pure/type.ML?*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   132
fun unvarifyT (Type (a, Ts)) = Type (a, map unvarifyT Ts)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   133
  | unvarifyT (TVar ((a, 0), S)) = TFree (a, S)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   134
  | unvarifyT T = T;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   135
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   136
(*Inverse of varify.  Move to Pure/logic.ML?*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   137
fun unvarify (Const(a,T))    = Const(a, unvarifyT T)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   138
  | unvarify (Var((a,0), T)) = Free(a, unvarifyT T)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   139
  | unvarify (Var(ixn,T))    = Var(ixn, unvarifyT T)	(*non-zero index!*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   140
  | unvarify (Abs (a,T,body)) = Abs (a, unvarifyT T, unvarify body)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   141
  | unvarify (f$t) = unvarify f $ unvarify t
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   142
  | unvarify t = t;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   143
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   144
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   145
(*Make distinct individual variables a1, a2, a3, ..., an. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   146
fun mk_frees a [] = []
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   147
  | mk_frees a (T::Ts) = Free(a,T) :: mk_frees (bump_string a) Ts;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   148
14
1c0926788772 ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents: 6
diff changeset
   149
(*Return the conclusion of a rule, of the form t:X*)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   150
fun rule_concl rl = 
435
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 231
diff changeset
   151
    let val Const("Trueprop",_) $ (Const("op :",_) $ t $ X) = 
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 231
diff changeset
   152
		Logic.strip_imp_concl rl
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 231
diff changeset
   153
    in  (t,X)  end;
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 231
diff changeset
   154
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 231
diff changeset
   155
(*As above, but return error message if bad*)
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 231
diff changeset
   156
fun rule_concl_msg sign rl = rule_concl rl
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 231
diff changeset
   157
    handle Bind => error ("Ill-formed conclusion of introduction rule: " ^ 
ca5356bd315a Addition of cardinals and order types, various tidying
lcp
parents: 231
diff changeset
   158
			  Sign.string_of_term sign rl);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   159
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   160
(*For deriving cases rules.  CollectD2 discards the domain, which is redundant;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   161
  read_instantiate replaces a propositional variable by a formula variable*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   162
val equals_CollectD = 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   163
    read_instantiate [("W","?Q")]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   164
        (make_elim (equalityD1 RS subsetD RS CollectD2));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   165
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   166
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   167
(*From HOL/ex/meson.ML: raises exception if no rules apply -- unlike RL*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   168
fun tryres (th, rl::rls) = (th RS rl handle THM _ => tryres(th,rls))
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   169
  | tryres (th, []) = raise THM("tryres", 0, [th]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   170
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   171
fun gen_make_elim elim_rls rl = 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   172
      standard (tryres (rl, elim_rls @ [revcut_rl]));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   173
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   174
(** For datatype definitions **)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   175
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   176
fun dest_mem (Const("op :",_) $ x $ A) = (x,A)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   177
  | dest_mem _ = error "Constructor specifications must have the form x:A";
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   178
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   179
(*read a constructor specification*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   180
fun read_construct sign (id, sprems, syn) =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   181
    let val prems = map (readtm sign oT) sprems
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   182
	val args = map (#1 o dest_mem) prems
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   183
	val T = (map (#2 o dest_Free) args) ---> iT
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   184
		handle TERM _ => error 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   185
		    "Bad variable in constructor specification"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   186
        val name = const_name id syn  (*handle infix constructors*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   187
    in ((id,T,syn), name, args, prems) end;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   188
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   189
val read_constructs = map o map o read_construct;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   190
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   191
(*convert constructor specifications into introduction rules*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   192
fun mk_intr_tms (rec_tm, constructs) =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   193
  let fun mk_intr ((id,T,syn), name, args, prems) =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   194
	  Logic.list_implies
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   195
	      (map mk_tprop prems,
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   196
	       mk_tprop (mem_const $ list_comb(Const(name,T), args) $ rec_tm)) 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   197
  in  map mk_intr constructs  end;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   198
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   199
val mk_all_intr_tms = flat o map mk_intr_tms o op ~~;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   200
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   201
val Un		= Const("op Un", [iT,iT]--->iT)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   202
and empty	= Const("0", iT)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   203
and univ	= Const("univ", iT-->iT)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   204
and quniv	= Const("quniv", iT-->iT);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   205
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   206
(*Make a datatype's domain: form the union of its set parameters*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   207
fun union_params rec_tm =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   208
  let val (_,args) = strip_comb rec_tm
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   209
  in  case (filter (fn arg => type_of arg = iT) args) of
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   210
         []    => empty
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   211
       | iargs => fold_bal (app Un) iargs
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   212
  end;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   213
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   214
fun data_domain rec_tms =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   215
  replicate (length rec_tms) (univ $ union_params (hd rec_tms));
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   216
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   217
fun Codata_domain rec_tms =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   218
  replicate (length rec_tms) (quniv $ union_params (hd rec_tms));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   219
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   220
(*Could go to FOL, but it's hardly general*)
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   221
val def_swap_iff = prove_goal IFOL.thy "a==b ==> a=c <-> c=b"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   222
 (fn [def] => [(rewtac def), (rtac iffI 1), (REPEAT (etac sym 1))]);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   223
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   224
val def_trans = prove_goal IFOL.thy "[| f==g;  g(a)=b |] ==> f(a)=b"
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   225
  (fn [rew,prem] => [ rewtac rew, rtac prem 1 ]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   226
55
331d93292ee0 ZF/ind-syntax/refl_thin: new
lcp
parents: 14
diff changeset
   227
(*Delete needless equality assumptions*)
331d93292ee0 ZF/ind-syntax/refl_thin: new
lcp
parents: 14
diff changeset
   228
val refl_thin = prove_goal IFOL.thy "!!P. [| a=a;  P |] ==> P"
331d93292ee0 ZF/ind-syntax/refl_thin: new
lcp
parents: 14
diff changeset
   229
     (fn _ => [assume_tac 1]);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   230
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   231
end;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 466
diff changeset
   232