src/Pure/drule.ML
changeset 214 ed6a3e2b1a33
parent 211 7ab45715c0a6
child 229 4002c4cd450c
equal deleted inserted replaced
213:42f2b8a3581f 214:ed6a3e2b1a33
    48   val prths: thm list -> thm list
    48   val prths: thm list -> thm list
    49   val read_instantiate: (string*string)list -> thm -> thm
    49   val read_instantiate: (string*string)list -> thm -> thm
    50   val read_instantiate_sg: Sign.sg -> (string*string)list -> thm -> thm
    50   val read_instantiate_sg: Sign.sg -> (string*string)list -> thm -> thm
    51   val reflexive_thm: thm
    51   val reflexive_thm: thm
    52   val revcut_rl: thm
    52   val revcut_rl: thm
    53   val rewrite_goal_rule: (meta_simpset -> thm -> thm option) -> meta_simpset ->
    53   val rewrite_goal_rule: bool*bool -> (meta_simpset -> thm -> thm option)
    54         int -> thm -> thm
    54         -> meta_simpset -> int -> thm -> thm
    55   val rewrite_goals_rule: thm list -> thm -> thm
    55   val rewrite_goals_rule: thm list -> thm -> thm
    56   val rewrite_rule: thm list -> thm -> thm
    56   val rewrite_rule: thm list -> thm -> thm
    57   val RS: thm * thm -> thm
    57   val RS: thm * thm -> thm
    58   val RSN: thm * (int * thm) -> thm
    58   val RSN: thm * (int * thm) -> thm
    59   val RL: thm list * thm list -> thm list
    59   val RL: thm list * thm list -> thm list
   374   let val xy = Sign.read_cterm Sign.pure ("x::'a::logic == y",propT)
   374   let val xy = Sign.read_cterm Sign.pure ("x::'a::logic == y",propT)
   375       val yz = Sign.read_cterm Sign.pure ("y::'a::logic == z",propT)
   375       val yz = Sign.read_cterm Sign.pure ("y::'a::logic == z",propT)
   376       val xythm = Thm.assume xy and yzthm = Thm.assume yz
   376       val xythm = Thm.assume xy and yzthm = Thm.assume yz
   377   in standard(Thm.implies_intr yz (Thm.transitive xythm yzthm)) end;
   377   in standard(Thm.implies_intr yz (Thm.transitive xythm yzthm)) end;
   378 
   378 
   379 
       
   380 (** Below, a "conversion" has type sign->term->thm **)
   379 (** Below, a "conversion" has type sign->term->thm **)
   381 
   380 
   382 (*In [A1,...,An]==>B, rewrite the selected A's only -- for rewrite_goals_tac*)
   381 (*In [A1,...,An]==>B, rewrite the selected A's only -- for rewrite_goals_tac*)
       
   382 (*Do not rewrite flex-flex pairs*)
   383 fun goals_conv pred cv sign = 
   383 fun goals_conv pred cv sign = 
   384   let val triv = reflexive o Sign.fake_cterm_of sign
   384   let val triv = reflexive o Sign.fake_cterm_of sign
   385       fun gconv i t =
   385       fun gconv i t =
   386         let val (A,B) = Logic.dest_implies t
   386         let val (A,B) = Logic.dest_implies t
   387 	    val thA = if (pred i) then (cv sign A) else (triv A)
   387             val (thA,j) = case A of
   388 	in  combination (combination (triv implies) thA)
   388                   Const("=?=",_)$_$_ => (triv A,i)
   389                         (gconv (i+1) B)
   389                 | _ => (if pred i then cv sign A else triv A, i+1)
   390         end
   390 	in  combination (combination (triv implies) thA) (gconv j B) end
   391         handle TERM _ => triv t
   391         handle TERM _ => triv t
   392   in gconv 1 end;
   392   in gconv 1 end;
   393 
   393 
   394 (*Use a conversion to transform a theorem*)
   394 (*Use a conversion to transform a theorem*)
   395 fun fconv_rule cv th =
   395 fun fconv_rule cv th =
   396   let val {sign,prop,...} = rep_thm th
   396   let val {sign,prop,...} = rep_thm th
   397   in  equal_elim (cv sign prop) th  end;
   397   in  equal_elim (cv sign prop) th  end;
   398 
   398 
   399 (*rewriting conversion*)
   399 (*rewriting conversion*)
   400 fun rew_conv prover mss sign t =
   400 fun rew_conv mode prover mss sign t =
   401   rewrite_cterm mss prover (Sign.fake_cterm_of sign t);
   401   rewrite_cterm mode mss prover (Sign.fake_cterm_of sign t);
   402 
   402 
   403 (*Rewrite a theorem*)
   403 (*Rewrite a theorem*)
   404 fun rewrite_rule thms = fconv_rule (rew_conv (K(K None)) (Thm.mss_of thms));
   404 fun rewrite_rule thms =
       
   405   fconv_rule (rew_conv (true,false) (K(K None)) (Thm.mss_of thms));
   405 
   406 
   406 (*Rewrite the subgoals of a proof state (represented by a theorem) *)
   407 (*Rewrite the subgoals of a proof state (represented by a theorem) *)
   407 fun rewrite_goals_rule thms =
   408 fun rewrite_goals_rule thms =
   408   fconv_rule (goals_conv (K true) (rew_conv (K(K None)) (Thm.mss_of thms)));
   409   fconv_rule (goals_conv (K true) (rew_conv (true,false) (K(K None))
       
   410              (Thm.mss_of thms)));
   409 
   411 
   410 (*Rewrite the subgoal of a proof state (represented by a theorem) *)
   412 (*Rewrite the subgoal of a proof state (represented by a theorem) *)
   411 fun rewrite_goal_rule prover mss i =
   413 fun rewrite_goal_rule mode prover mss i thm =
   412       fconv_rule (goals_conv (fn j => j=i) (rew_conv prover mss));
   414   if 0 < i  andalso  i <= nprems_of thm
       
   415   then fconv_rule (goals_conv (fn j => j=i) (rew_conv mode prover mss)) thm
       
   416   else raise THM("rewrite_goal_rule",i,[thm]);
   413 
   417 
   414 
   418 
   415 (** Derived rules mainly for METAHYPS **)
   419 (** Derived rules mainly for METAHYPS **)
   416 
   420 
   417 (*Given the term "a", takes (%x.t)==(%x.u) to t[a/x]==u[a/x]*)
   421 (*Given the term "a", takes (%x.t)==(%x.u) to t[a/x]==u[a/x]*)