How to get typedef type to inherit statements from its mother type for type classes

Post an answer Follow-up question

Brian provided the answer, proposing a solution to use lift and gear. However, I cannot find enough tutorial information on how to lift and transmit to know how to set up his answer in order to finish what I will need to do.

Here I work in the dark and use the answer given as the plug'n'play template to ask this next question.

The command in my source code typedef trivAlg = "{x::sT. x = emS}" gives me a new type, which is a subset of the parent type sT .

I have a membership operator consts inP :: "sT => sT => bool" , and therefore in my naive view of raising and passing, since my monoid_add 0 was defined as the constant emS::sT , and I can make this statement , (emS::sT) inP emS , I would like to do something like this:

 theorem "~((0::trivAlg) inP 0)" 

So, I'm trying to use the lift to get my inP to work with the trivAlg type like this:

 lift_definition inP_trivAlg :: "trivAlg => trivAlg => bool" is "% x y. (x inP y)" by simp theorem "~((0::trivAlg) inP 0)" theorem "(emS::trivAlg) = emS" 

However, I get type collisions using theorem because my use of sT and trivAlg incompatible.

If the answer can be added to show me how to make my inP work with the trivAlg type, I would appreciate it. Or maybe I'm not familiar.

Preliminary Information on the (Original) Question

I have my sT type, which represents "everything is a collection." So far, all my constants and operators have been defined with a single type sT . For example, my empty set, membership operator, and union operator are defined like this:

 consts emS :: "sT" consts inP :: "sT => sT => bool" consts geU :: "sT => sT" 

Now I find out a little early if I can link my sT into generalized groups in Groups.thy .

From the HOL document, I try to get examples from sections 4.2, 4.3 and 4.4 of groups and 15.2 and 15.3 from Nat.

Well, I almost answer my own question, but I don’t know enough to find out if I am asking a reasonable question. I think that I know that a solution can only be with locales, sublayers, and interpretations, and not with type classes.

I was looking a bit for locales.pdf and classes.pdf , and therefore I know that locales and classes are intertwined. I also looked at IsarMathLib to see how locales, subwords, and interpretations are used there.

Question

My question is, with my trivial algebraic structure below trivAlg , which is a new type defined with typedef , how can I set things up with class classes so that I can use my constants like emS , inP and geU listed above, with elements like trivAlg ?

After I have listed the code below, I ask a few questions about specific lines of code in Groups.thy .

The code

 typedef trivAlg = "{x::sT. x = emS}" by auto instantiation trivAlg :: zero begin definition trivAlg_zero: "0 = Abs_trivAlg emS" instance .. end instantiation trivAlg :: monoid_add begin definition plus_trivAlg: "m + n = (Abs_trivAlg emS)" instance proof fix nmq :: trivAlg show "(n + m) + q = n + (m + q)" by(metis plus_trivAlg) show "0 + n = n" apply(induct n) apply(auto) by(metis plus_trivAlg) show "n + 0 = n" apply(induct n) apply(auto) by(metis plus_trivAlg) qed end theorem "((n::trivAlg) + m) + q = n + (m + q)" by(metis plus_trivAlg) theorem "((0::trivAlg) + 0) = 0" by(metis monoid_add_class.add.left_neutral) 

The next question is about Groups.thy

In lines 151 to 155 in groups. Thus, the following code exists:

 class semigroup_add = plus + assumes add_assoc [algebra_simps, field_simps]: "(a + b) + c = a + (b + c)" sublocale semigroup_add < add!: semigroup plus proof qed (fact add_assoc) 

There is not a single document to teach me how to use classes, locales, subwords and interpretations, so I don’t know exactly what that tells me.

If I want to use semigroup_add , which is in Groups.thy, do I have the choice to use it either as a type class or as a language?

+3
source share
2 answers

To get the appropriate operations on the trivAlg type, perhaps the easiest way is to use the Isabelle Lifting package; you can use the Transfer package to validate class instances. Here is an example:

 typedef trivAlg = "{x::sT. x = emS}" by auto setup_lifting type_definition_trivAlg instantiation trivAlg :: zero begin lift_definition zero_trivAlg :: "trivAlg" is "emS" . instance .. end instantiation trivAlg :: monoid_add begin lift_definition plus_trivAlg :: "trivAlg => trivAlg => trivAlg" is "% x y. emS" by simp instance proof fix nmq :: trivAlg show "(n + m) + q = n + (m + q)" by transfer simp show "0 + n = n" by transfer simp show "n + 0 = n" by transfer simp qed end 
+3
source

Simple things kill me if I don’t know what the syntax means, and most of Isabelle / HOL’s training is “looking at a few examples for long periods of time”, which doesn’t mean that there is not much documentation for Isabelle compared to other helpers by proof.

Here I end the question of how to actually use what Brian gave me.

My inP is actually a binary notation for the in_P :: sT => sT => bool function that I want to raise to print trivAlg , although I'm not sure that I used the term "lift" correctly now.

From the list of Isabelle users , I found an example showing the cancellation of the HOL union statement. Similarly, I will raise my in_P as follows:

 lift_definition in_P_trivAlg :: "trivAlg => trivAlg => bool" is "in_P :: sT => sT => bool" by simp 

In my previous trial and error attempts, I used my inP , which is only a designation, and it did not drown in the fact that lift_definition introduces a completely new function. These things finally came to me, and instead of "trial and error" I got "trial and success" using the in_P_trivAlg function reasonably, like this:

 theorem "~(in_P_trivAlg 0 0)" by(metis Ax_em in_P_trivAlg.rep_eq zero_trivAlg.rep_eq) 

This suggests that the empty set does not contain itself. This is good and tells me that I am on the right track, given that 0 was defined as emS , which is defined with the axiom Ax_em , so as not to contain elements.

Now I need to figure out how to overload the notation of the membership operator \<in>\<^isub>\iota> . Overloading the notation has not been important so far, since I did not need to overload most of the standard notations, for example \<in> .

It looks like I will need to rename the theorems, for example in_P_trivAlg.rep_eq , and I just got the answer for it from "Can I define some names for the theorem?" .

From RealVector.thy , now I see that there are many renames with the lemmas , for example

 text {* Recover original theorem names *} lemmas scaleR_left_commute = real_vector.scale_left_commute lemmas scaleR_zero_left = real_vector.scale_zero_left ... 

The purpose of this code would mean nothing to me if it were not for the response to the Stackoveflow that I just provided a link to.

+1
source

All Articles