I sometimes need to apply a simplification in a branch of an if-then-else without destructing the discriminee.
From Coq Require Import Setoid.
Lemma true_and :
forall P, True /\ P <-> P.
Proof.
firstorder.
Qed.
Goal (forall (b:bool) P Q, if b then True /\ P else Q).
intros.
Fail rewrite (true_and P).
Abort.
In this example rewrite
fails (setoid_rewrite
too), suggesting to register the following
"subrelation eq (Basics.flip Basics.impl)"
: seems fair to me"subrelation iff eq"
: no way!
Why is the rewriting engine so demanding?
I think the rewriting strategies are failing because what you want is not a rewriting, it's a reduction (
True /\ P
is not technically equal toP
). If you want to maintain theif then else
statement, I'll suggest the following solution (yet a bit unsatisfactory):In a
Tactics.v
file, add the following lemma and ltacs :Then, when you have a goal with a top-level
if then else
, you can apply a theoremTh
to either the left or right side withite_app1 Th
orite_app2 Th
. For example, you goal would be :You'll probably need to fine-tune the ltacs to your needs (apply in the context vs in the goal, etc.), but that's a first solution. Maybe someone can bring more ltac dark magic to solve this in a more general way.