-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Applying the parametricity techniques to the generation of Boolean equality #93
Comments
I think the match expansion trick is exactly what we do in coq elpi parametricity implementation |
And I think @gares implementation of equality generation and induction scheme reuses this and the same trick... |
not for equality test, but for induction yes. |
Ah, thanks for the information! I mentioned I had an issue with fixpoints last Wednesday at the Coq call and it did not ring a bell to anyone. So, I should probably have had to explain the exact problems I had. About Boolean equality, it is not a problem that it is not total. One can do the parametricity in an option type and return a result only when it is not Inductive GI (F:Type->Type) A := GC : F A -> F nat -> GI F A.
Inductive K2 (b:bool) (F : if b then Type else Type->Type) : Type :=
C2 : (if b return (if b then Type else Type->Type) -> Type
then fun A => A else fun F => F nat) F ->
K2 b F. which I don't think elpi support (see the PR for examples). Anyway, this is very good news. I've been very enthousiastic when I learned all what elpi derive can do. The need for schemes is ubiquitous and we should make their automatic generation widely available. What would be e.g. the cost of using the parametricity techniques everywhere in elpi? And how easy would it be to plug the elpi generation of schemes directly within Coq so that e.g. at least all the Also, compared to paramcoq, are there further cooperations to install, e.g. so that the match-expansion trick is transferred to paramcoq, and, conversely, if ever paramcoq does things that elpi does not (maybe e.g. deriving schemes also for constants?) can be transferred to elpi? |
How do you get a boolean test for W for example? |
In practice, the algorithm sees a function type and fails. But if your question is about what is theoretically possible, we could build a Boolean equality for More generally, Escardó and Oliva have explored the decidability of non-finite decidable types and shown that there is a duality between types with decidable equality and compact types (see e.g. this talk). That would be very interesting to apply their work to the synthesis of Boolean equality and, e.g. produce automatically the Boolean equality for |
Do you have an idea of the extent of the applicability of the match-expansion trick? For instance, the
Is the match-expansion trick documented somewhere? If not, that would justify writing a note about it, what do you think? |
I'm not a parametricity expert and I'm just maintaining paramcoq because I'm using it through CoqEAL. |
The only problem I see is that paramcoq does support full CIC. coq-elpi does not cover mutual stuff (and univpoly, but that is coming). So maybe in the future, but not today. |
Sure, no hurry (and I wouldn't say the support of univpoly in paramcoq is very elaborate) |
Actually, the example works w/o extra effort and elpi generates parametricity for it (I took a wrong path in my previous investigations). These are good news.
So, regarding standard parametricity, my summary so far is that:
|
Hi, I made recently an experiment of using parametricity techniques in Coq to automatically generate a Boolean equality associated to an inductive type as an alternative to the ad hoc algorithm currently in use.
It worked surprisingly well (see coq/coq#15527) but I stumbled too on the
fix
typing issue, that is on the question of proving thatF (fix F)
is convertible tofix F
. I may have a solution working sometimes and reminiscent of the trick used for nice fixpoints in paramcoq. The trick is to use a "match"-expansion: forx
an inhabitant of the inductive type and assuming the type has constructorC
, we can translatefix f x := F f x
aswhat forces the reduction of
(fix f x := F f x) y
insideF_R
intoF f y
, becausey
is now a constructor able to trigger the reduction.I don't know yet the exact extent of the trick. It seems to require further match-expansions in
F_R
if there are othermatch
in it.Here is an example for the case of Boolean equality:
PS: Long time ago, @mlasson mentioned to me a problem with typing fixpoints in CIC but I have to confess that I don't remember if it was about adjusting the types in the recursive call or about the issue with constraints over indices in fixpoints, or maybe about both. So, maybe this was related.
The text was updated successfully, but these errors were encountered: