Skip to content
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

apply tactic, similar to rewrite #747

Merged
merged 7 commits into from
Jan 24, 2025
Merged

Conversation

patrick-nicodemus
Copy link
Contributor

@patrick-nicodemus patrick-nicodemus commented Jan 19, 2025

Let me know if you can suggest useful ways to eliminate duplication here between apply and rewrite, both of them are doing the same thing where they traverse nested foralls.

Is repeatedly calling refine and failing inefficient? I have no idea.

I would also be interested if you have suggestions for making it stronger, it would be nice to have it behave as
"if the type of term f is unifiable with forall (x : A), B, then recursively apply f _. But I don't know how to check that checks whether a type is unifiable with a product type.

@patrick-nicodemus
Copy link
Contributor Author

Not sure if coq.saturate is appropriate here, if we want to be able to apply f : A -> (B -> C) to the goal B -> C.
Unless we want to saturate both the term to be applied and the goal.

Copy link
Contributor

@gares gares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, please have a look at my comments.

% from context
coq.typecheck T Ty ok;
% Eq is a reference to a declared variable in the context
std.mem Ctx (decl T _ Ty)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to check this? Can't it be an arbitrary term?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want the type Ty of the term T somehow, so that I can iteratively drop down through the nested foralls of Ty.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the typecheck line suffices, no need for the '; mem ...' part

Comment on lines 9 to 12
apply Term (prod _ _ B) G GL :-
whd (app [Term, Hole]) [] HD ARGS,
unwind HD ARGS Term',
apply Term' (B Hole) G GL.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a misconception here, I think you want to reduce the type, not the proof term
Untested:

Suggested change
apply Term (prod _ _ B) G GL :-
whd (app [Term, Hole]) [] HD ARGS,
unwind HD ARGS Term',
apply Term' (B Hole) G GL.
apply Term Ty G GL :-
whd Ty [] (prod _ _ B) [],
apply {coq.mk-app Term [Hole]} (B Hole) G GL.

Elpi Accumulate lp:{{
pred apply i:term, i:term, o:goal, o:list sealed-goal.

apply T _ G GL :- refine T G GL.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
apply T _ G GL :- refine T G GL.
apply T _ G GL :- refine T G GL, !.

@gares
Copy link
Contributor

gares commented Jan 20, 2025

Let me know if you can suggest useful ways to eliminate duplication here between apply and rewrite, both of them are doing the same thing where they traverse nested foralls.

Is repeatedly calling refine and failing inefficient? I have no idea.

I would also be interested if you have suggestions for making it stronger, it would be nice to have it behave as "if the type of term f is unifiable with forall (x : A), B, then recursively apply f _. But I don't know how to check that checks whether a type is unifiable with a product type.

I did do a whd. If you want to be stronger and unify, you can call coq.unify-eq Ty {{ forall x, lp:(B x) }} ok (the quotation is not necessary, but looks nicer than (prod _ _ B) (or (prod _ _ x\B x) that I do recomment since it documents B takes an argument.

@gares gares merged commit cd0a9c3 into LPCIC:master Jan 24, 2025
51 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants