Metamath Proof Explorer


Theorem bitsres

Description: Restrict the bits of a number to an upper integer set. (Contributed by Mario Carneiro, 5-Sep-2016)

Ref Expression
Assertion bitsres A N 0 bits A N = bits A 2 N 2 N

Proof

Step Hyp Ref Expression
1 simpl A N 0 A
2 2nn 2
3 2 a1i A N 0 2
4 simpr A N 0 N 0
5 3 4 nnexpcld A N 0 2 N
6 1 5 zmodcld A N 0 A mod 2 N 0
7 6 nn0zd A N 0 A mod 2 N
8 7 znegcld A N 0 A mod 2 N
9 sadadd A mod 2 N A bits A mod 2 N sadd bits A = bits - A mod 2 N + A
10 8 1 9 syl2anc A N 0 bits A mod 2 N sadd bits A = bits - A mod 2 N + A
11 sadadd A mod 2 N A mod 2 N bits A mod 2 N sadd bits A mod 2 N = bits - A mod 2 N + A mod 2 N
12 8 7 11 syl2anc A N 0 bits A mod 2 N sadd bits A mod 2 N = bits - A mod 2 N + A mod 2 N
13 8 zcnd A N 0 A mod 2 N
14 7 zcnd A N 0 A mod 2 N
15 13 14 addcomd A N 0 - A mod 2 N + A mod 2 N = A mod 2 N + A mod 2 N
16 14 negidd A N 0 A mod 2 N + A mod 2 N = 0
17 15 16 eqtrd A N 0 - A mod 2 N + A mod 2 N = 0
18 17 fveq2d A N 0 bits - A mod 2 N + A mod 2 N = bits 0
19 0bits bits 0 =
20 18 19 eqtrdi A N 0 bits - A mod 2 N + A mod 2 N =
21 12 20 eqtrd A N 0 bits A mod 2 N sadd bits A mod 2 N =
22 21 oveq1d A N 0 bits A mod 2 N sadd bits A mod 2 N sadd bits A N = sadd bits A N
23 bitsss bits A mod 2 N 0
24 bitsss bits A mod 2 N 0
25 inss1 bits A N bits A
26 bitsss bits A 0
27 26 a1i A N 0 bits A 0
28 25 27 sstrid A N 0 bits A N 0
29 sadass bits A mod 2 N 0 bits A mod 2 N 0 bits A N 0 bits A mod 2 N sadd bits A mod 2 N sadd bits A N = bits A mod 2 N sadd bits A mod 2 N sadd bits A N
30 23 24 28 29 mp3an12i A N 0 bits A mod 2 N sadd bits A mod 2 N sadd bits A N = bits A mod 2 N sadd bits A mod 2 N sadd bits A N
31 bitsmod A N 0 bits A mod 2 N = bits A 0 ..^ N
32 31 oveq1d A N 0 bits A mod 2 N sadd bits A N = bits A 0 ..^ N sadd bits A N
33 inss1 bits A 0 ..^ N bits A
34 33 27 sstrid A N 0 bits A 0 ..^ N 0
35 fzouzdisj 0 ..^ N N =
36 35 ineq2i bits A 0 ..^ N N = bits A
37 inindi bits A 0 ..^ N N = bits A 0 ..^ N bits A N
38 in0 bits A =
39 36 37 38 3eqtr3i bits A 0 ..^ N bits A N =
40 39 a1i A N 0 bits A 0 ..^ N bits A N =
41 34 28 40 saddisj A N 0 bits A 0 ..^ N sadd bits A N = bits A 0 ..^ N bits A N
42 indi bits A 0 ..^ N N = bits A 0 ..^ N bits A N
43 41 42 eqtr4di A N 0 bits A 0 ..^ N sadd bits A N = bits A 0 ..^ N N
44 nn0uz 0 = 0
45 4 44 eleqtrdi A N 0 N 0
46 fzouzsplit N 0 0 = 0 ..^ N N
47 45 46 syl A N 0 0 = 0 ..^ N N
48 44 47 eqtrid A N 0 0 = 0 ..^ N N
49 26 48 sseqtrid A N 0 bits A 0 ..^ N N
50 df-ss bits A 0 ..^ N N bits A 0 ..^ N N = bits A
51 49 50 sylib A N 0 bits A 0 ..^ N N = bits A
52 43 51 eqtrd A N 0 bits A 0 ..^ N sadd bits A N = bits A
53 32 52 eqtrd A N 0 bits A mod 2 N sadd bits A N = bits A
54 53 oveq2d A N 0 bits A mod 2 N sadd bits A mod 2 N sadd bits A N = bits A mod 2 N sadd bits A
55 30 54 eqtrd A N 0 bits A mod 2 N sadd bits A mod 2 N sadd bits A N = bits A mod 2 N sadd bits A
56 sadid2 bits A N 0 sadd bits A N = bits A N
57 28 56 syl A N 0 sadd bits A N = bits A N
58 22 55 57 3eqtr3d A N 0 bits A mod 2 N sadd bits A = bits A N
59 1 zcnd A N 0 A
60 13 59 addcomd A N 0 - A mod 2 N + A = A + A mod 2 N
61 59 14 negsubd A N 0 A + A mod 2 N = A A mod 2 N
62 59 14 subcld A N 0 A A mod 2 N
63 5 nncnd A N 0 2 N
64 5 nnne0d A N 0 2 N 0
65 62 63 64 divcan1d A N 0 A A mod 2 N 2 N 2 N = A A mod 2 N
66 1 zred A N 0 A
67 5 nnrpd A N 0 2 N +
68 moddiffl A 2 N + A A mod 2 N 2 N = A 2 N
69 66 67 68 syl2anc A N 0 A A mod 2 N 2 N = A 2 N
70 69 oveq1d A N 0 A A mod 2 N 2 N 2 N = A 2 N 2 N
71 61 65 70 3eqtr2d A N 0 A + A mod 2 N = A 2 N 2 N
72 60 71 eqtrd A N 0 - A mod 2 N + A = A 2 N 2 N
73 72 fveq2d A N 0 bits - A mod 2 N + A = bits A 2 N 2 N
74 10 58 73 3eqtr3d A N 0 bits A N = bits A 2 N 2 N