coqcoq-tactic

Stuck at a simple inequality of natural number proof in Coq


I want to prove the inversion of inequality on negation, in natural numbers:

forall i j : nat, i <= j -> forall w : nat, i <= w -> j <= w -> w - i >= w - j.

I attempt to prove by induction. I first trivially prove that w - i >= w - i by reflexity. Then I try to prove w - i >= w - S m provided that w - i >= w - m, and I get stuck. It seems that if I prove w - m >= w - S m, it's done. But I can't solve that either. Could anyone help? Thank you so much!

Why isn't there an easy list of available tactics alongside their descriptions on the web?


Solution

  • I'm no expert at this, but a way you can structure this proof in Coq:

    Require Import Arith.
    
    Lemma le_minus : forall i j : nat, i <= j -> forall w : nat, i <= w -> j <= w -> w - i >= w - j.
    Proof.
      intros i j H1 w H2 H3.
      (* Induction on j *)
      induction j as [| m IHm].
      - (* Base Case: j = 0 *)
        assert (i = 0) as Hi0 by lia.
        rewrite Hi0. simpl. auto.
      - (* Inductive Step: j = S m *)
        destruct (Nat.eq_dec i (S m)).
        + (* Case: i = S m *)
          subst. lia.
        + (* Case: i < S m *)
          assert (i <= m) as H4 by lia.
          specialize (IHm H4 w H2).
          apply le_trans with (w - m). 
          * apply IHm. lia.
          * simpl. lia.
    Qed.
    

    Base Case

    If j = 0, then by the condition i ≤ j, we have i = 0. The goal is w − 0 ≥ w − 0, which is trivial.

    Inductive Step j = S m

    Tactics

    Some useful Coq tactics resources on the web

    Unfortunately, there is no "easy" list of Coq tactics out there on the web, and it does require quite a digging online.

    I hope this helps!