Metamath Proof Explorer


Theorem bitsmod

Description: Truncating the bit sequence after some M is equivalent to reducing the argument mod 2 ^ M . (Contributed by Mario Carneiro, 6-Sep-2016)

Ref Expression
Assertion bitsmod N M 0 bits N mod 2 M = bits N 0 ..^ M

Proof

Step Hyp Ref Expression
1 simpl N M 0 N
2 2nn 2
3 2 a1i N M 0 2
4 simpr N M 0 M 0
5 3 4 nnexpcld N M 0 2 M
6 1 5 zmodcld N M 0 N mod 2 M 0
7 6 nn0zd N M 0 N mod 2 M
8 7 biantrurd N M 0 x 0 ¬ 2 N mod 2 M 2 x N mod 2 M x 0 ¬ 2 N mod 2 M 2 x
9 1 ad2antrr N M 0 x 0 x < M N
10 simplr N M 0 x 0 x < M x 0
11 bitsval2 N x 0 x bits N ¬ 2 N 2 x
12 9 10 11 syl2anc N M 0 x 0 x < M x bits N ¬ 2 N 2 x
13 simpr N M 0 x 0 x < M x < M
14 13 biantrud N M 0 x 0 x < M x bits N x bits N x < M
15 2z 2
16 15 a1i N M 0 x 0 x < M 2
17 9 zred N M 0 x 0 x < M N
18 2 a1i N M 0 x 0 x < M 2
19 18 10 nnexpcld N M 0 x 0 x < M 2 x
20 17 19 nndivred N M 0 x 0 x < M N 2 x
21 20 flcld N M 0 x 0 x < M N 2 x
22 7 ad2antrr N M 0 x 0 x < M N mod 2 M
23 22 zred N M 0 x 0 x < M N mod 2 M
24 23 19 nndivred N M 0 x 0 x < M N mod 2 M 2 x
25 24 flcld N M 0 x 0 x < M N mod 2 M 2 x
26 19 nnzd N M 0 x 0 x < M 2 x
27 26 16 zmulcld N M 0 x 0 x < M 2 x 2
28 5 ad2antrr N M 0 x 0 x < M 2 M
29 28 nnzd N M 0 x 0 x < M 2 M
30 9 22 zsubcld N M 0 x 0 x < M N N mod 2 M
31 2cnd N M 0 x 0 x < M 2
32 31 10 expp1d N M 0 x 0 x < M 2 x + 1 = 2 x 2
33 1nn0 1 0
34 33 a1i N M 0 x 0 x < M 1 0
35 10 34 nn0addcld N M 0 x 0 x < M x + 1 0
36 35 nn0zd N M 0 x 0 x < M x + 1
37 simplr N M 0 x 0 M 0
38 37 adantr N M 0 x 0 x < M M 0
39 38 nn0zd N M 0 x 0 x < M M
40 nn0ltp1le x 0 M 0 x < M x + 1 M
41 10 38 40 syl2anc N M 0 x 0 x < M x < M x + 1 M
42 13 41 mpbid N M 0 x 0 x < M x + 1 M
43 eluz2 M x + 1 x + 1 M x + 1 M
44 36 39 42 43 syl3anbrc N M 0 x 0 x < M M x + 1
45 dvdsexp 2 x + 1 0 M x + 1 2 x + 1 2 M
46 16 35 44 45 syl3anc N M 0 x 0 x < M 2 x + 1 2 M
47 32 46 eqbrtrrd N M 0 x 0 x < M 2 x 2 2 M
48 28 nnrpd N M 0 x 0 x < M 2 M +
49 moddifz N 2 M + N N mod 2 M 2 M
50 17 48 49 syl2anc N M 0 x 0 x < M N N mod 2 M 2 M
51 2ne0 2 0
52 51 a1i N M 0 x 0 x < M 2 0
53 31 52 39 expne0d N M 0 x 0 x < M 2 M 0
54 dvdsval2 2 M 2 M 0 N N mod 2 M 2 M N N mod 2 M N N mod 2 M 2 M
55 29 53 30 54 syl3anc N M 0 x 0 x < M 2 M N N mod 2 M N N mod 2 M 2 M
56 50 55 mpbird N M 0 x 0 x < M 2 M N N mod 2 M
57 27 29 30 47 56 dvdstrd N M 0 x 0 x < M 2 x 2 N N mod 2 M
58 30 zcnd N M 0 x 0 x < M N N mod 2 M
59 19 nncnd N M 0 x 0 x < M 2 x
60 10 nn0zd N M 0 x 0 x < M x
61 31 52 60 expne0d N M 0 x 0 x < M 2 x 0
62 58 59 61 divcan2d N M 0 x 0 x < M 2 x N N mod 2 M 2 x = N N mod 2 M
63 57 62 breqtrrd N M 0 x 0 x < M 2 x 2 2 x N N mod 2 M 2 x
64 10 nn0red N M 0 x 0 x < M x
65 38 nn0red N M 0 x 0 x < M M
66 64 65 13 ltled N M 0 x 0 x < M x M
67 eluz2 M x x M x M
68 60 39 66 67 syl3anbrc N M 0 x 0 x < M M x
69 dvdsexp 2 x 0 M x 2 x 2 M
70 16 10 68 69 syl3anc N M 0 x 0 x < M 2 x 2 M
71 26 29 30 70 56 dvdstrd N M 0 x 0 x < M 2 x N N mod 2 M
72 dvdsval2 2 x 2 x 0 N N mod 2 M 2 x N N mod 2 M N N mod 2 M 2 x
73 26 61 30 72 syl3anc N M 0 x 0 x < M 2 x N N mod 2 M N N mod 2 M 2 x
74 71 73 mpbid N M 0 x 0 x < M N N mod 2 M 2 x
75 dvdscmulr 2 N N mod 2 M 2 x 2 x 2 x 0 2 x 2 2 x N N mod 2 M 2 x 2 N N mod 2 M 2 x
76 16 74 26 61 75 syl112anc N M 0 x 0 x < M 2 x 2 2 x N N mod 2 M 2 x 2 N N mod 2 M 2 x
77 63 76 mpbid N M 0 x 0 x < M 2 N N mod 2 M 2 x
78 25 zcnd N M 0 x 0 x < M N mod 2 M 2 x
79 74 zcnd N M 0 x 0 x < M N N mod 2 M 2 x
80 22 zcnd N M 0 x 0 x < M N mod 2 M
81 9 zcnd N M 0 x 0 x < M N
82 80 81 pncan3d N M 0 x 0 x < M N mod 2 M + N - N mod 2 M = N
83 82 oveq1d N M 0 x 0 x < M N mod 2 M + N - N mod 2 M 2 x = N 2 x
84 80 58 59 61 divdird N M 0 x 0 x < M N mod 2 M + N - N mod 2 M 2 x = N mod 2 M 2 x + N N mod 2 M 2 x
85 83 84 eqtr3d N M 0 x 0 x < M N 2 x = N mod 2 M 2 x + N N mod 2 M 2 x
86 85 fveq2d N M 0 x 0 x < M N 2 x = N mod 2 M 2 x + N N mod 2 M 2 x
87 fladdz N mod 2 M 2 x N N mod 2 M 2 x N mod 2 M 2 x + N N mod 2 M 2 x = N mod 2 M 2 x + N N mod 2 M 2 x
88 24 74 87 syl2anc N M 0 x 0 x < M N mod 2 M 2 x + N N mod 2 M 2 x = N mod 2 M 2 x + N N mod 2 M 2 x
89 86 88 eqtrd N M 0 x 0 x < M N 2 x = N mod 2 M 2 x + N N mod 2 M 2 x
90 78 79 89 mvrladdd N M 0 x 0 x < M N 2 x N mod 2 M 2 x = N N mod 2 M 2 x
91 77 90 breqtrrd N M 0 x 0 x < M 2 N 2 x N mod 2 M 2 x
92 dvdssub2 2 N 2 x N mod 2 M 2 x 2 N 2 x N mod 2 M 2 x 2 N 2 x 2 N mod 2 M 2 x
93 16 21 25 91 92 syl31anc N M 0 x 0 x < M 2 N 2 x 2 N mod 2 M 2 x
94 93 notbid N M 0 x 0 x < M ¬ 2 N 2 x ¬ 2 N mod 2 M 2 x
95 12 14 94 3bitr3d N M 0 x 0 x < M x bits N x < M ¬ 2 N mod 2 M 2 x
96 z0even 2 0
97 1 ad2antrr N M 0 x 0 ¬ x < M N
98 97 zred N M 0 x 0 ¬ x < M N
99 2rp 2 +
100 99 a1i N M 0 x 0 ¬ x < M 2 +
101 37 nn0zd N M 0 x 0 M
102 101 adantr N M 0 x 0 ¬ x < M M
103 100 102 rpexpcld N M 0 x 0 ¬ x < M 2 M +
104 98 103 modcld N M 0 x 0 ¬ x < M N mod 2 M
105 simplr N M 0 x 0 ¬ x < M x 0
106 105 nn0zd N M 0 x 0 ¬ x < M x
107 100 106 rpexpcld N M 0 x 0 ¬ x < M 2 x +
108 6 ad2antrr N M 0 x 0 ¬ x < M N mod 2 M 0
109 108 nn0ge0d N M 0 x 0 ¬ x < M 0 N mod 2 M
110 104 107 109 divge0d N M 0 x 0 ¬ x < M 0 N mod 2 M 2 x
111 103 rpred N M 0 x 0 ¬ x < M 2 M
112 107 rpred N M 0 x 0 ¬ x < M 2 x
113 modlt N 2 M + N mod 2 M < 2 M
114 98 103 113 syl2anc N M 0 x 0 ¬ x < M N mod 2 M < 2 M
115 100 rpred N M 0 x 0 ¬ x < M 2
116 1le2 1 2
117 116 a1i N M 0 x 0 ¬ x < M 1 2
118 102 zred N M 0 x 0 ¬ x < M M
119 105 nn0red N M 0 x 0 ¬ x < M x
120 simpr N M 0 x 0 ¬ x < M ¬ x < M
121 118 119 120 nltled N M 0 x 0 ¬ x < M M x
122 eluz2 x M M x M x
123 102 106 121 122 syl3anbrc N M 0 x 0 ¬ x < M x M
124 115 117 123 leexp2ad N M 0 x 0 ¬ x < M 2 M 2 x
125 104 111 112 114 124 ltletrd N M 0 x 0 ¬ x < M N mod 2 M < 2 x
126 107 rpcnd N M 0 x 0 ¬ x < M 2 x
127 126 mulid1d N M 0 x 0 ¬ x < M 2 x 1 = 2 x
128 125 127 breqtrrd N M 0 x 0 ¬ x < M N mod 2 M < 2 x 1
129 1red N M 0 x 0 ¬ x < M 1
130 104 129 107 ltdivmuld N M 0 x 0 ¬ x < M N mod 2 M 2 x < 1 N mod 2 M < 2 x 1
131 128 130 mpbird N M 0 x 0 ¬ x < M N mod 2 M 2 x < 1
132 1e0p1 1 = 0 + 1
133 131 132 breqtrdi N M 0 x 0 ¬ x < M N mod 2 M 2 x < 0 + 1
134 104 107 rerpdivcld N M 0 x 0 ¬ x < M N mod 2 M 2 x
135 0z 0
136 flbi N mod 2 M 2 x 0 N mod 2 M 2 x = 0 0 N mod 2 M 2 x N mod 2 M 2 x < 0 + 1
137 134 135 136 sylancl N M 0 x 0 ¬ x < M N mod 2 M 2 x = 0 0 N mod 2 M 2 x N mod 2 M 2 x < 0 + 1
138 110 133 137 mpbir2and N M 0 x 0 ¬ x < M N mod 2 M 2 x = 0
139 96 138 breqtrrid N M 0 x 0 ¬ x < M 2 N mod 2 M 2 x
140 120 intnand N M 0 x 0 ¬ x < M ¬ x bits N x < M
141 139 140 2thd N M 0 x 0 ¬ x < M 2 N mod 2 M 2 x ¬ x bits N x < M
142 141 con2bid N M 0 x 0 ¬ x < M x bits N x < M ¬ 2 N mod 2 M 2 x
143 95 142 pm2.61dan N M 0 x 0 x bits N x < M ¬ 2 N mod 2 M 2 x
144 101 biantrurd N M 0 x 0 x bits N x < M M x bits N x < M
145 143 144 bitr3d N M 0 x 0 ¬ 2 N mod 2 M 2 x M x bits N x < M
146 an12 M x bits N x < M x bits N M x < M
147 145 146 bitrdi N M 0 x 0 ¬ 2 N mod 2 M 2 x x bits N M x < M
148 147 pm5.32da N M 0 x 0 ¬ 2 N mod 2 M 2 x x 0 x bits N M x < M
149 8 148 bitr3d N M 0 N mod 2 M x 0 ¬ 2 N mod 2 M 2 x x 0 x bits N M x < M
150 3anass N mod 2 M x 0 ¬ 2 N mod 2 M 2 x N mod 2 M x 0 ¬ 2 N mod 2 M 2 x
151 elfzo2 x 0 ..^ M x 0 M x < M
152 elnn0uz x 0 x 0
153 152 3anbi1i x 0 M x < M x 0 M x < M
154 3anass x 0 M x < M x 0 M x < M
155 151 153 154 3bitr2i x 0 ..^ M x 0 M x < M
156 155 anbi2i x bits N x 0 ..^ M x bits N x 0 M x < M
157 an12 x bits N x 0 M x < M x 0 x bits N M x < M
158 156 157 bitri x bits N x 0 ..^ M x 0 x bits N M x < M
159 149 150 158 3bitr4g N M 0 N mod 2 M x 0 ¬ 2 N mod 2 M 2 x x bits N x 0 ..^ M
160 bitsval x bits N mod 2 M N mod 2 M x 0 ¬ 2 N mod 2 M 2 x
161 elin x bits N 0 ..^ M x bits N x 0 ..^ M
162 159 160 161 3bitr4g N M 0 x bits N mod 2 M x bits N 0 ..^ M
163 162 eqrdv N M 0 bits N mod 2 M = bits N 0 ..^ M