How can I state a lemma in Isabelle/HOL that does not obey sort constraints?
To explain why that makes sense, consider the following example theory:
theory Test
imports Main
begin
class embeddable =
fixes embedding::"'a ⇒ nat"
assumes "inj embedding"
lemma OFCLASS_I:
assumes "inj (embedding::'a⇒_)"
shows "OFCLASS('a::type,embeddable_class)"
apply intro_classes by (fact assms)
instantiation nat :: embeddable begin
definition "embedding = id"
instance
apply (rule OFCLASS_I) unfolding embedding_nat_def by simp
end
end
This theory defines a type class "embeddable" with one type parameters "embedding". (Basically, the class embeddable characterizes countable numbers with an explicit enumeration, but I chose this simply to have a very simple example.)
To simplify instance-proofs for the type class, the theory states an auxiliary lemma OFCLASS_I
that shows goals of the form OFCLASS(...,embeddable)
. This lemma can then be used to solve the proof obligations produced by instance
.
First, why would I even want that? (In the present theory, apply (rule OFCLASS_I)
does the same as the builtin apply intro_classes
and hence is useless.) In more complex cases, there are two reasons for such a lemma:
- The lemma can give alternative criteria for instantiation of a type class, making subsequent proofs simpler.
- The lemma could be used in automated (ML-level) instantiations. Here using
intro_classes
is problematic, because the number of subgoals ofintro_classes
can vary depending on what instance proofs have been performed earlier. (A lemma such asOFCLASS_I
has a stable, well-controlled subgoals.)
However, the above theory does not work in Isabelle/HOL (neither 2015 or 2016-RC1) because the lemma does not type-check. The sort constraint "embedding::(_::embeddable => _)" is not satisfied. However, this type contraint is not a logic necessity (it is not enforced by the logical kernel but instead of a higher level).
So, is there a clean way of stating the theory above? (I give a somewhat ugly solution in my answer, but I am looking for something cleaner.)