src/HOL/Modelcheck/mucke_oracle.ML
changeset 20194 c9dbce9a23a1
parent 20071 8f3e1ddb50e6
child 22596 d0d2af4db18f
equal deleted inserted replaced
20193:46f5ef758422 20194:c9dbce9a23a1
    49   end |
    49   end |
    50   contains_if (a $ b) = if ((contains_if b)=[]) then (contains_if a)
    50   contains_if (a $ b) = if ((contains_if b)=[]) then (contains_if a)
    51 		        else (contains_if b) |
    51 		        else (contains_if b) |
    52   contains_if _ = [];
    52   contains_if _ = [];
    53 
    53 
    54   fun find_replace_term (Abs(a,T,t)) = find_replace_term (snd(variant_abs(a,T,t))) |
    54   fun find_replace_term (Abs(a,T,t)) = find_replace_term (snd(Syntax.variant_abs(a,T,t))) |
    55   find_replace_term (a $ b) = if ((contains_if (a $ b))=[]) then
    55   find_replace_term (a $ b) = if ((contains_if (a $ b))=[]) then
    56   (if (snd(find_replace_term b)=[]) then (find_replace_term a) else (find_replace_term b))
    56   (if (snd(find_replace_term b)=[]) then (find_replace_term a) else (find_replace_term b))
    57   else (a $ b,contains_if(a $ b))|
    57   else (a $ b,contains_if(a $ b))|
    58   find_replace_term t = (t,[]);
    58   find_replace_term t = (t,[]);
    59 
    59 
   165 
   165 
   166 (* delivers type of a term *)
   166 (* delivers type of a term *)
   167 fun type_of_term (Const(_,t)) = t |
   167 fun type_of_term (Const(_,t)) = t |
   168 type_of_term (Free(_,t)) = t |
   168 type_of_term (Free(_,t)) = t |
   169 type_of_term (Var(_,t)) = t |
   169 type_of_term (Var(_,t)) = t |
   170 type_of_term (Abs(x,t,trm)) = Type("fun",[t,type_of_term(snd(variant_abs(x,t,trm)))]) |
   170 type_of_term (Abs(x,t,trm)) = Type("fun",[t,type_of_term(snd(Syntax.variant_abs(x,t,trm)))]) |
   171 type_of_term (a $ b) =
   171 type_of_term (a $ b) =
   172 let
   172 let
   173  fun accept_fun_type (Type("fun",[x,y])) = (x,y) |
   173  fun accept_fun_type (Type("fun",[x,y])) = (x,y) |
   174  accept_fun_type _ =
   174  accept_fun_type _ =
   175  error "no function type returned, where it was expected (in type_of_term)";
   175  error "no function type returned, where it was expected (in type_of_term)";
   320 
   320 
   321 fun dest_atom (Const t) = dest_Const (Const t)
   321 fun dest_atom (Const t) = dest_Const (Const t)
   322   | dest_atom (Free t)  = dest_Free (Free t);
   322   | dest_atom (Free t)  = dest_Free (Free t);
   323 
   323 
   324 fun get_decls sign Clist (Abs(s,tp,trm)) = 
   324 fun get_decls sign Clist (Abs(s,tp,trm)) = 
   325     let val VarAbs = variant_abs(s,tp,trm);
   325     let val VarAbs = Syntax.variant_abs(s,tp,trm);
   326     in get_decls sign (Const(fst VarAbs,tp)::Clist) (snd VarAbs)
   326     in get_decls sign (Const(fst VarAbs,tp)::Clist) (snd VarAbs)
   327     end
   327     end
   328   | get_decls sign Clist ((Const("split",_)) $ trm) = get_decls sign Clist trm
   328   | get_decls sign Clist ((Const("split",_)) $ trm) = get_decls sign Clist trm
   329   | get_decls sign Clist trm = (Clist,trm);
   329   | get_decls sign Clist trm = (Clist,trm);
   330 
   330 
   427 in MuckeDeclTerm end;
   427 in MuckeDeclTerm end;
   428 
   428 
   429 fun elim_quantifications sign ((Const("Ex",_)) $ Abs (str,tp,t)) =
   429 fun elim_quantifications sign ((Const("Ex",_)) $ Abs (str,tp,t)) =
   430     (let val ExConst = Const("_Ex",make_fun_type [tp,tp,tp,tp]);
   430     (let val ExConst = Const("_Ex",make_fun_type [tp,tp,tp,tp]);
   431      	 val TypeConst = Const (type_to_string_OUTPUT tp,tp);
   431      	 val TypeConst = Const (type_to_string_OUTPUT tp,tp);
   432 	 val VarAbs = variant_abs(str,tp,t);
   432 	 val VarAbs = Syntax.variant_abs(str,tp,t);
   433 	 val BoundConst = Const(fst VarAbs,tp);
   433 	 val BoundConst = Const(fst VarAbs,tp);
   434 	 val t1 = ExConst $ TypeConst;
   434 	 val t1 = ExConst $ TypeConst;
   435 	 val t2 = t1 $ BoundConst;
   435 	 val t2 = t1 $ BoundConst;
   436  	 val t3 = elim_quantifications sign (snd VarAbs)
   436  	 val t3 = elim_quantifications sign (snd VarAbs)
   437      in t2 $ t3 end)
   437      in t2 $ t3 end)
   438   |  elim_quantifications sign ((Const("All",_)) $ Abs (str,tp,t)) =
   438   |  elim_quantifications sign ((Const("All",_)) $ Abs (str,tp,t)) =
   439     (let val AllConst = Const("_All",make_fun_type [tp,tp,tp,tp]);
   439     (let val AllConst = Const("_All",make_fun_type [tp,tp,tp,tp]);
   440     	 val TypeConst = Const (type_to_string_OUTPUT tp,tp);
   440     	 val TypeConst = Const (type_to_string_OUTPUT tp,tp);
   441 	 val VarAbs = variant_abs(str,tp,t);
   441 	 val VarAbs = Syntax.variant_abs(str,tp,t);
   442 	 val BoundConst = Const(fst VarAbs,tp);
   442 	 val BoundConst = Const(fst VarAbs,tp);
   443 	 val t1 = AllConst $ TypeConst;
   443 	 val t1 = AllConst $ TypeConst;
   444 	 val t2 = t1 $ BoundConst;
   444 	 val t2 = t1 $ BoundConst;
   445 	 val t3 = elim_quantifications sign (snd VarAbs)
   445 	 val t3 = elim_quantifications sign (snd VarAbs)
   446      in t2 $ t3 end)
   446      in t2 $ t3 end)
   604 (* enrich_case_with_terms enriches a case term with additional *)
   604 (* enrich_case_with_terms enriches a case term with additional *)
   605 (* conditions according to the context of the case replacement *)
   605 (* conditions according to the context of the case replacement *)
   606 fun enrich_case_with_terms sg [] t = t |
   606 fun enrich_case_with_terms sg [] t = t |
   607 enrich_case_with_terms sg [trm] (Abs(x,T,t)) =
   607 enrich_case_with_terms sg [trm] (Abs(x,T,t)) =
   608 let
   608 let
   609  val v = variant_abs(x,T,t);
   609  val v = Syntax.variant_abs(x,T,t);
   610  val f = fst v;
   610  val f = fst v;
   611  val s = snd v
   611  val s = snd v
   612 in
   612 in
   613 (Const("Ex",Type("fun",[Type("fun",[T,Type("bool",[])]),Type("bool",[])])) $
   613 (Const("Ex",Type("fun",[Type("fun",[T,Type("bool",[])]),Type("bool",[])])) $
   614 (Abs(x,T,
   614 (Abs(x,T,
   632 enrich_case_with_terms sg r (trm $ (Bound(length(r))))))
   632 enrich_case_with_terms sg r (trm $ (Bound(length(r))))))
   633 end;
   633 end;
   634 
   634 
   635 fun replace_termlist_with_constrs sg tl (a::l1) (c::l2) t = 
   635 fun replace_termlist_with_constrs sg tl (a::l1) (c::l2) t = 
   636 let
   636 let
   637  fun heart_of_trm (Abs(x,T,t)) = heart_of_trm(snd(variant_abs(x,T,t))) |
   637  fun heart_of_trm (Abs(x,T,t)) = heart_of_trm(snd(Syntax.variant_abs(x,T,t))) |
   638  heart_of_trm t = t;
   638  heart_of_trm t = t;
   639  fun replace_termlist_with_args _ _ trm _ [] _ ([],[]) = trm (* should never occur *) |
   639  fun replace_termlist_with_args _ _ trm _ [] _ ([],[]) = trm (* should never occur *) |
   640  replace_termlist_with_args sg _ trm _ [a] _ ([],[]) =
   640  replace_termlist_with_args sg _ trm _ [a] _ ([],[]) =
   641 	if ((heart_of_trm trm)= Const("False",Type("bool",[]))) then trm else 
   641 	if ((heart_of_trm trm)= Const("False",Type("bool",[]))) then trm else 
   642 	(enrich_case_with_terms sg a trm) |
   642 	(enrich_case_with_terms sg a trm) |
   702 end |
   702 end |
   703 replace_case sg tl (a $ b) 1 = a $ (replace_case sg tl b 0) |
   703 replace_case sg tl (a $ b) 1 = a $ (replace_case sg tl b 0) |
   704 replace_case sg tl (a $ b) n = (replace_case sg tl a (n-1)) $ (replace_case sg tl b 0) |
   704 replace_case sg tl (a $ b) n = (replace_case sg tl a (n-1)) $ (replace_case sg tl b 0) |
   705 replace_case sg tl (Abs(x,T,t)) _ = 
   705 replace_case sg tl (Abs(x,T,t)) _ = 
   706 let 
   706 let 
   707  val v = variant_abs(x,T,t);
   707  val v = Syntax.variant_abs(x,T,t);
   708  val f = fst v;
   708  val f = fst v;
   709  val s = snd v
   709  val s = snd v
   710 in
   710 in
   711  Abs(x,T,abstract_over(Free(f,T),replace_case sg tl s 0))
   711  Abs(x,T,abstract_over(Free(f,T),replace_case sg tl s 0))
   712 end |
   712 end |
   777  else
   777  else
   778  (if (constr_term_contains_var sg tl a x) then true 
   778  (if (constr_term_contains_var sg tl a x) then true 
   779   else (constr_term_contains_var sg tl b x))
   779   else (constr_term_contains_var sg tl b x))
   780 end |
   780 end |
   781 constr_term_contains_var sg tl (Abs(y,ty,trm)) x =
   781 constr_term_contains_var sg tl (Abs(y,ty,trm)) x =
   782          constr_term_contains_var sg tl (snd(variant_abs(y,ty,trm))) x |
   782          constr_term_contains_var sg tl (snd(Syntax.variant_abs(y,ty,trm))) x |
   783 constr_term_contains_var _ _ _ _ = false;
   783 constr_term_contains_var _ _ _ _ = false;
   784 val vt = variant_abs(x,ty,trm);
   784 val vt = Syntax.variant_abs(x,ty,trm);
   785 val tt = remove_vars sg tl (snd(vt))
   785 val tt = remove_vars sg tl (snd(vt))
   786 in
   786 in
   787 if (constr_term_contains_var sg tl tt (fst vt))
   787 if (constr_term_contains_var sg tl tt (fst vt))
   788 (* fst vt muss frei vorkommen, als ECHTER TeilKonstruktorterm *)
   788 (* fst vt muss frei vorkommen, als ECHTER TeilKonstruktorterm *)
   789 then (Abs(x,ty,
   789 then (Abs(x,ty,