src/Pure/thm.ML
changeset 8291 5469b894f30b
parent 8129 29e239c7b8c2
child 8296 c72122020380
equal deleted inserted replaced
8290:7015d6b11b56 8291:5469b894f30b
   267   else  Cterm {sign_ref = sign_ref, T = T, maxidx = maxidx_of_term t, t = t};
   267   else  Cterm {sign_ref = sign_ref, T = T, maxidx = maxidx_of_term t, t = t};
   268 
   268 
   269 (*Form cterm out of a function and an argument*)
   269 (*Form cterm out of a function and an argument*)
   270 fun capply (Cterm {t=f, sign_ref=sign_ref1, T=Type("fun",[dty,rty]), maxidx=maxidx1})
   270 fun capply (Cterm {t=f, sign_ref=sign_ref1, T=Type("fun",[dty,rty]), maxidx=maxidx1})
   271            (Cterm {t=x, sign_ref=sign_ref2, T, maxidx=maxidx2}) =
   271            (Cterm {t=x, sign_ref=sign_ref2, T, maxidx=maxidx2}) =
   272       if T = dty then Cterm{t=f$x, sign_ref=Sign.merge_refs(sign_ref1,sign_ref2), T=rty,
   272       if T = dty then
   273                             maxidx=Int.max(maxidx1, maxidx2)}
   273         Cterm{t=Sign.nodup_vars (f$x), sign_ref=Sign.merge_refs(sign_ref1,sign_ref2), T=rty,
       
   274           maxidx=Int.max(maxidx1, maxidx2)}
   274       else raise CTERM "capply: types don't agree"
   275       else raise CTERM "capply: types don't agree"
   275   | capply _ _ = raise CTERM "capply: first arg is not a function"
   276   | capply _ _ = raise CTERM "capply: first arg is not a function"
   276 
   277 
   277 fun cabs (Cterm {t=Free(a,ty), sign_ref=sign_ref1, T=T1, maxidx=maxidx1})
   278 fun cabs (Cterm {t=Free(a,ty), sign_ref=sign_ref1, T=T1, maxidx=maxidx1})
   278          (Cterm {t=t2, sign_ref=sign_ref2, T=T2, maxidx=maxidx2}) =
   279          (Cterm {t=t2, sign_ref=sign_ref2, T=T2, maxidx=maxidx2}) =
   279       Cterm {t=absfree(a,ty,t2), sign_ref=Sign.merge_refs(sign_ref1,sign_ref2),
   280       Cterm {t=Sign.nodup_vars (absfree(a,ty,t2)), sign_ref=Sign.merge_refs(sign_ref1,sign_ref2),
   280              T = ty --> T2, maxidx=Int.max(maxidx1, maxidx2)}
   281              T = ty --> T2, maxidx=Int.max(maxidx1, maxidx2)}
   281   | cabs _ _ = raise CTERM "cabs: first arg is not a free variable";
   282   | cabs _ _ = raise CTERM "cabs: first arg is not a free variable";
   282 
   283 
   283 
   284 
   284 
   285 
   642 (*** Meta rules ***)
   643 (*** Meta rules ***)
   643 
   644 
   644 (*Check that term does not contain same var with different typing/sorting.
   645 (*Check that term does not contain same var with different typing/sorting.
   645   If this check must be made, recalculate maxidx in hope of preventing its
   646   If this check must be made, recalculate maxidx in hope of preventing its
   646   recurrence.*)
   647   recurrence.*)
   647 fun nodup_Vars (thm as Thm{sign_ref, der, maxidx, shyps, hyps, prop}) s =
   648 fun nodup_vars (thm as Thm{sign_ref, der, maxidx, shyps, hyps, prop}) s =
   648   (Sign.nodup_Vars prop; 
   649   (Sign.nodup_vars prop; 
   649    Thm {sign_ref = sign_ref, 
   650    Thm {sign_ref = sign_ref, 
   650          der = der,     
   651          der = der,     
   651          maxidx = maxidx_of_term prop,
   652          maxidx = maxidx_of_term prop,
   652          shyps = shyps, 
   653          shyps = shyps, 
   653          hyps = hyps, 
   654          hyps = hyps, 
   654          prop = prop})
   655          prop = prop})
   655   handle TYPE(msg,Ts,ts) => raise TYPE(s^": "^msg,Ts,ts);
   656   handle TYPE(msg,Ts,ts) => raise TYPE(s^": "^msg,Ts,ts);
       
   657 
   656 
   658 
   657 (** 'primitive' rules **)
   659 (** 'primitive' rules **)
   658 
   660 
   659 (*discharge all assumptions t from ts*)
   661 (*discharge all assumptions t from ts*)
   660 val disch = gen_rem (op aconv);
   662 val disch = gen_rem (op aconv);
   761                          maxidx = Int.max(maxidx, maxt),
   763                          maxidx = Int.max(maxidx, maxt),
   762                          shyps = [],
   764                          shyps = [],
   763                          hyps = hyps,  
   765                          hyps = hyps,  
   764                          prop = betapply(A,t)})
   766                          prop = betapply(A,t)})
   765                in if maxt >= 0 andalso maxidx >= 0
   767                in if maxt >= 0 andalso maxidx >= 0
   766                   then nodup_Vars thm "forall_elim" 
   768                   then nodup_vars thm "forall_elim" 
   767                   else thm (*no new Vars: no expensive check!*)
   769                   else thm (*no new Vars: no expensive check!*)
   768                end
   770                end
   769       | _ => raise THM("forall_elim: not quantified", 0, [th])
   771       | _ => raise THM("forall_elim: not quantified", 0, [th])
   770   end
   772   end
   771   handle TERM _ =>
   773   handle TERM _ =>
   822                      maxidx = Int.max(max1,max2), 
   824                      maxidx = Int.max(max1,max2), 
   823                      shyps = [],
   825                      shyps = [],
   824                      hyps = union_term(hyps1,hyps2),
   826                      hyps = union_term(hyps1,hyps2),
   825                      prop = eq$t1$t2})
   827                      prop = eq$t1$t2})
   826                  in if max1 >= 0 andalso max2 >= 0
   828                  in if max1 >= 0 andalso max2 >= 0
   827                     then nodup_Vars thm "transitive" 
   829                     then nodup_vars thm "transitive" 
   828                     else thm (*no new Vars: no expensive check!*)
   830                     else thm (*no new Vars: no expensive check!*)
   829                  end
   831                  end
   830      | _ =>  err"premises"
   832      | _ =>  err"premises"
   831   end;
   833   end;
   832 
   834 
   927                             maxidx = Int.max(max1,max2), 
   929                             maxidx = Int.max(max1,max2), 
   928                             shyps = union_sort(shyps1,shyps2),
   930                             shyps = union_sort(shyps1,shyps2),
   929                             hyps = union_term(hyps1,hyps2),
   931                             hyps = union_term(hyps1,hyps2),
   930                             prop = Logic.mk_equals(f$t, g$u)}
   932                             prop = Logic.mk_equals(f$t, g$u)}
   931           in if max1 >= 0 andalso max2 >= 0
   933           in if max1 >= 0 andalso max2 >= 0
   932              then nodup_Vars thm "combination" 
   934              then nodup_vars thm "combination" 
   933              else thm (*no new Vars: no expensive check!*)  
   935              else thm (*no new Vars: no expensive check!*)  
   934           end
   936           end
   935      | _ =>  raise THM("combination: premises", 0, [th1,th2])
   937      | _ =>  raise THM("combination: premises", 0, [th1,th2])
   936   end;
   938   end;
   937 
   939 
  1082                    prop = newprop})
  1084                    prop = newprop})
  1083   in  if not(instl_ok(map #1 tpairs))
  1085   in  if not(instl_ok(map #1 tpairs))
  1084       then raise THM("instantiate: variables not distinct", 0, [th])
  1086       then raise THM("instantiate: variables not distinct", 0, [th])
  1085       else if not(null(findrep(map #1 vTs)))
  1087       else if not(null(findrep(map #1 vTs)))
  1086       then raise THM("instantiate: type variables not distinct", 0, [th])
  1088       then raise THM("instantiate: type variables not distinct", 0, [th])
  1087       else nodup_Vars newth "instantiate"
  1089       else nodup_vars newth "instantiate"
  1088   end
  1090   end
  1089   handle TERM _ => raise THM("instantiate: incompatible signatures", 0, [th])
  1091   handle TERM _ => raise THM("instantiate: incompatible signatures", 0, [th])
  1090        | TYPE (msg, _, _) => raise THM (msg, 0, [th]);
  1092        | TYPE (msg, _, _) => raise THM (msg, 0, [th]);
  1091 
  1093 
  1092 end;
  1094 end;
  1131         der = infer_derivs (VarifyT fixed, [der]), 
  1133         der = infer_derivs (VarifyT fixed, [der]), 
  1132         maxidx = Int.max(0,maxidx), 
  1134         maxidx = Int.max(0,maxidx), 
  1133         shyps = shyps, 
  1135         shyps = shyps, 
  1134         hyps = hyps,
  1136         hyps = hyps,
  1135         prop = Type.varify(prop,tfrees)}
  1137         prop = Type.varify(prop,tfrees)}
  1136      in nodup_Vars thm "varifyT" end
  1138      in nodup_vars thm "varifyT" end
  1137 (* this nodup_Vars check can be removed if thms are guaranteed not to contain
  1139 (* this nodup_vars check can be removed if thms are guaranteed not to contain
  1138 duplicate TVars with differnt sorts *)
  1140 duplicate TVars with different sorts *)
  1139   end;
  1141   end;
  1140 
  1142 
  1141 val varifyT = varifyT' [];
  1143 val varifyT = varifyT' [];
  1142 
  1144 
  1143 (* Replace all TVars by new TFrees *)
  1145 (* Replace all TVars by new TFrees *)