Where did lt_index go?
Question
I was using a lemma named lt_index in Coq, I remember it states that
n < 2 * m + 1 -> (n - 1) / 2 < m
Now, I can't use this lemma anymore, and when I do SearchAbout lt_index, coq answers with
Error: The reference lt_index was not found in the current environment.
My imports are as follows
Require Import Coq.Numbers.Natural.Peano.NPeano. Require Import Arith.
Did I miss something?
EDIT: Apparently, I dreamed about this lt_index lemma and never existed. Anyway, I came up with a proof to the same result, I added 1 <= n as precondition. Here it is
forall n m : nat, 1 <= n -> n < 2 * m + 1 -> (n - 1) / 2 < mforall n m : nat, 1 <= n -> n < 2 * m + 1 -> (n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1n <= n - 1 + 1n, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1(n - 1) / 2 < mapply Nat.sub_add_le.n, m: nat
H: 1 <= n
H0: n < 2 * m + 1n <= n - 1 + 1n, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
H2: n = n - 1 + 1(n - 1 + 1 - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
m0: nat
H3: n <= m0
H2: S m0 = n - 1 + 1(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
H2: n = n - 1 + 1(n - 1 + 1 - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
H2: n = n - 1 + 1(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n - 1 + 1 < 2 * m + 1
H1: n <= n - 1 + 1
H2: n = n - 1 + 1(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: 1 + (n - 1) < 2 * m + 1
H1: n <= n - 1 + 1
H2: n = n - 1 + 1(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: 1 + (n - 1) < 2 * m + 1
H1: n <= n - 1 + 1
H2: n = n - 1 + 12 * m + 1 = 1 + 2 * mn, m: nat
H: 1 <= n
H0: 1 + (n - 1) < 2 * m + 1
H1: n <= n - 1 + 1
H2: n = n - 1 + 1
H3: 2 * m + 1 = 1 + 2 * m(n - 1) / 2 < mapply plus_comm.n, m: nat
H: 1 <= n
H0: 1 + (n - 1) < 2 * m + 1
H1: n <= n - 1 + 1
H2: n = n - 1 + 12 * m + 1 = 1 + 2 * mn, m: nat
H: 1 <= n
H0: 1 + (n - 1) < 2 * m + 1
H1: n <= n - 1 + 1
H2: n = n - 1 + 1
H3: 2 * m + 1 = 1 + 2 * m(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: 1 + (n - 1) < 1 + 2 * m
H1: n <= n - 1 + 1
H2: n = n - 1 + 1
H3: 2 * m + 1 = 1 + 2 * m(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n - 1 < 2 * m
H1: n <= n - 1 + 1
H2: n = n - 1 + 1
H3: 2 * m + 1 = 1 + 2 * m(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: (n - 1) / 2 < m
H1: n <= n - 1 + 1
H2: n = n - 1 + 1
H3: 2 * m + 1 = 1 + 2 * m(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n - 1 < 2 * m
H1: n <= n - 1 + 1
H2: n = n - 1 + 1
H3: 2 * m + 1 = 1 + 2 * m2 <> 0trivial.n, m: nat
H: 1 <= n
H0: (n - 1) / 2 < m
H1: n <= n - 1 + 1
H2: n = n - 1 + 1
H3: 2 * m + 1 = 1 + 2 * m(n - 1) / 2 < mdiscriminate.n, m: nat
H: 1 <= n
H0: n - 1 < 2 * m
H1: n <= n - 1 + 1
H2: n = n - 1 + 1
H3: 2 * m + 1 = 1 + 2 * m2 <> 0n, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
m0: nat
H3: n <= m0
H2: S m0 = n - 1 + 1(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
m0: nat
H3: n <= m0
H2: S m0 = 1 + (n - 1)(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
m0: nat
H3: n <= m0
H2: S m0 = n(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
m0: nat
H3: n <= m0
H2: S m0 = 1 + (n - 1)1 <= nn, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
m0: nat
H3: n <= m0
H2: S m0 = n(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
m0: nat
H3: n < S m0
H2: S m0 = n(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
m0: nat
H3: n <= m0
H2: S m0 = nm0 < S m0n, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
m0: nat
H3: n < S m0
H2: S m0 = n(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
m0: nat
H3: n < n
H2: S m0 = n(n - 1) / 2 < mapply lt_irrefl.n, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
m0: nat
H2: S m0 = n~ n < napply lt_n_Sn.n, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
m0: nat
H3: n <= m0
H2: S m0 = nm0 < S m0trivial. Qed.n, m: nat
H: 1 <= n
H0: n < 2 * m + 1
H1: n <= n - 1 + 1
m0: nat
H3: n <= m0
H2: S m0 = 1 + (n - 1)1 <= n
If you realize there is an improvement to this proof, I'd be glad to hear about it.
Answer (larsr)
While it is good to try to solve these kinds of problems by hand as an exercise, in the long run it can get tedious, if you really want to work on something else.
There are tactics that can help you to solve systems of equations with inequalities. You can for instance use the tactics lia from Psatz, or omega from Omega. The proof terms are not a pretty sight, but if that doesn't matter then why not.
Unfortunately they don't handle division, so they can't solve this system, but there is a lemma in the library that you can use to get rid of the /. I found it by doing Search ( _ / _ < _ ).
Require Import Coq.Numbers.Natural.Peano.NPeano. (* this provides 'lia' for solving linear integer arithmetic *) Require Import Psatz.forall n m : nat, 1 <= n -> n < 2 * m + 1 -> (n - 1) / 2 < mforall n m : nat, 1 <= n -> n < 2 * m + 1 -> (n - 1) / 2 < mapply Nat.div_lt_upper_bound; lia. Qed.n, m: nat
H: 1 <= n
H0: n < 2 * m + 1(n - 1) / 2 < m
Answer (Anton Trunov)
If you for some reason would like to get a "manual" solution, using the standard library, then here it is.
Require Import Coq.Arith.Arith.forall n m : nat, 1 <= n -> n < 2 * m + 1 -> (n - 1) / 2 < mforall n m : nat, 1 <= n -> n < 2 * m + 1 -> (n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1(n - 1) / 2 < mn, m: nat
H: 1 <= n
H0: n < 2 * m + 1n - 1 < 2 * mm: nat
H: 1 <= 0
H0: 0 < 2 * m + 10 - 1 < 2 * mn, m: nat
H: 1 <= S n
H0: S n < 2 * m + 1S n - 1 < 2 * minversion H.m: nat
H: 1 <= 0
H0: 0 < 2 * m + 10 - 1 < 2 * mn, m: nat
H: 1 <= S n
H0: S n < 2 * m + 1S n - 1 < 2 * mrewrite Nat.add_1_r... Qed.n, m: nat
H: 1 <= S n
H0: S n < 2 * m + 1n + 1 < 2 * m + 1
Q: Thanks @Anton, one question: why did you add Proof with auto at the very beginning of your proof? What is the role of with auto?
A: It's just a shortcut. The construction Proof with <tactic> works as follows. When you see ellipsis (...) ending a tactic t1, it's equivalent to turning it into t1; <tactic>. So rewrite Nat.add_1_r... behaves as rewrite Nat.add_1_r; auto.