theory Scratch imports "HOL-Library.Rewrite" begin (* A useful lemma *) lemma sum_single: assumes "finite A" assumes "\j. j \ i \ j\A \ f j = 0" shows "sum f A = (if i\A then f i else 0)" apply (subst sum.mono_neutral_cong_right[where S=\A \ {i}\ and h=f]) using assms by auto lemma \(\x::bool\UNIV. (\y\UNIV. of_bool (x=y))) = 2\ (* Lets rewrite the inner sum with sum_single. *) apply (rewrite at \\x\UNIV. \\ sum_single) (* This gives us the schematic variable ?i8 that we would like to instantiate with x *) oops lemma \(\x::bool\UNIV. (\y\UNIV. of_bool (x=y))) = 2\ apply (rewrite at \\x\UNIV. \\ sum_single where ?i=x) (* Error (this syntax has been removed, it seems) *) oops lemma \(\x::bool\UNIV. (\y\UNIV. of_bool (x=y))) = 2\ (* Trying to instantiate. *) apply (rewrite at \\x\UNIV. \\ to \if x\_ then _ else _\ sum_single) (* Exception Pattern *)