src/Pure/thm.ML
changeset 1023 f5f36bdc8003
parent 979 a29142d703bc
child 1028 88c8df00905b
equal deleted inserted replaced
1022:c4921e635bf7 1023:f5f36bdc8003
  1064 fun var_perm(t,u) = vperm(t,u) andalso
  1064 fun var_perm(t,u) = vperm(t,u) andalso
  1065                     eq_set(add_term_vars(t,[]), add_term_vars(u,[]))
  1065                     eq_set(add_term_vars(t,[]), add_term_vars(u,[]))
  1066 
  1066 
  1067 (*simple test for looping rewrite*)
  1067 (*simple test for looping rewrite*)
  1068 fun loops sign prems (lhs,rhs) =
  1068 fun loops sign prems (lhs,rhs) =
  1069   is_Var(lhs) orelse
  1069    is_Var(lhs)
  1070   (is_Free(lhs) andalso (exists (apl(lhs, Logic.occs)) (rhs::prems))) orelse
  1070   orelse
  1071   (null(prems) andalso
  1071    (exists (apl(lhs, Logic.occs)) (rhs::prems))
  1072    Pattern.matches (#tsig(Sign.rep_sg sign)) (lhs,rhs));
  1072   orelse
       
  1073    (null(prems) andalso
       
  1074     Pattern.matches (#tsig(Sign.rep_sg sign)) (lhs,rhs));
  1073 
  1075 
  1074 fun mk_rrule (thm as Thm{hyps,sign,prop,maxidx,...}) =
  1076 fun mk_rrule (thm as Thm{hyps,sign,prop,maxidx,...}) =
  1075   let val prems = Logic.strip_imp_prems prop
  1077   let val prems = Logic.strip_imp_prems prop
  1076       val concl = Logic.strip_imp_concl prop
  1078       val concl = Logic.strip_imp_concl prop
  1077       val (lhs,_) = Logic.dest_equals concl handle TERM _ =>
  1079       val (lhs,_) = Logic.dest_equals concl handle TERM _ =>
  1228                           thm;
  1230                           thm;
  1229                         raise Pattern.MATCH)
  1231                         raise Pattern.MATCH)
  1230             val insts = Pattern.match (#tsig(Sign.rep_sg signt)) (lhs,etat)
  1232             val insts = Pattern.match (#tsig(Sign.rep_sg signt)) (lhs,etat)
  1231             val prop' = ren_inst(insts,prop,lhs,t);
  1233             val prop' = ren_inst(insts,prop,lhs,t);
  1232             val hyps' = hyps union hypst;
  1234             val hyps' = hyps union hypst;
  1233             val thm' = Thm{sign=signt, hyps=hyps', prop=prop', maxidx=maxidx}
  1235             val thm' = Thm{sign=signt, hyps=hyps', prop=prop',
       
  1236                            maxidx=maxidx_of_term prop'}
  1234             val (lhs',rhs') = Logic.dest_equals(Logic.strip_imp_concl prop')
  1237             val (lhs',rhs') = Logic.dest_equals(Logic.strip_imp_concl prop')
  1235         in if perm andalso not(termless(rhs',lhs')) then None else
  1238         in if perm andalso not(termless(rhs',lhs')) then None else
  1236            if Logic.count_prems(prop',0) = 0
  1239            if Logic.count_prems(prop',0) = 0
  1237            then (trace_thm "Rewriting:" thm'; Some(hyps',rhs'))
  1240            then (trace_thm "Rewriting:" thm'; Some(hyps',rhs'))
  1238            else (trace_thm "Trying to rewrite:" thm';
  1241            else (trace_thm "Trying to rewrite:" thm';
  1259       val tsig = #tsig(Sign.rep_sg signt)
  1262       val tsig = #tsig(Sign.rep_sg signt)
  1260       val insts = Pattern.match tsig (lhs,t) handle Pattern.MATCH =>
  1263       val insts = Pattern.match tsig (lhs,t) handle Pattern.MATCH =>
  1261                   error("Congruence rule did not match")
  1264                   error("Congruence rule did not match")
  1262       val prop' = ren_inst(insts,prop,lhs,t);
  1265       val prop' = ren_inst(insts,prop,lhs,t);
  1263       val thm' = Thm{sign=signt, hyps=hyps union hypst,
  1266       val thm' = Thm{sign=signt, hyps=hyps union hypst,
  1264                      prop=prop', maxidx=maxidx}
  1267                      prop=prop', maxidx=maxidx_of_term prop'}
  1265       val unit = trace_thm "Applying congruence rule" thm';
  1268       val unit = trace_thm "Applying congruence rule" thm';
  1266       fun err() = error("Failed congruence proof!")
  1269       fun err() = error("Failed congruence proof!")
  1267 
  1270 
  1268   in case prover thm' of
  1271   in case prover thm' of
  1269        None => err()
  1272        None => err()