How can I rewrite selectively in Coq?
Question
Require Import Coq.Arith.Arith. Section foo. Variable a : nat. Variable fvs : list nat. Variable maxNum : list nat -> nat. Hypothesis H : a = max (maxNum fvs) a + 1. Hypothesis H1 : max (maxNum fvs) a >= a.a: nat
fvs: list nat
maxNum: list nat -> nat
H: a = Init.Nat.max (maxNum fvs) a + 1
H1: Init.Nat.max (maxNum fvs) a >= aFalse
Doing rewrite H in H1., replaces both the as whereas I only want to rewrite the a on the RHS. Can it be done? I want to prove false from the above two hypotheses.
Answer
One option is to use rewrite ... at <position>. like so:
a: nat
fvs: list nat
maxNum: list nat -> nat
H: a = Init.Nat.max (maxNum fvs) a + 1
H1: Init.Nat.max (maxNum fvs) a >= Init.Nat.max (maxNum fvs) a + 1False
What you want can also be done in a slightly different way. Observe that max (maxNum fvs) a is irrelevant here -- you can use any natural number instead of that expression and your theorem would still hold. That means you can use the generalize tactic.
a: nat
fvs: list nat
maxNum: list nat -> nat
H: a = Init.Nat.max (maxNum fvs) a + 1
H1: Init.Nat.max (maxNum fvs) a >= aFalsea: nat
fvs: list nat
maxNum: list nat -> nata = Init.Nat.max (maxNum fvs) a + 1 -> Init.Nat.max (maxNum fvs) a >= a -> Falsea: nat
fvs: list nat
maxNum: list nat -> natforall n : nat, a = n + 1 -> n >= a -> Falsefvs: list nat
maxNum: list nat -> nat
n: natn >= n + 1 -> Falseapply Nat.nle_succ_diag_l. Qed. End foo.fvs: list nat
maxNum: list nat -> nat
n: natn >= S n -> False