Metamath Proof Explorer


Theorem bitsinv1lem

Description: Lemma for bitsinv1 . (Contributed by Mario Carneiro, 22-Sep-2016)

Ref Expression
Assertion bitsinv1lem N M 0 N mod 2 M + 1 = N mod 2 M + if M bits N 2 M 0

Proof

Step Hyp Ref Expression
1 oveq2 2 M = if M bits N 2 M 0 N mod 2 M + 2 M = N mod 2 M + if M bits N 2 M 0
2 1 eqeq2d 2 M = if M bits N 2 M 0 N mod 2 M + 1 = N mod 2 M + 2 M N mod 2 M + 1 = N mod 2 M + if M bits N 2 M 0
3 oveq2 0 = if M bits N 2 M 0 N mod 2 M + 0 = N mod 2 M + if M bits N 2 M 0
4 3 eqeq2d 0 = if M bits N 2 M 0 N mod 2 M + 1 = N mod 2 M + 0 N mod 2 M + 1 = N mod 2 M + if M bits N 2 M 0
5 simpl N M 0 N
6 2nn 2
7 6 a1i N M 0 2
8 simpr N M 0 M 0
9 7 8 nnexpcld N M 0 2 M
10 5 9 zmodcld N M 0 N mod 2 M 0
11 10 nn0cnd N M 0 N mod 2 M
12 11 adantr N M 0 M bits N N mod 2 M
13 1nn0 1 0
14 13 a1i N M 0 1 0
15 8 14 nn0addcld N M 0 M + 1 0
16 7 15 nnexpcld N M 0 2 M + 1
17 5 16 zmodcld N M 0 N mod 2 M + 1 0
18 17 nn0cnd N M 0 N mod 2 M + 1
19 18 adantr N M 0 M bits N N mod 2 M + 1
20 12 19 pncan3d N M 0 M bits N N mod 2 M + N mod 2 M + 1 - N mod 2 M = N mod 2 M + 1
21 18 11 subcld N M 0 N mod 2 M + 1 N mod 2 M
22 21 adantr N M 0 M bits N N mod 2 M + 1 N mod 2 M
23 6 a1i N M 0 M bits N 2
24 simplr N M 0 M bits N M 0
25 23 24 nnexpcld N M 0 M bits N 2 M
26 25 nncnd N M 0 M bits N 2 M
27 2cnd N M 0 2
28 2ne0 2 0
29 28 a1i N M 0 2 0
30 8 nn0zd N M 0 M
31 27 29 30 expne0d N M 0 2 M 0
32 31 adantr N M 0 M bits N 2 M 0
33 z0even 2 0
34 id N mod 2 M + 1 N mod 2 M 2 M = 0 N mod 2 M + 1 N mod 2 M 2 M = 0
35 33 34 breqtrrid N mod 2 M + 1 N mod 2 M 2 M = 0 2 N mod 2 M + 1 N mod 2 M 2 M
36 bitsval2 N M 0 M bits N ¬ 2 N 2 M
37 5 zred N M 0 N
38 9 nnrpd N M 0 2 M +
39 moddiffl N 2 M + N N mod 2 M 2 M = N 2 M
40 37 38 39 syl2anc N M 0 N N mod 2 M 2 M = N 2 M
41 40 breq2d N M 0 2 N N mod 2 M 2 M 2 N 2 M
42 2z 2
43 42 a1i N M 0 2
44 moddifz N 2 M + N N mod 2 M 2 M
45 37 38 44 syl2anc N M 0 N N mod 2 M 2 M
46 5 zcnd N M 0 N
47 46 11 18 nnncan1d N M 0 N - N mod 2 M - N N mod 2 M + 1 = N mod 2 M + 1 N mod 2 M
48 47 oveq1d N M 0 N - N mod 2 M - N N mod 2 M + 1 2 M = N mod 2 M + 1 N mod 2 M 2 M
49 46 11 subcld N M 0 N N mod 2 M
50 46 18 subcld N M 0 N N mod 2 M + 1
51 9 nncnd N M 0 2 M
52 49 50 51 31 divsubdird N M 0 N - N mod 2 M - N N mod 2 M + 1 2 M = N N mod 2 M 2 M N N mod 2 M + 1 2 M
53 48 52 eqtr3d N M 0 N mod 2 M + 1 N mod 2 M 2 M = N N mod 2 M 2 M N N mod 2 M + 1 2 M
54 27 50 mulcomd N M 0 2 N N mod 2 M + 1 = N N mod 2 M + 1 2
55 27 51 mulcomd N M 0 2 2 M = 2 M 2
56 27 8 expp1d N M 0 2 M + 1 = 2 M 2
57 55 56 eqtr4d N M 0 2 2 M = 2 M + 1
58 54 57 oveq12d N M 0 2 N N mod 2 M + 1 2 2 M = N N mod 2 M + 1 2 2 M + 1
59 50 51 27 31 29 divcan5d N M 0 2 N N mod 2 M + 1 2 2 M = N N mod 2 M + 1 2 M
60 16 nncnd N M 0 2 M + 1
61 30 peano2zd N M 0 M + 1
62 27 29 61 expne0d N M 0 2 M + 1 0
63 50 27 60 62 div23d N M 0 N N mod 2 M + 1 2 2 M + 1 = N N mod 2 M + 1 2 M + 1 2
64 58 59 63 3eqtr3d N M 0 N N mod 2 M + 1 2 M = N N mod 2 M + 1 2 M + 1 2
65 16 nnrpd N M 0 2 M + 1 +
66 moddifz N 2 M + 1 + N N mod 2 M + 1 2 M + 1
67 37 65 66 syl2anc N M 0 N N mod 2 M + 1 2 M + 1
68 67 43 zmulcld N M 0 N N mod 2 M + 1 2 M + 1 2
69 64 68 eqeltrd N M 0 N N mod 2 M + 1 2 M
70 45 69 zsubcld N M 0 N N mod 2 M 2 M N N mod 2 M + 1 2 M
71 53 70 eqeltrd N M 0 N mod 2 M + 1 N mod 2 M 2 M
72 dvdsmul2 N N mod 2 M + 1 2 M + 1 2 2 N N mod 2 M + 1 2 M + 1 2
73 67 43 72 syl2anc N M 0 2 N N mod 2 M + 1 2 M + 1 2
74 46 18 11 nnncan2d N M 0 N - N mod 2 M - N mod 2 M + 1 N mod 2 M = N N mod 2 M + 1
75 74 oveq1d N M 0 N - N mod 2 M - N mod 2 M + 1 N mod 2 M 2 M = N N mod 2 M + 1 2 M
76 49 21 51 31 divsubdird N M 0 N - N mod 2 M - N mod 2 M + 1 N mod 2 M 2 M = N N mod 2 M 2 M N mod 2 M + 1 N mod 2 M 2 M
77 75 76 64 3eqtr3d N M 0 N N mod 2 M 2 M N mod 2 M + 1 N mod 2 M 2 M = N N mod 2 M + 1 2 M + 1 2
78 73 77 breqtrrd N M 0 2 N N mod 2 M 2 M N mod 2 M + 1 N mod 2 M 2 M
79 dvdssub2 2 N N mod 2 M 2 M N mod 2 M + 1 N mod 2 M 2 M 2 N N mod 2 M 2 M N mod 2 M + 1 N mod 2 M 2 M 2 N N mod 2 M 2 M 2 N mod 2 M + 1 N mod 2 M 2 M
80 43 45 71 78 79 syl31anc N M 0 2 N N mod 2 M 2 M 2 N mod 2 M + 1 N mod 2 M 2 M
81 41 80 bitr3d N M 0 2 N 2 M 2 N mod 2 M + 1 N mod 2 M 2 M
82 81 notbid N M 0 ¬ 2 N 2 M ¬ 2 N mod 2 M + 1 N mod 2 M 2 M
83 36 82 bitrd N M 0 M bits N ¬ 2 N mod 2 M + 1 N mod 2 M 2 M
84 83 con2bid N M 0 2 N mod 2 M + 1 N mod 2 M 2 M ¬ M bits N
85 35 84 syl5ib N M 0 N mod 2 M + 1 N mod 2 M 2 M = 0 ¬ M bits N
86 85 con2d N M 0 M bits N ¬ N mod 2 M + 1 N mod 2 M 2 M = 0
87 df-neg 1 = 0 1
88 51 mulm1d N M 0 -1 2 M = 2 M
89 9 nnred N M 0 2 M
90 89 renegcld N M 0 2 M
91 37 38 modcld N M 0 N mod 2 M
92 91 renegcld N M 0 N mod 2 M
93 37 65 modcld N M 0 N mod 2 M + 1
94 93 91 resubcld N M 0 N mod 2 M + 1 N mod 2 M
95 modlt N 2 M + N mod 2 M < 2 M
96 37 38 95 syl2anc N M 0 N mod 2 M < 2 M
97 91 89 ltnegd N M 0 N mod 2 M < 2 M 2 M < N mod 2 M
98 96 97 mpbid N M 0 2 M < N mod 2 M
99 df-neg N mod 2 M = 0 N mod 2 M
100 0red N M 0 0
101 modge0 N 2 M + 1 + 0 N mod 2 M + 1
102 37 65 101 syl2anc N M 0 0 N mod 2 M + 1
103 100 93 91 102 lesub1dd N M 0 0 N mod 2 M N mod 2 M + 1 N mod 2 M
104 99 103 eqbrtrid N M 0 N mod 2 M N mod 2 M + 1 N mod 2 M
105 90 92 94 98 104 ltletrd N M 0 2 M < N mod 2 M + 1 N mod 2 M
106 88 105 eqbrtrd N M 0 -1 2 M < N mod 2 M + 1 N mod 2 M
107 1red N M 0 1
108 107 renegcld N M 0 1
109 108 94 38 ltmuldivd N M 0 -1 2 M < N mod 2 M + 1 N mod 2 M 1 < N mod 2 M + 1 N mod 2 M 2 M
110 106 109 mpbid N M 0 1 < N mod 2 M + 1 N mod 2 M 2 M
111 87 110 eqbrtrrid N M 0 0 1 < N mod 2 M + 1 N mod 2 M 2 M
112 0zd N M 0 0
113 zlem1lt 0 N mod 2 M + 1 N mod 2 M 2 M 0 N mod 2 M + 1 N mod 2 M 2 M 0 1 < N mod 2 M + 1 N mod 2 M 2 M
114 112 71 113 syl2anc N M 0 0 N mod 2 M + 1 N mod 2 M 2 M 0 1 < N mod 2 M + 1 N mod 2 M 2 M
115 111 114 mpbird N M 0 0 N mod 2 M + 1 N mod 2 M 2 M
116 elnn0z N mod 2 M + 1 N mod 2 M 2 M 0 N mod 2 M + 1 N mod 2 M 2 M 0 N mod 2 M + 1 N mod 2 M 2 M
117 71 115 116 sylanbrc N M 0 N mod 2 M + 1 N mod 2 M 2 M 0
118 nn0uz 0 = 0
119 117 118 eleqtrdi N M 0 N mod 2 M + 1 N mod 2 M 2 M 0
120 16 nnred N M 0 2 M + 1
121 modge0 N 2 M + 0 N mod 2 M
122 37 38 121 syl2anc N M 0 0 N mod 2 M
123 93 91 subge02d N M 0 0 N mod 2 M N mod 2 M + 1 N mod 2 M N mod 2 M + 1
124 122 123 mpbid N M 0 N mod 2 M + 1 N mod 2 M N mod 2 M + 1
125 modlt N 2 M + 1 + N mod 2 M + 1 < 2 M + 1
126 37 65 125 syl2anc N M 0 N mod 2 M + 1 < 2 M + 1
127 94 93 120 124 126 lelttrd N M 0 N mod 2 M + 1 N mod 2 M < 2 M + 1
128 127 56 breqtrd N M 0 N mod 2 M + 1 N mod 2 M < 2 M 2
129 7 nnred N M 0 2
130 94 129 38 ltdivmuld N M 0 N mod 2 M + 1 N mod 2 M 2 M < 2 N mod 2 M + 1 N mod 2 M < 2 M 2
131 128 130 mpbird N M 0 N mod 2 M + 1 N mod 2 M 2 M < 2
132 elfzo2 N mod 2 M + 1 N mod 2 M 2 M 0 ..^ 2 N mod 2 M + 1 N mod 2 M 2 M 0 2 N mod 2 M + 1 N mod 2 M 2 M < 2
133 119 43 131 132 syl3anbrc N M 0 N mod 2 M + 1 N mod 2 M 2 M 0 ..^ 2
134 fzo0to2pr 0 ..^ 2 = 0 1
135 133 134 eleqtrdi N M 0 N mod 2 M + 1 N mod 2 M 2 M 0 1
136 elpri N mod 2 M + 1 N mod 2 M 2 M 0 1 N mod 2 M + 1 N mod 2 M 2 M = 0 N mod 2 M + 1 N mod 2 M 2 M = 1
137 135 136 syl N M 0 N mod 2 M + 1 N mod 2 M 2 M = 0 N mod 2 M + 1 N mod 2 M 2 M = 1
138 137 ord N M 0 ¬ N mod 2 M + 1 N mod 2 M 2 M = 0 N mod 2 M + 1 N mod 2 M 2 M = 1
139 86 138 syld N M 0 M bits N N mod 2 M + 1 N mod 2 M 2 M = 1
140 139 imp N M 0 M bits N N mod 2 M + 1 N mod 2 M 2 M = 1
141 22 26 32 140 diveq1d N M 0 M bits N N mod 2 M + 1 N mod 2 M = 2 M
142 141 oveq2d N M 0 M bits N N mod 2 M + N mod 2 M + 1 - N mod 2 M = N mod 2 M + 2 M
143 20 142 eqtr3d N M 0 M bits N N mod 2 M + 1 = N mod 2 M + 2 M
144 18 adantr N M 0 ¬ M bits N N mod 2 M + 1
145 11 adantr N M 0 ¬ M bits N N mod 2 M
146 21 adantr N M 0 ¬ M bits N N mod 2 M + 1 N mod 2 M
147 51 adantr N M 0 ¬ M bits N 2 M
148 31 adantr N M 0 ¬ M bits N 2 M 0
149 n2dvds1 ¬ 2 1
150 breq2 N mod 2 M + 1 N mod 2 M 2 M = 1 2 N mod 2 M + 1 N mod 2 M 2 M 2 1
151 149 150 mtbiri N mod 2 M + 1 N mod 2 M 2 M = 1 ¬ 2 N mod 2 M + 1 N mod 2 M 2 M
152 138 151 syl6 N M 0 ¬ N mod 2 M + 1 N mod 2 M 2 M = 0 ¬ 2 N mod 2 M + 1 N mod 2 M 2 M
153 152 83 sylibrd N M 0 ¬ N mod 2 M + 1 N mod 2 M 2 M = 0 M bits N
154 153 con1d N M 0 ¬ M bits N N mod 2 M + 1 N mod 2 M 2 M = 0
155 154 imp N M 0 ¬ M bits N N mod 2 M + 1 N mod 2 M 2 M = 0
156 146 147 148 155 diveq0d N M 0 ¬ M bits N N mod 2 M + 1 N mod 2 M = 0
157 144 145 156 subeq0d N M 0 ¬ M bits N N mod 2 M + 1 = N mod 2 M
158 145 addid1d N M 0 ¬ M bits N N mod 2 M + 0 = N mod 2 M
159 157 158 eqtr4d N M 0 ¬ M bits N N mod 2 M + 1 = N mod 2 M + 0
160 2 4 143 159 ifbothda N M 0 N mod 2 M + 1 = N mod 2 M + if M bits N 2 M 0