src/Pure/logic.ML
changeset 4822 2733e21814fe
parent 4693 2e47ea2c6109
child 5041 a1d0a6d555cd
equal deleted inserted replaced
4821:bfbaea156f43 4822:2733e21814fe
    24   val is_equals         : term -> bool
    24   val is_equals         : term -> bool
    25   val lift_fns		: term * int -> (term -> term) * (term -> term)
    25   val lift_fns		: term * int -> (term -> term) * (term -> term)
    26   val list_flexpairs	: (term*term)list * term -> term
    26   val list_flexpairs	: (term*term)list * term -> term
    27   val list_implies	: term list * term -> term
    27   val list_implies	: term list * term -> term
    28   val list_rename_params: string list * term -> term
    28   val list_rename_params: string list * term -> term
       
    29   val mk_cond_defpair	: term list -> term * term -> string * term
       
    30   val mk_defpair	: term * term -> string * term
    29   val mk_equals		: term * term -> term
    31   val mk_equals		: term * term -> term
    30   val mk_flexpair	: term * term -> term
    32   val mk_flexpair	: term * term -> term
    31   val mk_implies	: term * term -> term
    33   val mk_implies	: term * term -> term
    32   val mk_inclass	: typ * class -> term
    34   val mk_inclass	: typ * class -> term
    33   val mk_type		: typ -> term
    35   val mk_type		: typ -> term
    70 fun mk_implies(A,B) = implies $ A $ B;
    72 fun mk_implies(A,B) = implies $ A $ B;
    71 
    73 
    72 fun dest_implies (Const("==>",_) $ A $ B)  =  (A,B)
    74 fun dest_implies (Const("==>",_) $ A $ B)  =  (A,B)
    73   | dest_implies A = raise TERM("dest_implies", [A]);
    75   | dest_implies A = raise TERM("dest_implies", [A]);
    74 
    76 
       
    77 
    75 (** nested implications **)
    78 (** nested implications **)
    76 
    79 
    77 (* [A1,...,An], B  goes to  A1==>...An==>B  *)
    80 (* [A1,...,An], B  goes to  A1==>...An==>B  *)
    78 fun list_implies ([], B) = B : term
    81 fun list_implies ([], B) = B : term
    79   | list_implies (A::AS, B) = implies $ A $ list_implies(AS,B);
    82   | list_implies (A::AS, B) = implies $ A $ list_implies(AS,B);
    96 
    99 
    97 (*Count premises -- quicker than (length ostrip_prems) *)
   100 (*Count premises -- quicker than (length ostrip_prems) *)
    98 fun count_prems (Const("==>", _) $ A $ B, n) = count_prems (B,n+1)
   101 fun count_prems (Const("==>", _) $ A $ B, n) = count_prems (B,n+1)
    99   | count_prems (_,n) = n;
   102   | count_prems (_,n) = n;
   100 
   103 
       
   104 
   101 (** flex-flex constraints **)
   105 (** flex-flex constraints **)
   102 
   106 
   103 (*Make a constraint.*)
   107 (*Make a constraint.*)
   104 fun mk_flexpair(t,u) = flexpair(fastype_of t) $ t $ u;
   108 fun mk_flexpair(t,u) = flexpair(fastype_of t) $ t $ u;
   105 
   109 
   134     goes to   ( [(a1,b1),...,(am,bm)] , [B1,...,Bn] , C)    *)
   138     goes to   ( [(a1,b1),...,(am,bm)] , [B1,...,Bn] , C)    *)
   135 fun strip_horn A =
   139 fun strip_horn A =
   136   let val (tpairs,horn) = strip_flexpairs A 
   140   let val (tpairs,horn) = strip_flexpairs A 
   137   in  (tpairs, strip_imp_prems horn, strip_imp_concl horn)   end;
   141   in  (tpairs, strip_imp_prems horn, strip_imp_concl horn)   end;
   138 
   142 
       
   143 
       
   144 (** definitions **)
       
   145 
       
   146 fun mk_cond_defpair As (lhs, rhs) =
       
   147   (case Term.head_of lhs of
       
   148     Const (name, _) =>
       
   149       (Sign.base_name name ^ "_def", list_implies (As, mk_equals (lhs, rhs)))
       
   150   | _ => raise TERM ("Malformed definition: head of lhs not a constant", [lhs, rhs]));
       
   151 
       
   152 fun mk_defpair lhs_rhs = mk_cond_defpair [] lhs_rhs;
       
   153 
       
   154 
   139 (** types as terms **)
   155 (** types as terms **)
   140 
   156 
   141 fun mk_type ty = Const ("TYPE", itselfT ty);
   157 fun mk_type ty = Const ("TYPE", itselfT ty);
   142 
   158 
   143 fun dest_type (Const ("TYPE", Type ("itself", [ty]))) = ty
   159 fun dest_type (Const ("TYPE", Type ("itself", [ty]))) = ty
   144   | dest_type t = raise TERM ("dest_type", [t]);
   160   | dest_type t = raise TERM ("dest_type", [t]);
       
   161 
   145 
   162 
   146 (** class constraints **)
   163 (** class constraints **)
   147 
   164 
   148 fun mk_inclass (ty, c) =
   165 fun mk_inclass (ty, c) =
   149   Const (Sign.const_of_class c, itselfT ty --> propT) $ mk_type ty;
   166   Const (Sign.const_of_class c, itselfT ty --> propT) $ mk_type ty;