Supose I have the following code in Isabelle:
typedecl type1
typedecl type2
typedecl type3
consts
A::"type1 set"
B::"type2 set"
When I want to use union operation with A and B as bellow:
axiomatization where
c0: "A ∪ B = {}"
Since A and B are sets of different types, I get an error of clash of types which makes sense! As a workaround I want to type cast A and B to both become sets of type "type3", so I can apply union operations to them. How this type casting is possible in isabelle in this specific example, and how it is possible in general.
Thanks
Type casts require explicit functions between the types, say,
Using these functions, you can state your axiom as follows:
Isabelle can also automatically insert such coercion functions, but you have to enable it first:
These three declarations do the following
cast_A
andcast_B
as coercion functions, i.e., coercion inference may insert them if needed.image
(written infix as ` ) as a map function for coercions. These map functions allow the inference system to apply coercions to the parameters of type constructors. Here, the declaration allows to coerce sets by applying a coercion function to all its elements.With these preparations, the axiom can be written as before:
However, coercion insertion is only a means to remove clutter from the input notation. The coercions are explicit in the theorem and your proofs have to deal with them. If you look at the theorem
c0
, you will see the coercions.Finally a comment on these kinds of embedings. The predefined sum type
type1 + type2
consists exactly of all the elements of typetype1
and those of typetype2
with the cast functionsInl
andInr
, respectively. So, if your typetype3
has no other purpose than being the union oftype1
andtype2
, the sum type might be more convenient to work with.Also note that your axiom expresses that the sets
A
andB
are empty.