1

The subst tactic is very useful in coq, it can remove useless variable names and make our context clear.

But when we have a = a1 , a1 = a2 in our context, it often keeps a2 instead of a in the result, which makes our context ugly.

Of course you can rename them one by one, but that makes subst not as convenient as before.

So I'm wondering, is there an easy way to make subst just keep the prettiest variable name, which can be just the minimum one in lexicographical order.

luochen1990
  • 3,689
  • 1
  • 22
  • 37
  • You can tell `subst` which variables to substitute for, `Goal forall a a1 a2:nat, a = a1 -> a1 = a2 -> a + a1 = a2 + a1. intros; subst. Restart. intros; subst a1 a2. ` – larsr Aug 24 '18 at 08:25

1 Answers1

2

There's no generic way to analyze the names of variables in Ltac (without a plugin). If you generally run into this situation where equalities have newer variables on the right hand side you can write a version of subst that prefers right-to-left substitutions:

Ltac reverse_subst :=
  repeat match goal with
         | [ H: ?x = ?x' |- _ ] =>
           (is_var x'; subst x') || (is_var x; subst x)
         end.
Tej Chajed
  • 3,749
  • 14
  • 18