# Replacing "true = false"

**URL:** <https://discourse.rocq-prover.org/t/replacing-true-false/2248>\
**Category:** Using Rocq\
**Created:** [April 10, 2024, 8:39pm UTC](https://discourse.rocq-prover.org/t/replacing-true-false/2248 "2024-04-10T20:39:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zepalmer](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.rocq-prover.org/zepalmer/32/923_2.png) [@zepalmer](https://discourse.rocq-prover.org/u/zepalmer)\
**Post date:** [April 10, 2024, 8:39pm UTC](https://discourse.rocq-prover.org/t/replacing-true-false/2248/1 "2024-04-10T20:39:49Z")

</div>

Hi! I’ve been learning Ltac by scribbling together a tactic that tidies things up for me. In my case, I seem to occasionally wind up with goals of the form `true = false \/ P` that I would like to simplify to just `P`. In order to be robust via compositionality, though, I’d like to tell the tactic to do two things:

- Whenever we see `False \/ P`, use `right` to replace it with `P`
- Whenever we see `Q \/ P`, do work to simplify equalities.

It is, bizarrely enough, this second part that I can’t figure out how to do. Consider this silly toy example:

```auto
Lemma foo : forall (x : nat), true = false \/ x >= 0.
Proof.
  intro x.

```

I wind up in this proof state:

```auto
1 goal
x : nat
______________________________________ (1/1)
true = false \/ x >= 0

```

Is there a good way to transform the `true = false` into `False`? (There are obviously a bunch of different ways to prove this silly lemma, but reducing `true = false` to `False` is the crux of my dilemma.)

`rewrite` won’t work here because (IIUC) it only rewrites _within_ equalities. `discriminate` wants to finish the proof. `replace` won’t help because we can’t prove `(true = false) = False`. This feels like a ridiculous thing to ask about, but this problem doesn’t seem particularly conducive to my search engine.

My thanks!

---

<div class="post-metadata">

**Author:** ![caverill](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.rocq-prover.org/caverill/32/832_2.png) [@caverill](https://discourse.rocq-prover.org/u/caverill)\
**Post date:** [April 11, 2024, 7:16am UTC](https://discourse.rocq-prover.org/t/replacing-true-false/2248/2 "2024-04-11T07:16:56Z")

</div>

I’m no Ltac expert, but here’s a little MWE I cooked up:

```auto
Lemma ignore_left : forall (P Q : Prop),
  ~ P -> Q -> P \/ Q.
Proof. auto. Qed.

Lemma ignore_right : forall (P Q : Prop),
  ~ Q -> P -> P \/ Q.
Proof. auto. Qed.

Require Import Lia.
Ltac prove_false := auto || lia || discriminate || contradiction.
Ltac ignore_false_branch :=
  match goal with
  | [|- ?P \/ ?Q] =>
    let H := fresh "H" in
    (assert (~ P) as H by prove_false; apply ignore_left; auto; clear H) ||
    (assert (~ Q) as H by prove_false; apply ignore_right; auto; clear H)
  end.

Theorem example : forall n, 0 <= n \/ true = false.
Proof.
  intros. ignore_false_branch. (* left with 0 <= n goal *) 
  lia.
Qed.

```

This really only does the first part of what you’re asking, but I think strengthening an automatic false-prover is a more approachable task then reducing arbitrary terms into intermediate terms.

The important chunk here is `prove_false`, which you should probably specialize for whatever goals you’re encountering. I just threw some tactics together.

---

<div class="post-metadata">

**Author:** ![SkySkimmer](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.rocq-prover.org/skyskimmer/32/369_2.png) [@SkySkimmer](https://discourse.rocq-prover.org/u/SkySkimmer)\
**Post date:** [April 11, 2024, 8:33am UTC](https://discourse.rocq-prover.org/t/replacing-true-false/2248/3 "2024-04-11T08:33:20Z")

</div>

You can use setoid\_rewrite with some lemmas:

```auto
Require Import Setoid Morphisms.

Lemma true_neq_false : true = false <-> False.
Proof. split;intros H;inversion H. Qed.

Lemma false_or_id P : False \/ P <-> P.
Proof. tauto. Qed.

Lemma foo : forall (x : nat), true = false \/ x >= 0.
Proof.
  intro x.
  setoid_rewrite true_neq_false; setoid_rewrite false_or_id.
  (* goal: x >= 0 *)

```

instead of listing the lemmas in the proof you can also use autorewrite:

```auto

Hint Rewrite true_neq_false false_or_id : goalsimpl.

Lemma foo : forall (x : nat), true = false \/ x >= 0.
Proof.
  intro x.
  autorewrite with goalsimpl.

```

---

<div class="post-metadata">

**Author:** ![zepalmer](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.rocq-prover.org/zepalmer/32/923_2.png) [@zepalmer](https://discourse.rocq-prover.org/u/zepalmer)\
**Post date:** [April 11, 2024, 2:34pm UTC](https://discourse.rocq-prover.org/t/replacing-true-false/2248/4 "2024-04-11T14:34:47Z")

</div>

@SkySkimmer Thanks! This is exactly the information I needed. The documentation on `setoid_rewrite` is a bit sparse in the manual, so I’m a naïve enough user that I missed it. 🙂

@caverill It was just the second part that I wasn’t sure how to do, but your solution to the first part uses some techniques that I should definitely learn. Thanks for the example!
