A possible counter example for theorem numbertheory_3pow2pownm1mod2pownp3eq2pownp2
Wenda302 opened this issue · comments
Oh that's a tough one for me, but for n=1
, lhs is 8 mod 16
rhs is 8
it looks good?
I've got an informal proof of it by induction, assuming for n
is correct, where we can have 3^(2^n) = z * 2^(n + 3) + 2^(n+2)
for an integer z
, plug it in for 3^(2^(n + 1))
and we can let it to be 2^(n + 3) * (z * 2^(n + 2)) + 2^(n + 1) + 1) * (2 * z + 1)
, where the last 2 expr are odd, and we can say that when it mod 2^(n + 4)
, it is 2^(n + 3)
.
But formalizing it looks quite challenging.
You are correct. I made a silly mistake in types when translating the statement to Isabelle, and the counter example generator in Isabelle suggested the counter example when 2 is a polymorphic type (rather than the type of natural numbers).
The statement is correct, and it can be proved using induction (similar to what you sketched):
theorem numbertheory_3pow2pownm1mod2pownp3eq2pownp2:
fixes n :: nat
assumes "0 < n"
shows "(3^(2^n) - 1) mod (2^(n + 3)) = (2::nat)^(n + 2)"
using assms
proof (induct n)
case (Suc n)
have ?case when "n=0"
using that by simp
moreover have ?case when "n>0"
proof -
define m::nat where "m = 2^n"
have "(3 ^ 2 ^ n - 1) mod 2 ^ (n + 3) = (2::nat)^ (n + 2)"
using Suc(1) that by simp
then have "(3^m - 1) mod (8*m) = 4*m"
unfolding m_def by (auto simp:algebra_simps power_add)
then obtain k where k0:"3^m - 1 = (8*m)*k + 4*m"
by (metis mult_div_mod_eq)
define M::nat where "M = 4*m*k^2+m+4*m*k+k"
have k:"3^m = (8*m)*k + 4*m +1"
proof -
have "3^m≥(1::nat)" by auto
then show ?thesis
using k0 by linarith
qed
have "3 ^ 2 ^ Suc n - 1 = ((3::nat) ^ (m*2)) - 1"
unfolding m_def by (auto simp:algebra_simps)
also have "... = (3 ^ m)⇧2 - 1"
unfolding power_mult by simp
also have "... = ((8*m)*k + 4*m +1)^2 -1 "
unfolding k by simp
also have "... = (16*m)*M + 8*m"
unfolding M_def by (auto simp:algebra_simps power2_eq_square)
finally have "3 ^ 2 ^ Suc n - 1 = (16*m)*M + 8*m" .
moreover have "((16*m)*M + 8*m) mod (16*m) = 8*m"
by simp
then have "((16*m)*M + 8*m) mod 2 ^ (Suc n + 3) = 2 ^ (Suc n + 2)"
unfolding m_def by (auto simp:algebra_simps power_add)
ultimately show ?thesis by auto
qed
ultimately show ?case by blast
qed simp