Metamath Proof Explorer


Theorem digexp

Description: The K th digit of a power to the base is either 1 or 0. (Contributed by AV, 24-May-2020)

Ref Expression
Assertion digexp B 2 K 0 N 0 K digit B B N = if K = N 1 0

Proof

Step Hyp Ref Expression
1 eluzelcn B 2 B
2 eluz2nn B 2 B
3 2 nnne0d B 2 B 0
4 1 3 jca B 2 B B 0
5 4 3ad2ant1 B 2 K 0 N 0 B B 0
6 nn0z K 0 K
7 nn0z N 0 N
8 6 7 anim12i K 0 N 0 K N
9 8 ancomd K 0 N 0 N K
10 9 3adant1 B 2 K 0 N 0 N K
11 expsub B B 0 N K B N K = B N B K
12 5 10 11 syl2anc B 2 K 0 N 0 B N K = B N B K
13 12 eqcomd B 2 K 0 N 0 B N B K = B N K
14 13 fveq2d B 2 K 0 N 0 B N B K = B N K
15 14 oveq1d B 2 K 0 N 0 B N B K mod B = B N K mod B
16 2 3ad2ant1 B 2 K 0 N 0 B
17 simp2 B 2 K 0 N 0 K 0
18 eluzelre B 2 B
19 reexpcl B N 0 B N
20 18 19 sylan B 2 N 0 B N
21 18 adantr B 2 N 0 B
22 simpr B 2 N 0 N 0
23 eluzge2nn0 B 2 B 0
24 23 nn0ge0d B 2 0 B
25 24 adantr B 2 N 0 0 B
26 21 22 25 expge0d B 2 N 0 0 B N
27 20 26 jca B 2 N 0 B N 0 B N
28 27 3adant2 B 2 K 0 N 0 B N 0 B N
29 elrege0 B N 0 +∞ B N 0 B N
30 28 29 sylibr B 2 K 0 N 0 B N 0 +∞
31 nn0digval B K 0 B N 0 +∞ K digit B B N = B N B K mod B
32 16 17 30 31 syl3anc B 2 K 0 N 0 K digit B B N = B N B K mod B
33 simpr B 2 K 0 N 0 K = N K = N
34 33 eqcomd B 2 K 0 N 0 K = N N = K
35 nn0cn N 0 N
36 35 3ad2ant3 B 2 K 0 N 0 N
37 nn0cn K 0 K
38 37 3ad2ant2 B 2 K 0 N 0 K
39 36 38 subeq0ad B 2 K 0 N 0 N K = 0 N = K
40 39 adantr B 2 K 0 N 0 K = N N K = 0 N = K
41 34 40 mpbird B 2 K 0 N 0 K = N N K = 0
42 41 oveq2d B 2 K 0 N 0 K = N B N K = B 0
43 1 exp0d B 2 B 0 = 1
44 43 3ad2ant1 B 2 K 0 N 0 B 0 = 1
45 44 adantr B 2 K 0 N 0 K = N B 0 = 1
46 42 45 eqtrd B 2 K 0 N 0 K = N B N K = 1
47 46 fveq2d B 2 K 0 N 0 K = N B N K = 1
48 1zzd B 2 K 0 N 0 K = N 1
49 flid 1 1 = 1
50 48 49 syl B 2 K 0 N 0 K = N 1 = 1
51 47 50 eqtrd B 2 K 0 N 0 K = N B N K = 1
52 51 oveq1d B 2 K 0 N 0 K = N B N K mod B = 1 mod B
53 eluz2gt1 B 2 1 < B
54 1mod B 1 < B 1 mod B = 1
55 18 53 54 syl2anc B 2 1 mod B = 1
56 55 3ad2ant1 B 2 K 0 N 0 1 mod B = 1
57 56 adantr B 2 K 0 N 0 K = N 1 mod B = 1
58 52 57 eqtr2d B 2 K 0 N 0 K = N 1 = B N K mod B
59 simprl1 N < K B 2 K 0 N 0 ¬ K = N B 2
60 7 adantl K 0 N 0 N
61 6 adantr K 0 N 0 K
62 60 61 zsubcld K 0 N 0 N K
63 62 3adant1 B 2 K 0 N 0 N K
64 63 ad2antrl N < K B 2 K 0 N 0 ¬ K = N N K
65 nn0re N 0 N
66 65 3ad2ant3 B 2 K 0 N 0 N
67 nn0re K 0 K
68 67 3ad2ant2 B 2 K 0 N 0 K
69 66 68 sublt0d B 2 K 0 N 0 N K < 0 N < K
70 69 biimprd B 2 K 0 N 0 N < K N K < 0
71 70 adantr B 2 K 0 N 0 ¬ K = N N < K N K < 0
72 71 impcom N < K B 2 K 0 N 0 ¬ K = N N K < 0
73 expnegico01 B 2 N K N K < 0 B N K 0 1
74 59 64 72 73 syl3anc N < K B 2 K 0 N 0 ¬ K = N B N K 0 1
75 ico01fl0 B N K 0 1 B N K = 0
76 74 75 syl N < K B 2 K 0 N 0 ¬ K = N B N K = 0
77 76 oveq1d N < K B 2 K 0 N 0 ¬ K = N B N K mod B = 0 mod B
78 2 nnrpd B 2 B +
79 0mod B + 0 mod B = 0
80 78 79 syl B 2 0 mod B = 0
81 80 3ad2ant1 B 2 K 0 N 0 0 mod B = 0
82 81 ad2antrl N < K B 2 K 0 N 0 ¬ K = N 0 mod B = 0
83 77 82 eqtrd N < K B 2 K 0 N 0 ¬ K = N B N K mod B = 0
84 eluzelz B 2 B
85 84 3ad2ant1 B 2 K 0 N 0 B
86 85 ad2antrl ¬ N < K B 2 K 0 N 0 ¬ K = N B
87 67 65 anim12i K 0 N 0 K N
88 lenlt K N K N ¬ N < K
89 88 bicomd K N ¬ N < K K N
90 87 89 syl K 0 N 0 ¬ N < K K N
91 90 biimpd K 0 N 0 ¬ N < K K N
92 91 3adant1 B 2 K 0 N 0 ¬ N < K K N
93 92 adantr B 2 K 0 N 0 ¬ K = N ¬ N < K K N
94 93 impcom ¬ N < K B 2 K 0 N 0 ¬ K = N K N
95 3simpc B 2 K 0 N 0 K 0 N 0
96 95 ad2antrl ¬ N < K B 2 K 0 N 0 ¬ K = N K 0 N 0
97 nn0sub K 0 N 0 K N N K 0
98 96 97 syl ¬ N < K B 2 K 0 N 0 ¬ K = N K N N K 0
99 94 98 mpbid ¬ N < K B 2 K 0 N 0 ¬ K = N N K 0
100 zexpcl B N K 0 B N K
101 86 99 100 syl2anc ¬ N < K B 2 K 0 N 0 ¬ K = N B N K
102 flid B N K B N K = B N K
103 101 102 syl ¬ N < K B 2 K 0 N 0 ¬ K = N B N K = B N K
104 103 oveq1d ¬ N < K B 2 K 0 N 0 ¬ K = N B N K mod B = B N K mod B
105 1 3ad2ant1 B 2 K 0 N 0 B
106 3 3ad2ant1 B 2 K 0 N 0 B 0
107 105 106 63 expm1d B 2 K 0 N 0 B N - K - 1 = B N K B
108 107 eqcomd B 2 K 0 N 0 B N K B = B N - K - 1
109 108 ad2antrl ¬ N < K B 2 K 0 N 0 ¬ K = N B N K B = B N - K - 1
110 pm4.56 ¬ K = N ¬ N < K ¬ K = N N < K
111 87 3adant1 B 2 K 0 N 0 K N
112 axlttri K N K < N ¬ K = N N < K
113 111 112 syl B 2 K 0 N 0 K < N ¬ K = N N < K
114 113 biimprd B 2 K 0 N 0 ¬ K = N N < K K < N
115 110 114 syl5bi B 2 K 0 N 0 ¬ K = N ¬ N < K K < N
116 115 expdimp B 2 K 0 N 0 ¬ K = N ¬ N < K K < N
117 116 impcom ¬ N < K B 2 K 0 N 0 ¬ K = N K < N
118 8 3adant1 B 2 K 0 N 0 K N
119 118 ad2antrl ¬ N < K B 2 K 0 N 0 ¬ K = N K N
120 znnsub K N K < N N K
121 119 120 syl ¬ N < K B 2 K 0 N 0 ¬ K = N K < N N K
122 117 121 mpbid ¬ N < K B 2 K 0 N 0 ¬ K = N N K
123 nnm1nn0 N K N - K - 1 0
124 122 123 syl ¬ N < K B 2 K 0 N 0 ¬ K = N N - K - 1 0
125 zexpcl B N - K - 1 0 B N - K - 1
126 86 124 125 syl2anc ¬ N < K B 2 K 0 N 0 ¬ K = N B N - K - 1
127 109 126 eqeltrd ¬ N < K B 2 K 0 N 0 ¬ K = N B N K B
128 18 3ad2ant1 B 2 K 0 N 0 B
129 128 106 63 reexpclzd B 2 K 0 N 0 B N K
130 78 3ad2ant1 B 2 K 0 N 0 B +
131 mod0 B N K B + B N K mod B = 0 B N K B
132 129 130 131 syl2anc B 2 K 0 N 0 B N K mod B = 0 B N K B
133 132 ad2antrl ¬ N < K B 2 K 0 N 0 ¬ K = N B N K mod B = 0 B N K B
134 127 133 mpbird ¬ N < K B 2 K 0 N 0 ¬ K = N B N K mod B = 0
135 104 134 eqtrd ¬ N < K B 2 K 0 N 0 ¬ K = N B N K mod B = 0
136 83 135 pm2.61ian B 2 K 0 N 0 ¬ K = N B N K mod B = 0
137 136 eqcomd B 2 K 0 N 0 ¬ K = N 0 = B N K mod B
138 58 137 ifeqda B 2 K 0 N 0 if K = N 1 0 = B N K mod B
139 15 32 138 3eqtr4d B 2 K 0 N 0 K digit B B N = if K = N 1 0