src/HOL/Tools/TFL/usyntax.ML
changeset 38549 d0385f2764d8
parent 37678 0040bafffdef
child 38554 f8999e19dd49
equal deleted inserted replaced
38548:dea0d2cca822 38549:d0385f2764d8
   157   | mk_abs{Bvar as Free(s,ty),Body}  = Abs(s,ty,abstract_over(Bvar,Body))
   157   | mk_abs{Bvar as Free(s,ty),Body}  = Abs(s,ty,abstract_over(Bvar,Body))
   158   | mk_abs _ = raise USYN_ERR "mk_abs" "Bvar is not a variable";
   158   | mk_abs _ = raise USYN_ERR "mk_abs" "Bvar is not a variable";
   159 
   159 
   160 
   160 
   161 fun mk_imp{ant,conseq} =
   161 fun mk_imp{ant,conseq} =
   162    let val c = Const("op -->",HOLogic.boolT --> HOLogic.boolT --> HOLogic.boolT)
   162    let val c = Const(@{const_name "op -->"},HOLogic.boolT --> HOLogic.boolT --> HOLogic.boolT)
   163    in list_comb(c,[ant,conseq])
   163    in list_comb(c,[ant,conseq])
   164    end;
   164    end;
   165 
   165 
   166 fun mk_select (r as {Bvar,Body}) =
   166 fun mk_select (r as {Bvar,Body}) =
   167   let val ty = type_of Bvar
   167   let val ty = type_of Bvar
   169   in list_comb(c,[mk_abs r])
   169   in list_comb(c,[mk_abs r])
   170   end;
   170   end;
   171 
   171 
   172 fun mk_forall (r as {Bvar,Body}) =
   172 fun mk_forall (r as {Bvar,Body}) =
   173   let val ty = type_of Bvar
   173   let val ty = type_of Bvar
   174       val c = Const("All",(ty --> HOLogic.boolT) --> HOLogic.boolT)
   174       val c = Const(@{const_name "All"},(ty --> HOLogic.boolT) --> HOLogic.boolT)
   175   in list_comb(c,[mk_abs r])
   175   in list_comb(c,[mk_abs r])
   176   end;
   176   end;
   177 
   177 
   178 fun mk_exists (r as {Bvar,Body}) =
   178 fun mk_exists (r as {Bvar,Body}) =
   179   let val ty = type_of Bvar
   179   let val ty = type_of Bvar
   180       val c = Const("Ex",(ty --> HOLogic.boolT) --> HOLogic.boolT)
   180       val c = Const(@{const_name "Ex"},(ty --> HOLogic.boolT) --> HOLogic.boolT)
   181   in list_comb(c,[mk_abs r])
   181   in list_comb(c,[mk_abs r])
   182   end;
   182   end;
   183 
   183 
   184 
   184 
   185 fun mk_conj{conj1,conj2} =
   185 fun mk_conj{conj1,conj2} =
   186    let val c = Const("op &",HOLogic.boolT --> HOLogic.boolT --> HOLogic.boolT)
   186    let val c = Const(@{const_name "op &"},HOLogic.boolT --> HOLogic.boolT --> HOLogic.boolT)
   187    in list_comb(c,[conj1,conj2])
   187    in list_comb(c,[conj1,conj2])
   188    end;
   188    end;
   189 
   189 
   190 fun mk_disj{disj1,disj2} =
   190 fun mk_disj{disj1,disj2} =
   191    let val c = Const("op |",HOLogic.boolT --> HOLogic.boolT --> HOLogic.boolT)
   191    let val c = Const(@{const_name "op |"},HOLogic.boolT --> HOLogic.boolT --> HOLogic.boolT)
   192    in list_comb(c,[disj1,disj2])
   192    in list_comb(c,[disj1,disj2])
   193    end;
   193    end;
   194 
   194 
   195 fun prod_ty ty1 ty2 = HOLogic.mk_prodT (ty1,ty2);
   195 fun prod_ty ty1 ty2 = HOLogic.mk_prodT (ty1,ty2);
   196 
   196 
   242        val v = Free(s', ty);
   242        val v = Free(s', ty);
   243      in ({Bvar = v, Body = Term.betapply (a,v)}, s'::used)
   243      in ({Bvar = v, Body = Term.betapply (a,v)}, s'::used)
   244      end
   244      end
   245   | dest_abs _ _ =  raise USYN_ERR "dest_abs" "not an abstraction";
   245   | dest_abs _ _ =  raise USYN_ERR "dest_abs" "not an abstraction";
   246 
   246 
   247 fun dest_eq(Const("op =",_) $ M $ N) = {lhs=M, rhs=N}
   247 fun dest_eq(Const(@{const_name "op ="},_) $ M $ N) = {lhs=M, rhs=N}
   248   | dest_eq _ = raise USYN_ERR "dest_eq" "not an equality";
   248   | dest_eq _ = raise USYN_ERR "dest_eq" "not an equality";
   249 
   249 
   250 fun dest_imp(Const("op -->",_) $ M $ N) = {ant=M, conseq=N}
   250 fun dest_imp(Const(@{const_name "op -->"},_) $ M $ N) = {ant=M, conseq=N}
   251   | dest_imp _ = raise USYN_ERR "dest_imp" "not an implication";
   251   | dest_imp _ = raise USYN_ERR "dest_imp" "not an implication";
   252 
   252 
   253 fun dest_forall(Const("All",_) $ (a as Abs _)) = fst (dest_abs [] a)
   253 fun dest_forall(Const(@{const_name "All"},_) $ (a as Abs _)) = fst (dest_abs [] a)
   254   | dest_forall _ = raise USYN_ERR "dest_forall" "not a forall";
   254   | dest_forall _ = raise USYN_ERR "dest_forall" "not a forall";
   255 
   255 
   256 fun dest_exists(Const("Ex",_) $ (a as Abs _)) = fst (dest_abs [] a)
   256 fun dest_exists(Const(@{const_name "Ex"},_) $ (a as Abs _)) = fst (dest_abs [] a)
   257   | dest_exists _ = raise USYN_ERR "dest_exists" "not an existential";
   257   | dest_exists _ = raise USYN_ERR "dest_exists" "not an existential";
   258 
   258 
   259 fun dest_neg(Const("not",_) $ M) = M
   259 fun dest_neg(Const("not",_) $ M) = M
   260   | dest_neg _ = raise USYN_ERR "dest_neg" "not a negation";
   260   | dest_neg _ = raise USYN_ERR "dest_neg" "not a negation";
   261 
   261 
   262 fun dest_conj(Const("op &",_) $ M $ N) = {conj1=M, conj2=N}
   262 fun dest_conj(Const(@{const_name "op &"},_) $ M $ N) = {conj1=M, conj2=N}
   263   | dest_conj _ = raise USYN_ERR "dest_conj" "not a conjunction";
   263   | dest_conj _ = raise USYN_ERR "dest_conj" "not a conjunction";
   264 
   264 
   265 fun dest_disj(Const("op |",_) $ M $ N) = {disj1=M, disj2=N}
   265 fun dest_disj(Const(@{const_name "op |"},_) $ M $ N) = {disj1=M, disj2=N}
   266   | dest_disj _ = raise USYN_ERR "dest_disj" "not a disjunction";
   266   | dest_disj _ = raise USYN_ERR "dest_disj" "not a disjunction";
   267 
   267 
   268 fun mk_pair{fst,snd} =
   268 fun mk_pair{fst,snd} =
   269    let val ty1 = type_of fst
   269    let val ty1 = type_of fst
   270        val ty2 = type_of snd
   270        val ty2 = type_of snd
   400 
   400 
   401 fun is_WFR (Const(@{const_name Wellfounded.wf},_)$_) = true
   401 fun is_WFR (Const(@{const_name Wellfounded.wf},_)$_) = true
   402   | is_WFR _                 = false;
   402   | is_WFR _                 = false;
   403 
   403 
   404 fun ARB ty = mk_select{Bvar=Free("v",ty),
   404 fun ARB ty = mk_select{Bvar=Free("v",ty),
   405                        Body=Const("True",HOLogic.boolT)};
   405                        Body=Const(@{const_name "True"},HOLogic.boolT)};
   406 
   406 
   407 end;
   407 end;