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

Feature request: accept patterns in argument of replace #15009

Open
cpitclaudel opened this issue Oct 8, 2021 · 3 comments
Open

Feature request: accept patterns in argument of replace #15009

cpitclaudel opened this issue Oct 8, 2021 · 3 comments
Labels
kind: enhancement Enhancement to an existing user-facing feature, tactic, etc.

Comments

@cpitclaudel
Copy link
Contributor

Description of the problem

Currently the change tactic accepts patterns, but replace does not: one can write change (?x + ?x) with (2 * x), but not replace (?x + 1) with (1 + x) by lia.

This feature is really convenient when change-ing large terms; it would be nice to have it for replace, too.

The current alternative of course is to use match goal with context instead, like match goal with [ |- context[f ?x + ?y] => replace (f x + y) with (x + g y), but it's syntactically heavy.

@cpitclaudel cpitclaudel added the kind: enhancement Enhancement to an existing user-facing feature, tactic, etc. label Oct 8, 2021
@herbelin
Copy link
Member

herbelin commented Oct 9, 2021

This is a long-standing wish (at least of mine). Initially, I intended to implement it following the way change is implemented.

However, replace is defined as a TACTIC EXTEND which is not able to interpret left-hand side patterns the way change is doing it, so either replace had to be turned into a tactic interpreted natively (but defeating the idea of a flexible architecture for defining new tactics), or some refinement of the TACTIC EXTEND had to be done.

As of now, there is some confusion about the future of tactics which somehow inhibates evolutions.

For instance, the status of TACTIC EXTEND is unknown. @ppedrot is often blaming it which makes me hesitant to recommend extending it further (if @ppedrot knows how to do better, let's not waste time at maintaining an infrastructure that some other architecture can eventually provide in a more general, more flexible, more efficient way...).

Still, something has to be done, so I'd be tempted to ask @ppedrot about how he would recommend your wish to be efficiently implemented, whatever way it is. Maybe it is more direct that I'd think.

@ppedrot
Copy link
Member

ppedrot commented Oct 9, 2021

We can discuss this at the next weekly call. Technically you can perfectly implement the wish with TACTIC EXTEND using specific genargs defined for that (and you could even port change to this). But in terms of functionality, I am kind of wary of the issues with change used with patterns, it also has quite a few drawbacks regarding type inference and pattern substitution. I'd rather have two different tactics, one with patterns and the other with terms (and fix change accordingly).

@Zimmi48
Copy link
Member

Zimmi48 commented Oct 11, 2021

@ppedrot echange and ereplace then?

@cpitclaudel Note that you can work around this limitation of replace by relying on eassert instead:

Require Import Lia.
Goal forall P x, P (x + 1).
intros.
eassert (?[x] + 1 = 1 + ?x) as -> by lia.

The nice thing about the as -> clause is that it makes the side goal concrete (instead of still containing existential variables as if this clause had not been used).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Enhancement to an existing user-facing feature, tactic, etc.
Projects
None yet
Development

No branches or pull requests

4 participants