Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sum of exponents with same base

Tags:

coq

How can I prove the following statement in Coq?

forall x: nat,
x >= 1 -> 2 * 2 ^ (x - 1) = 2 ^ x.

I found lemma pow_add_r in module NZPow but for some reason I can´t use it.

Thanks, Marcus.

like image 213
Marcus Avatar asked Mar 16 '23 15:03

Marcus


1 Answers

I just saw your answer, but here is an explanation why your initial attempt didn't work, and how to make it run:

You can't directly use Nat.pow_add_r because your goal neither contains a term of the shape a ^ (b + c) nor a ^ b * a ^ c. You have to help Coq to recognize this pattern. In the following script, I first change 2 into 2 ^ 1, then use the lemma you provided.

Require Import Arith.

Lemma foo: forall x: nat, x >= 1 -> 2 * 2 ^ (x - 1) = 2 ^ x.
Proof.
intros x hx.
(* I only want to rewrite one occurrence of 2 *)
pattern 2 at 1; rewrite <- (Nat.pow_1_r 2). 
(* now my goal is 2 ^ 1 * 2 ^ (x-1) = 2 ^ x *)
rewrite <- Nat.pow_add_r.
(* now my goal is 2 ^ (1 + (x - 1)) = 2 ^ x 
   since x >= 1, we can rewrite the first term and conclude *)
now rewrite le_plus_minus_r.
Qed.

PS: you can Require Import Nat if you don't want to prefix the lemmas like I did.

like image 90
Vinz Avatar answered May 16 '23 06:05

Vinz