# HG changeset patch # User bulwahn # Date 1256396142 -7200 # Node ID 1413c62db67500492ec4397d982e41a4c702b9d0 # Parent b379ee2cddb11702e5b201776955fd7007b9b112 higher-order arguments in different rules are fixed to one name in the predicate compiler diff -r b379ee2cddb1 -r 1413c62db675 src/HOL/Tools/Predicate_Compile/predicate_compile_core.ML --- a/src/HOL/Tools/Predicate_Compile/predicate_compile_core.ML Sat Oct 24 16:55:42 2009 +0200 +++ b/src/HOL/Tools/Predicate_Compile/predicate_compile_core.ML Sat Oct 24 16:55:42 2009 +0200 @@ -258,23 +258,33 @@ (* generation of case rules from user-given introduction rules *) +(* how to detect polymorphic type dependencies in mutual recursive inductive predicates? *) fun import_intros [] ctxt = ([], ctxt) | import_intros (th :: ths) ctxt = let val ((_, [th']), ctxt') = Variable.import false [th] ctxt - val (pred, _) = strip_intro_concl 0 (prop_of th') + val thy = ProofContext.theory_of ctxt' + val (pred, ([], args)) = strip_intro_concl 0 (prop_of th') + val ho_args = filter (is_predT o fastype_of) args fun instantiate_typ th = let val (pred', _) = strip_intro_concl 0 (prop_of th) - val subst = Sign.typ_match (ProofContext.theory_of ctxt') + val _ = if not (fst (dest_Const pred) = fst (dest_Const pred')) then + error "Trying to instantiate another predicate" else () + val subst = Sign.typ_match thy (fastype_of pred', fastype_of pred) Vartab.empty val _ = Output.tracing (commas (map (fn ((x, i), (s, T)) => x ^ " instantiate to " ^ (Syntax.string_of_typ ctxt' T)) (Vartab.dest subst))) val subst' = map (fn (indexname, (s, T)) => ((indexname, s), T)) (Vartab.dest subst) in Thm.certify_instantiate (subst', []) th end; + fun instantiate_ho_args th = + let + val (_, (_, args')) = strip_intro_concl 0 (prop_of th) + val ho_args' = map dest_Var (filter (is_predT o fastype_of) args') + in Thm.certify_instantiate ([], ho_args' ~~ ho_args) th end val ((_, ths'), ctxt1) = - Variable.import false (map instantiate_typ ths) ctxt' + Variable.import false (map (instantiate_typ #> instantiate_ho_args) ths) ctxt' in (th' :: ths', ctxt1) end diff -r b379ee2cddb1 -r 1413c62db675 src/HOL/ex/Predicate_Compile_ex.thy --- a/src/HOL/ex/Predicate_Compile_ex.thy Sat Oct 24 16:55:42 2009 +0200 +++ b/src/HOL/ex/Predicate_Compile_ex.thy Sat Oct 24 16:55:42 2009 +0200 @@ -446,7 +446,7 @@ code_pred (inductify_all) S\<^isub>1p . thm S\<^isub>1p.equation -(* + theorem S\<^isub>1_sound: "w \ S\<^isub>1 \ length [x \ w. x = a] = length [x \ w. x = b]" quickcheck[generator=pred_compile] @@ -477,9 +477,8 @@ | "w \ S\<^isub>3 \ b # w \ B\<^isub>3" | "\v \ B\<^isub>3; w \ B\<^isub>3\ \ a # v @ w \ B\<^isub>3" -(* code_pred (inductify_all) S\<^isub>3 . -*) + theorem S\<^isub>3_sound: "w \ S\<^isub>3 \ length [x \ w. x = a] = length [x \ w. x = b]" quickcheck[generator=pred_compile, size=10, iterations=1] @@ -488,7 +487,7 @@ lemma "\ (length w > 2) \ \ (length [x \ w. x = a] = length [x \ w. x = b])" quickcheck[size=10, generator = pred_compile] oops -*) + inductive test where "length [x \ w. x = a] = length [x \ w. x = b] ==> test w"