src/Pure/thm.ML
changeset 2792 6c17c5ec3d8b
parent 2671 510d94c71dda
child 2962 97ae96c72d8c
equal deleted inserted replaced
2791:b65da0c53d94 2792:6c17c5ec3d8b
  1493 fun var_perm (t, u) =
  1493 fun var_perm (t, u) =
  1494   vperm (t, u) andalso eq_set_term (term_vars t, term_vars u);
  1494   vperm (t, u) andalso eq_set_term (term_vars t, term_vars u);
  1495 
  1495 
  1496 (*simple test for looping rewrite*)
  1496 (*simple test for looping rewrite*)
  1497 fun loops sign prems (lhs, rhs) =
  1497 fun loops sign prems (lhs, rhs) =
  1498    is_Var lhs
  1498    is_Var (head_of lhs)
  1499   orelse
  1499   orelse
  1500    (exists (apl (lhs, Logic.occs)) (rhs :: prems))
  1500    (exists (apl (lhs, Logic.occs)) (rhs :: prems))
  1501   orelse
  1501   orelse
  1502    (null prems andalso
  1502    (null prems andalso
  1503     Pattern.matches (#tsig (Sign.rep_sg sign)) (lhs, rhs));
  1503     Pattern.matches (#tsig (Sign.rep_sg sign)) (lhs, rhs));
  1710     (4) simplification procedures		(* FIXME (un-)conditional !! *)
  1710     (4) simplification procedures		(* FIXME (un-)conditional !! *)
  1711 *)
  1711 *)
  1712 
  1712 
  1713 fun rewritec (prover,signt) (mss as Mss{rules, procs, mk_rews, termless, ...}) 
  1713 fun rewritec (prover,signt) (mss as Mss{rules, procs, mk_rews, termless, ...}) 
  1714              (shypst,hypst,maxt,t,ders) =
  1714              (shypst,hypst,maxt,t,ders) =
  1715   let val etat = Pattern.eta_contract t;
  1715   let fun rew {thm as Thm{sign,der,maxidx,shyps,hyps,prop,...}, lhs, perm} =
  1716       fun rew {thm as Thm{sign,der,maxidx,shyps,hyps,prop,...}, lhs, perm} =
       
  1717         let val unit = if Sign.subsig(sign,signt) then ()
  1716         let val unit = if Sign.subsig(sign,signt) then ()
  1718                   else (trace_thm_warning "rewrite rule from different theory"
  1717                   else (trace_thm_warning "rewrite rule from different theory"
  1719                           thm;
  1718                           thm;
  1720                         raise Pattern.MATCH)
  1719                         raise Pattern.MATCH)
  1721             val rprop = if maxt = ~1 then prop
  1720             val rprop = if maxt = ~1 then prop
  1722                         else Logic.incr_indexes([],maxt+1) prop;
  1721                         else Logic.incr_indexes([],maxt+1) prop;
  1723             val rlhs = if maxt = ~1 then lhs
  1722             val rlhs = if maxt = ~1 then lhs
  1724                        else fst(Logic.dest_equals(Logic.strip_imp_concl rprop))
  1723                        else fst(Logic.dest_equals(Logic.strip_imp_concl rprop))
  1725             val insts = Pattern.match (#tsig(Sign.rep_sg signt)) (rlhs,etat)
  1724             val insts = Pattern.match (#tsig(Sign.rep_sg signt)) (rlhs,t)
  1726             val prop' = ren_inst(insts,rprop,rlhs,t);
  1725             val prop' = ren_inst(insts,rprop,rlhs,t);
  1727             val hyps' = union_term(hyps,hypst);
  1726             val hyps' = union_term(hyps,hypst);
  1728             val shyps' = add_insts_sorts (insts, union_sort(shyps,shypst));
  1727             val shyps' = add_insts_sorts (insts, union_sort(shyps,shypst));
  1729             val maxidx' = maxidx_of_term prop'
  1728             val maxidx' = maxidx_of_term prop'
  1730             val ct' = Cterm{sign = signt,       (*used for deriv only*)
  1729             val ct' = Cterm{sign = signt,       (*used for deriv only*)
  1764       in sort rrs ([],[]) 
  1763       in sort rrs ([],[]) 
  1765       end
  1764       end
  1766 
  1765 
  1767       fun proc_rews [] = None
  1766       fun proc_rews [] = None
  1768         | proc_rews ((f, _) :: fs) =
  1767         | proc_rews ((f, _) :: fs) =
  1769             (case f signt etat of
  1768             (case f signt t of
  1770               None => proc_rews fs
  1769               None => proc_rews fs
  1771             | Some raw_thm =>
  1770             | Some raw_thm =>
  1772                 (trace_thm "Proved rewrite rule: " raw_thm;
  1771                 (trace_thm "Proved rewrite rule: " raw_thm;
  1773                  (case rews (mk_procrule raw_thm) of
  1772                  (case rews (mk_procrule raw_thm) of
  1774                    None => proc_rews fs
  1773                    None => proc_rews fs
  1775                  | some => some)));
  1774                  | some => some)));
  1776   in
  1775   in
  1777     (case etat of
  1776     (case t of
  1778       Abs (_, _, body) $ u =>		(* FIXME bug!? (because of beta/eta overlap) *)
  1777       Abs (_, _, body) $ u =>		(* FIXME bug!? (because of beta/eta overlap) *)
  1779         Some (shypst, hypst, maxt, subst_bound (u, body), ders)
  1778         Some (shypst, hypst, maxt, subst_bound (u, body), ders)
  1780      | _ =>
  1779      | _ =>
  1781       (case rews (sort_rrules (Net.match_term rules etat)) of
  1780       (case rews (sort_rrules (Net.match_term rules t)) of
  1782         None => proc_rews (Net.match_term procs etat)
  1781         None => proc_rews (Net.match_term procs t)
  1783       | some => some))
  1782       | some => some))
  1784   end;
  1783   end;
  1785 
  1784 
  1786 
  1785 
  1787 (* conversion to apply a congruence rule to a term *)
  1786 (* conversion to apply a congruence rule to a term *)