How to get a typedef type to inherit operators from its mother type for type classes

久未见 提交于 2019-12-05 15:17:48

To get the corresponding operations on type trivAlg, probably the easiest way is to use Isabelle's Lifting package; you can then use the Transfer package to prove the 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 n m q :: 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

Simple things kill me if I don't know what the syntax means, and much of learning Isabelle/HOL is "stare at multiple examples for long periods of time", which is not to say there's not a lot of documentation for Isabelle relative to other proof assistants.

Here I finish off the question I had on how to actually use what Brian gave me.

My inP is actually binary notation for the function in_P :: sT => sT => bool, which is what I want to lift over to type trivAlg, though I'm not sure I just now used the term "lift" correctly.

From the Isabelle user's list, I found an example showing the lifting of the HOL union operator. Similarly, I lift my in_P like this:

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

In my previous trial and error attempts, I had been using my inP, which is only notation, and it hadn't sunk in that lift_definition is introducing a brand new function. Those those things finally occurred to me, and instead of "trial and error", I got "trial and success" by using the function in_P_trivAlg intelligently like this:

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

This says that the empty set doesn't contain itself. That's good, and tells me I'm on the right track, considering that 0 has been defined to be emS, which is defined, with the axiom Ax_em, to contain no elements .

I now need to figure out how to overload my membership operator notation \<in>\<^isub>\iota>. Overloading notation hasn't been important until now, since I've had a need to not overload most standard notation, like \<in>.

It looks like I'll have a need to rename theorems, such as in_P_trivAlg.rep_eq, and I just got the answer for that from "Can I define multiple names for a theorem?".

From RealVector.thy, I now see that there's a lot of renaming using the lemmas command, such as

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 that code would have meant nothing to me if it wasn't for the Stackoveflow answer I just provided a link to.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!