src/ZF/ind_syntax.ML
changeset 543 e961b2092869
parent 516 1957113f0d7d
child 568 756b0e2a6cac
equal deleted inserted replaced
542:164be35c8a16 543:e961b2092869
    12 structure Ind_Syntax =
    12 structure Ind_Syntax =
    13 struct
    13 struct
    14 (*Make a definition lhs==rhs, checking that vars on lhs contain those of rhs*)
    14 (*Make a definition lhs==rhs, checking that vars on lhs contain those of rhs*)
    15 fun mk_defpair (lhs, rhs) = 
    15 fun mk_defpair (lhs, rhs) = 
    16   let val Const(name, _) = head_of lhs
    16   let val Const(name, _) = head_of lhs
    17       val dummy = assert (term_vars rhs subset term_vars lhs
       
    18 		          andalso
       
    19 		          term_frees rhs subset term_frees lhs
       
    20 		          andalso
       
    21 		          term_tvars rhs subset term_tvars lhs
       
    22 		          andalso
       
    23 		          term_tfrees rhs subset term_tfrees lhs)
       
    24 	          ("Extra variables on RHS in definition of " ^ name)
       
    25   in (name ^ "_def", Logic.mk_equals (lhs, rhs)) end;
    17   in (name ^ "_def", Logic.mk_equals (lhs, rhs)) end;
    26 
    18 
    27 fun get_def thy s = get_axiom thy (s^"_def");
    19 fun get_def thy s = get_axiom thy (s^"_def");
    28 
    20 
    29 fun lookup_const sign a = Symtab.lookup(#const_tab (Sign.rep_sg sign), a);
    21 fun lookup_const sign a = Symtab.lookup(#const_tab (Sign.rep_sg sign), a);
    30 
       
    31 (*export to Pure/library?  *)
       
    32 fun assert_all pred l msg_fn = 
       
    33   let fun asl [] = ()
       
    34 	| asl (x::xs) = if pred x then asl xs
       
    35 	                else error (msg_fn x)
       
    36   in  asl l  end;
       
    37 
       
    38 
    22 
    39 (** Abstract syntax definitions for FOL and ZF **)
    23 (** Abstract syntax definitions for FOL and ZF **)
    40 
    24 
    41 val iT = Type("i",[])
    25 val iT = Type("i",[])
    42 and oT = Type("o",[]);
    26 and oT = Type("o",[]);
    76 fun mk_Collect (a,D,t) = Collect_const $ D $ absfree(a, iT, t);
    60 fun mk_Collect (a,D,t) = Collect_const $ D $ absfree(a, iT, t);
    77 
    61 
    78 val Trueprop = Const("Trueprop",oT-->propT);
    62 val Trueprop = Const("Trueprop",oT-->propT);
    79 fun mk_tprop P = Trueprop $ P;
    63 fun mk_tprop P = Trueprop $ P;
    80 
    64 
    81 (*Prove a goal stated as a term, with exception handling*)
       
    82 fun prove_term sign defs (P,tacsf) = 
       
    83     let val ct = cterm_of sign P
       
    84     in  prove_goalw_cterm defs ct tacsf
       
    85 	handle e => (writeln ("Exception in proof of\n" ^
       
    86 			       string_of_cterm ct); 
       
    87 		     raise e)
       
    88     end;
       
    89 
       
    90 (*Read an assumption in the given theory*)
    65 (*Read an assumption in the given theory*)
    91 fun assume_read thy a = assume (read_cterm (sign_of thy) (a,propT));
    66 fun assume_read thy a = assume (read_cterm (sign_of thy) (a,propT));
    92 
    67 
    93 fun readtm sign T a = 
    68 fun readtm sign T a = 
    94     read_cterm sign (a,T) |> term_of
    69     read_cterm sign (a,T) |> term_of
   124 	error"Premises may not be conjuctive"
    99 	error"Premises may not be conjuctive"
   125   | chk_prem rec_hd (Const("op :",_) $ t $ X) = 
   100   | chk_prem rec_hd (Const("op :",_) $ t $ X) = 
   126 	deny (Logic.occs(rec_hd,t)) "Recursion term on left of member symbol"
   101 	deny (Logic.occs(rec_hd,t)) "Recursion term on left of member symbol"
   127   | chk_prem rec_hd t = 
   102   | chk_prem rec_hd t = 
   128 	deny (Logic.occs(rec_hd,t)) "Recursion term in side formula";
   103 	deny (Logic.occs(rec_hd,t)) "Recursion term in side formula";
   129 
       
   130 
       
   131 (*Inverse of varifyT.  Move to Pure/type.ML?*)
       
   132 fun unvarifyT (Type (a, Ts)) = Type (a, map unvarifyT Ts)
       
   133   | unvarifyT (TVar ((a, 0), S)) = TFree (a, S)
       
   134   | unvarifyT T = T;
       
   135 
       
   136 (*Inverse of varify.  Move to Pure/logic.ML?*)
       
   137 fun unvarify (Const(a,T))    = Const(a, unvarifyT T)
       
   138   | unvarify (Var((a,0), T)) = Free(a, unvarifyT T)
       
   139   | unvarify (Var(ixn,T))    = Var(ixn, unvarifyT T)	(*non-zero index!*)
       
   140   | unvarify (Abs (a,T,body)) = Abs (a, unvarifyT T, unvarify body)
       
   141   | unvarify (f$t) = unvarify f $ unvarify t
       
   142   | unvarify t = t;
       
   143 
       
   144 
   104 
   145 (*Make distinct individual variables a1, a2, a3, ..., an. *)
   105 (*Make distinct individual variables a1, a2, a3, ..., an. *)
   146 fun mk_frees a [] = []
   106 fun mk_frees a [] = []
   147   | mk_frees a (T::Ts) = Free(a,T) :: mk_frees (bump_string a) Ts;
   107   | mk_frees a (T::Ts) = Free(a,T) :: mk_frees (bump_string a) Ts;
   148 
   108