0
Goal forall (w x y z: string), w <> x -> (if (eqb_string w x) then y else z) = z.
Proof.
  intros.
  rewrite false_eqb_string by trivial.
  reflexivity.
Qed.

false_eqb_string is a rather trivial proof principle. I'd like to use it implicitly, via autorewrite or similar. Unfortunately, if I add Hint Rewrite false_eqb_string, then any subterm of the form eqb_string _ _ gets rewritten, and the assumption _ <> _ added to goals, even when that's not a sensible thing to do.

How can I make rewrite false_eqb_string by trivial happen automatically, without mentioning it by name?

Carl Patenaude Poulin
  • 6,238
  • 5
  • 24
  • 46

2 Answers2

2

One fairly general construct is match goal with, allowing you to pattern-match on, well, your goal. So you can look for disequalities in your hypotheses with corresponding boolean comparisons in the goal (or other hypotheses if you want) (context _ [ _ ] is a special pattern that allows you to match any subterm against the pattern in brackets), and rewrite using the right lemma. You can then give this match tactic a name, so you don't need to remember how the lemma is actually called. As you might expect, match also supports many clauses (with a weird backtracking behavior to be aware of), so you can extend this tactic into your own poor man's rewriting database.

From Coq Require Import Arith.

Ltac rewrite_eqb :=
  match goal with
  | [ H : ?u <> ?v |- context E [ ?u =? ?v ] ] =>
    rewrite (proj2 (Nat.eqb_neq u v) H)
  end.

Goal forall (w x y z: nat), w <> x -> (if (Nat.eqb w x) then y else z) = z.
Proof.
  intros.
  rewrite_eqb.
  reflexivity.
Qed.

See also:

Li-yao Xia
  • 31,896
  • 2
  • 33
  • 56
2

I believe the construction you are looking for is

Hint Rewrite false_eqb_string using solve [ trivial ].

This is documented in the reference manual. Unlike rewrite ... by ..., Hint Rewrite ... using ... will not undo the rewrite if the tactic does not fully solve the side conditions, so you must wrap it in solve [ ... ] to get that effect.

Jason Gross
  • 5,928
  • 1
  • 26
  • 53