Metamath Proof Explorer


Theorem bitsinv1

Description: There is an explicit inverse to the bits function for nonnegative integers (which can be extended to negative integers using bitscmp ), part 1. (Contributed by Mario Carneiro, 7-Sep-2016)

Ref Expression
Assertion bitsinv1 N 0 n bits N 2 n = N

Proof

Step Hyp Ref Expression
1 oveq2 x = 0 0 ..^ x = 0 ..^ 0
2 fzo0 0 ..^ 0 =
3 1 2 eqtrdi x = 0 0 ..^ x =
4 3 ineq2d x = 0 bits N 0 ..^ x = bits N
5 in0 bits N =
6 4 5 eqtrdi x = 0 bits N 0 ..^ x =
7 6 sumeq1d x = 0 n bits N 0 ..^ x 2 n = n 2 n
8 sum0 n 2 n = 0
9 7 8 eqtrdi x = 0 n bits N 0 ..^ x 2 n = 0
10 oveq2 x = 0 2 x = 2 0
11 2cn 2
12 exp0 2 2 0 = 1
13 11 12 ax-mp 2 0 = 1
14 10 13 eqtrdi x = 0 2 x = 1
15 14 oveq2d x = 0 N mod 2 x = N mod 1
16 9 15 eqeq12d x = 0 n bits N 0 ..^ x 2 n = N mod 2 x 0 = N mod 1
17 16 imbi2d x = 0 N 0 n bits N 0 ..^ x 2 n = N mod 2 x N 0 0 = N mod 1
18 oveq2 x = k 0 ..^ x = 0 ..^ k
19 18 ineq2d x = k bits N 0 ..^ x = bits N 0 ..^ k
20 19 sumeq1d x = k n bits N 0 ..^ x 2 n = n bits N 0 ..^ k 2 n
21 oveq2 x = k 2 x = 2 k
22 21 oveq2d x = k N mod 2 x = N mod 2 k
23 20 22 eqeq12d x = k n bits N 0 ..^ x 2 n = N mod 2 x n bits N 0 ..^ k 2 n = N mod 2 k
24 23 imbi2d x = k N 0 n bits N 0 ..^ x 2 n = N mod 2 x N 0 n bits N 0 ..^ k 2 n = N mod 2 k
25 oveq2 x = k + 1 0 ..^ x = 0 ..^ k + 1
26 25 ineq2d x = k + 1 bits N 0 ..^ x = bits N 0 ..^ k + 1
27 26 sumeq1d x = k + 1 n bits N 0 ..^ x 2 n = n bits N 0 ..^ k + 1 2 n
28 oveq2 x = k + 1 2 x = 2 k + 1
29 28 oveq2d x = k + 1 N mod 2 x = N mod 2 k + 1
30 27 29 eqeq12d x = k + 1 n bits N 0 ..^ x 2 n = N mod 2 x n bits N 0 ..^ k + 1 2 n = N mod 2 k + 1
31 30 imbi2d x = k + 1 N 0 n bits N 0 ..^ x 2 n = N mod 2 x N 0 n bits N 0 ..^ k + 1 2 n = N mod 2 k + 1
32 oveq2 x = N 0 ..^ x = 0 ..^ N
33 32 ineq2d x = N bits N 0 ..^ x = bits N 0 ..^ N
34 33 sumeq1d x = N n bits N 0 ..^ x 2 n = n bits N 0 ..^ N 2 n
35 oveq2 x = N 2 x = 2 N
36 35 oveq2d x = N N mod 2 x = N mod 2 N
37 34 36 eqeq12d x = N n bits N 0 ..^ x 2 n = N mod 2 x n bits N 0 ..^ N 2 n = N mod 2 N
38 37 imbi2d x = N N 0 n bits N 0 ..^ x 2 n = N mod 2 x N 0 n bits N 0 ..^ N 2 n = N mod 2 N
39 nn0z N 0 N
40 zmod10 N N mod 1 = 0
41 39 40 syl N 0 N mod 1 = 0
42 41 eqcomd N 0 0 = N mod 1
43 oveq1 n bits N 0 ..^ k 2 n = N mod 2 k n bits N 0 ..^ k 2 n + n bits N k 2 n = N mod 2 k + n bits N k 2 n
44 fzonel ¬ k 0 ..^ k
45 44 a1i N 0 k 0 ¬ k 0 ..^ k
46 disjsn 0 ..^ k k = ¬ k 0 ..^ k
47 45 46 sylibr N 0 k 0 0 ..^ k k =
48 47 ineq2d N 0 k 0 bits N 0 ..^ k k = bits N
49 inindi bits N 0 ..^ k k = bits N 0 ..^ k bits N k
50 48 49 5 3eqtr3g N 0 k 0 bits N 0 ..^ k bits N k =
51 simpr N 0 k 0 k 0
52 nn0uz 0 = 0
53 51 52 eleqtrdi N 0 k 0 k 0
54 fzosplitsn k 0 0 ..^ k + 1 = 0 ..^ k k
55 53 54 syl N 0 k 0 0 ..^ k + 1 = 0 ..^ k k
56 55 ineq2d N 0 k 0 bits N 0 ..^ k + 1 = bits N 0 ..^ k k
57 indi bits N 0 ..^ k k = bits N 0 ..^ k bits N k
58 56 57 eqtrdi N 0 k 0 bits N 0 ..^ k + 1 = bits N 0 ..^ k bits N k
59 fzofi 0 ..^ k + 1 Fin
60 inss2 bits N 0 ..^ k + 1 0 ..^ k + 1
61 ssfi 0 ..^ k + 1 Fin bits N 0 ..^ k + 1 0 ..^ k + 1 bits N 0 ..^ k + 1 Fin
62 59 60 61 mp2an bits N 0 ..^ k + 1 Fin
63 62 a1i N 0 k 0 bits N 0 ..^ k + 1 Fin
64 2nn 2
65 64 a1i N 0 k 0 n bits N 0 ..^ k + 1 2
66 simpr N 0 k 0 n bits N 0 ..^ k + 1 n bits N 0 ..^ k + 1
67 66 elin2d N 0 k 0 n bits N 0 ..^ k + 1 n 0 ..^ k + 1
68 elfzouz n 0 ..^ k + 1 n 0
69 67 68 syl N 0 k 0 n bits N 0 ..^ k + 1 n 0
70 69 52 eleqtrrdi N 0 k 0 n bits N 0 ..^ k + 1 n 0
71 65 70 nnexpcld N 0 k 0 n bits N 0 ..^ k + 1 2 n
72 71 nncnd N 0 k 0 n bits N 0 ..^ k + 1 2 n
73 50 58 63 72 fsumsplit N 0 k 0 n bits N 0 ..^ k + 1 2 n = n bits N 0 ..^ k 2 n + n bits N k 2 n
74 bitsinv1lem N k 0 N mod 2 k + 1 = N mod 2 k + if k bits N 2 k 0
75 39 74 sylan N 0 k 0 N mod 2 k + 1 = N mod 2 k + if k bits N 2 k 0
76 eqeq2 2 k = if k bits N 2 k 0 n bits N k 2 n = 2 k n bits N k 2 n = if k bits N 2 k 0
77 eqeq2 0 = if k bits N 2 k 0 n bits N k 2 n = 0 n bits N k 2 n = if k bits N 2 k 0
78 simpr N 0 k 0 k bits N k bits N
79 78 snssd N 0 k 0 k bits N k bits N
80 sseqin2 k bits N bits N k = k
81 79 80 sylib N 0 k 0 k bits N bits N k = k
82 81 sumeq1d N 0 k 0 k bits N n bits N k 2 n = n k 2 n
83 simplr N 0 k 0 k bits N k 0
84 64 a1i N 0 k 0 k bits N 2
85 84 83 nnexpcld N 0 k 0 k bits N 2 k
86 85 nncnd N 0 k 0 k bits N 2 k
87 oveq2 n = k 2 n = 2 k
88 87 sumsn k 0 2 k n k 2 n = 2 k
89 83 86 88 syl2anc N 0 k 0 k bits N n k 2 n = 2 k
90 82 89 eqtrd N 0 k 0 k bits N n bits N k 2 n = 2 k
91 simpr N 0 k 0 ¬ k bits N ¬ k bits N
92 disjsn bits N k = ¬ k bits N
93 91 92 sylibr N 0 k 0 ¬ k bits N bits N k =
94 93 sumeq1d N 0 k 0 ¬ k bits N n bits N k 2 n = n 2 n
95 94 8 eqtrdi N 0 k 0 ¬ k bits N n bits N k 2 n = 0
96 76 77 90 95 ifbothda N 0 k 0 n bits N k 2 n = if k bits N 2 k 0
97 96 oveq2d N 0 k 0 N mod 2 k + n bits N k 2 n = N mod 2 k + if k bits N 2 k 0
98 75 97 eqtr4d N 0 k 0 N mod 2 k + 1 = N mod 2 k + n bits N k 2 n
99 73 98 eqeq12d N 0 k 0 n bits N 0 ..^ k + 1 2 n = N mod 2 k + 1 n bits N 0 ..^ k 2 n + n bits N k 2 n = N mod 2 k + n bits N k 2 n
100 43 99 syl5ibr N 0 k 0 n bits N 0 ..^ k 2 n = N mod 2 k n bits N 0 ..^ k + 1 2 n = N mod 2 k + 1
101 100 expcom k 0 N 0 n bits N 0 ..^ k 2 n = N mod 2 k n bits N 0 ..^ k + 1 2 n = N mod 2 k + 1
102 101 a2d k 0 N 0 n bits N 0 ..^ k 2 n = N mod 2 k N 0 n bits N 0 ..^ k + 1 2 n = N mod 2 k + 1
103 17 24 31 38 42 102 nn0ind N 0 N 0 n bits N 0 ..^ N 2 n = N mod 2 N
104 103 pm2.43i N 0 n bits N 0 ..^ N 2 n = N mod 2 N
105 id N 0 N 0
106 105 52 eleqtrdi N 0 N 0
107 64 a1i N 0 2
108 107 105 nnexpcld N 0 2 N
109 108 nnzd N 0 2 N
110 2z 2
111 uzid 2 2 2
112 110 111 ax-mp 2 2
113 bernneq3 2 2 N 0 N < 2 N
114 112 113 mpan N 0 N < 2 N
115 elfzo2 N 0 ..^ 2 N N 0 2 N N < 2 N
116 106 109 114 115 syl3anbrc N 0 N 0 ..^ 2 N
117 bitsfzo N N 0 N 0 ..^ 2 N bits N 0 ..^ N
118 39 105 117 syl2anc N 0 N 0 ..^ 2 N bits N 0 ..^ N
119 116 118 mpbid N 0 bits N 0 ..^ N
120 df-ss bits N 0 ..^ N bits N 0 ..^ N = bits N
121 119 120 sylib N 0 bits N 0 ..^ N = bits N
122 121 sumeq1d N 0 n bits N 0 ..^ N 2 n = n bits N 2 n
123 nn0re N 0 N
124 2rp 2 +
125 124 a1i N 0 2 +
126 125 39 rpexpcld N 0 2 N +
127 nn0ge0 N 0 0 N
128 modid N 2 N + 0 N N < 2 N N mod 2 N = N
129 123 126 127 114 128 syl22anc N 0 N mod 2 N = N
130 104 122 129 3eqtr3d N 0 n bits N 2 n = N