Metamath Proof Explorer


Theorem sadaddlem

Description: Lemma for sadadd . (Contributed by Mario Carneiro, 9-Sep-2016)

Ref Expression
Hypotheses sadaddlem.c C = seq 0 c 2 𝑜 , m 0 if cadd m bits A m bits B c 1 𝑜 n 0 if n = 0 n 1
sadaddlem.k K = bits 0 -1
sadaddlem.1 φ A
sadaddlem.2 φ B
sadaddlem.3 φ N 0
Assertion sadaddlem φ bits A sadd bits B 0 ..^ N = bits A + B mod 2 N

Proof

Step Hyp Ref Expression
1 sadaddlem.c C = seq 0 c 2 𝑜 , m 0 if cadd m bits A m bits B c 1 𝑜 n 0 if n = 0 n 1
2 sadaddlem.k K = bits 0 -1
3 sadaddlem.1 φ A
4 sadaddlem.2 φ B
5 sadaddlem.3 φ N 0
6 2nn 2
7 6 a1i φ 2
8 7 5 nnexpcld φ 2 N
9 8 nnzd φ 2 N
10 inss1 bits A 0 ..^ N bits A
11 bitsss bits A 0
12 10 11 sstri bits A 0 ..^ N 0
13 fzofi 0 ..^ N Fin
14 inss2 bits A 0 ..^ N 0 ..^ N
15 ssfi 0 ..^ N Fin bits A 0 ..^ N 0 ..^ N bits A 0 ..^ N Fin
16 13 14 15 mp2an bits A 0 ..^ N Fin
17 elfpw bits A 0 ..^ N 𝒫 0 Fin bits A 0 ..^ N 0 bits A 0 ..^ N Fin
18 12 16 17 mpbir2an bits A 0 ..^ N 𝒫 0 Fin
19 bitsf1o bits 0 : 0 1-1 onto 𝒫 0 Fin
20 f1ocnv bits 0 : 0 1-1 onto 𝒫 0 Fin bits 0 -1 : 𝒫 0 Fin 1-1 onto 0
21 f1of bits 0 -1 : 𝒫 0 Fin 1-1 onto 0 bits 0 -1 : 𝒫 0 Fin 0
22 19 20 21 mp2b bits 0 -1 : 𝒫 0 Fin 0
23 2 feq1i K : 𝒫 0 Fin 0 bits 0 -1 : 𝒫 0 Fin 0
24 22 23 mpbir K : 𝒫 0 Fin 0
25 24 ffvelrni bits A 0 ..^ N 𝒫 0 Fin K bits A 0 ..^ N 0
26 18 25 mp1i φ K bits A 0 ..^ N 0
27 26 nn0zd φ K bits A 0 ..^ N
28 3 27 zsubcld φ A K bits A 0 ..^ N
29 inss1 bits B 0 ..^ N bits B
30 bitsss bits B 0
31 29 30 sstri bits B 0 ..^ N 0
32 inss2 bits B 0 ..^ N 0 ..^ N
33 ssfi 0 ..^ N Fin bits B 0 ..^ N 0 ..^ N bits B 0 ..^ N Fin
34 13 32 33 mp2an bits B 0 ..^ N Fin
35 elfpw bits B 0 ..^ N 𝒫 0 Fin bits B 0 ..^ N 0 bits B 0 ..^ N Fin
36 31 34 35 mpbir2an bits B 0 ..^ N 𝒫 0 Fin
37 24 ffvelrni bits B 0 ..^ N 𝒫 0 Fin K bits B 0 ..^ N 0
38 36 37 mp1i φ K bits B 0 ..^ N 0
39 38 nn0zd φ K bits B 0 ..^ N
40 4 39 zsubcld φ B K bits B 0 ..^ N
41 2 fveq1i K bits A 0 ..^ N = bits 0 -1 bits A 0 ..^ N
42 3 8 zmodcld φ A mod 2 N 0
43 42 fvresd φ bits 0 A mod 2 N = bits A mod 2 N
44 bitsmod A N 0 bits A mod 2 N = bits A 0 ..^ N
45 3 5 44 syl2anc φ bits A mod 2 N = bits A 0 ..^ N
46 43 45 eqtrd φ bits 0 A mod 2 N = bits A 0 ..^ N
47 f1ocnvfv bits 0 : 0 1-1 onto 𝒫 0 Fin A mod 2 N 0 bits 0 A mod 2 N = bits A 0 ..^ N bits 0 -1 bits A 0 ..^ N = A mod 2 N
48 19 42 47 sylancr φ bits 0 A mod 2 N = bits A 0 ..^ N bits 0 -1 bits A 0 ..^ N = A mod 2 N
49 46 48 mpd φ bits 0 -1 bits A 0 ..^ N = A mod 2 N
50 41 49 eqtrid φ K bits A 0 ..^ N = A mod 2 N
51 50 oveq2d φ A K bits A 0 ..^ N = A A mod 2 N
52 51 oveq1d φ A K bits A 0 ..^ N 2 N = A A mod 2 N 2 N
53 3 zred φ A
54 8 nnrpd φ 2 N +
55 moddifz A 2 N + A A mod 2 N 2 N
56 53 54 55 syl2anc φ A A mod 2 N 2 N
57 52 56 eqeltrd φ A K bits A 0 ..^ N 2 N
58 8 nnne0d φ 2 N 0
59 dvdsval2 2 N 2 N 0 A K bits A 0 ..^ N 2 N A K bits A 0 ..^ N A K bits A 0 ..^ N 2 N
60 9 58 28 59 syl3anc φ 2 N A K bits A 0 ..^ N A K bits A 0 ..^ N 2 N
61 57 60 mpbird φ 2 N A K bits A 0 ..^ N
62 2 fveq1i K bits B 0 ..^ N = bits 0 -1 bits B 0 ..^ N
63 4 8 zmodcld φ B mod 2 N 0
64 63 fvresd φ bits 0 B mod 2 N = bits B mod 2 N
65 bitsmod B N 0 bits B mod 2 N = bits B 0 ..^ N
66 4 5 65 syl2anc φ bits B mod 2 N = bits B 0 ..^ N
67 64 66 eqtrd φ bits 0 B mod 2 N = bits B 0 ..^ N
68 f1ocnvfv bits 0 : 0 1-1 onto 𝒫 0 Fin B mod 2 N 0 bits 0 B mod 2 N = bits B 0 ..^ N bits 0 -1 bits B 0 ..^ N = B mod 2 N
69 19 63 68 sylancr φ bits 0 B mod 2 N = bits B 0 ..^ N bits 0 -1 bits B 0 ..^ N = B mod 2 N
70 67 69 mpd φ bits 0 -1 bits B 0 ..^ N = B mod 2 N
71 62 70 eqtrid φ K bits B 0 ..^ N = B mod 2 N
72 71 oveq2d φ B K bits B 0 ..^ N = B B mod 2 N
73 72 oveq1d φ B K bits B 0 ..^ N 2 N = B B mod 2 N 2 N
74 4 zred φ B
75 moddifz B 2 N + B B mod 2 N 2 N
76 74 54 75 syl2anc φ B B mod 2 N 2 N
77 73 76 eqeltrd φ B K bits B 0 ..^ N 2 N
78 dvdsval2 2 N 2 N 0 B K bits B 0 ..^ N 2 N B K bits B 0 ..^ N B K bits B 0 ..^ N 2 N
79 9 58 40 78 syl3anc φ 2 N B K bits B 0 ..^ N B K bits B 0 ..^ N 2 N
80 77 79 mpbird φ 2 N B K bits B 0 ..^ N
81 9 28 40 61 80 dvds2addd φ 2 N A K bits A 0 ..^ N + B - K bits B 0 ..^ N
82 3 zcnd φ A
83 4 zcnd φ B
84 26 nn0cnd φ K bits A 0 ..^ N
85 38 nn0cnd φ K bits B 0 ..^ N
86 82 83 84 85 addsub4d φ A + B - K bits A 0 ..^ N + K bits B 0 ..^ N = A K bits A 0 ..^ N + B - K bits B 0 ..^ N
87 81 86 breqtrrd φ 2 N A + B - K bits A 0 ..^ N + K bits B 0 ..^ N
88 3 4 zaddcld φ A + B
89 27 39 zaddcld φ K bits A 0 ..^ N + K bits B 0 ..^ N
90 moddvds 2 N A + B K bits A 0 ..^ N + K bits B 0 ..^ N A + B mod 2 N = K bits A 0 ..^ N + K bits B 0 ..^ N mod 2 N 2 N A + B - K bits A 0 ..^ N + K bits B 0 ..^ N
91 8 88 89 90 syl3anc φ A + B mod 2 N = K bits A 0 ..^ N + K bits B 0 ..^ N mod 2 N 2 N A + B - K bits A 0 ..^ N + K bits B 0 ..^ N
92 87 91 mpbird φ A + B mod 2 N = K bits A 0 ..^ N + K bits B 0 ..^ N mod 2 N
93 11 a1i φ bits A 0
94 30 a1i φ bits B 0
95 93 94 1 5 2 sadadd3 φ K bits A sadd bits B 0 ..^ N mod 2 N = K bits A 0 ..^ N + K bits B 0 ..^ N mod 2 N
96 inss1 bits A sadd bits B 0 ..^ N bits A sadd bits B
97 sadcl bits A 0 bits B 0 bits A sadd bits B 0
98 11 30 97 mp2an bits A sadd bits B 0
99 96 98 sstri bits A sadd bits B 0 ..^ N 0
100 inss2 bits A sadd bits B 0 ..^ N 0 ..^ N
101 ssfi 0 ..^ N Fin bits A sadd bits B 0 ..^ N 0 ..^ N bits A sadd bits B 0 ..^ N Fin
102 13 100 101 mp2an bits A sadd bits B 0 ..^ N Fin
103 elfpw bits A sadd bits B 0 ..^ N 𝒫 0 Fin bits A sadd bits B 0 ..^ N 0 bits A sadd bits B 0 ..^ N Fin
104 99 102 103 mpbir2an bits A sadd bits B 0 ..^ N 𝒫 0 Fin
105 24 ffvelrni bits A sadd bits B 0 ..^ N 𝒫 0 Fin K bits A sadd bits B 0 ..^ N 0
106 104 105 mp1i φ K bits A sadd bits B 0 ..^ N 0
107 106 nn0red φ K bits A sadd bits B 0 ..^ N
108 106 nn0ge0d φ 0 K bits A sadd bits B 0 ..^ N
109 2 fveq1i K bits A sadd bits B 0 ..^ N = bits 0 -1 bits A sadd bits B 0 ..^ N
110 109 fveq2i bits 0 K bits A sadd bits B 0 ..^ N = bits 0 bits 0 -1 bits A sadd bits B 0 ..^ N
111 106 fvresd φ bits 0 K bits A sadd bits B 0 ..^ N = bits K bits A sadd bits B 0 ..^ N
112 104 a1i φ bits A sadd bits B 0 ..^ N 𝒫 0 Fin
113 f1ocnvfv2 bits 0 : 0 1-1 onto 𝒫 0 Fin bits A sadd bits B 0 ..^ N 𝒫 0 Fin bits 0 bits 0 -1 bits A sadd bits B 0 ..^ N = bits A sadd bits B 0 ..^ N
114 19 112 113 sylancr φ bits 0 bits 0 -1 bits A sadd bits B 0 ..^ N = bits A sadd bits B 0 ..^ N
115 110 111 114 3eqtr3a φ bits K bits A sadd bits B 0 ..^ N = bits A sadd bits B 0 ..^ N
116 115 100 eqsstrdi φ bits K bits A sadd bits B 0 ..^ N 0 ..^ N
117 106 nn0zd φ K bits A sadd bits B 0 ..^ N
118 bitsfzo K bits A sadd bits B 0 ..^ N N 0 K bits A sadd bits B 0 ..^ N 0 ..^ 2 N bits K bits A sadd bits B 0 ..^ N 0 ..^ N
119 117 5 118 syl2anc φ K bits A sadd bits B 0 ..^ N 0 ..^ 2 N bits K bits A sadd bits B 0 ..^ N 0 ..^ N
120 116 119 mpbird φ K bits A sadd bits B 0 ..^ N 0 ..^ 2 N
121 elfzolt2 K bits A sadd bits B 0 ..^ N 0 ..^ 2 N K bits A sadd bits B 0 ..^ N < 2 N
122 120 121 syl φ K bits A sadd bits B 0 ..^ N < 2 N
123 modid K bits A sadd bits B 0 ..^ N 2 N + 0 K bits A sadd bits B 0 ..^ N K bits A sadd bits B 0 ..^ N < 2 N K bits A sadd bits B 0 ..^ N mod 2 N = K bits A sadd bits B 0 ..^ N
124 107 54 108 122 123 syl22anc φ K bits A sadd bits B 0 ..^ N mod 2 N = K bits A sadd bits B 0 ..^ N
125 92 95 124 3eqtr2d φ A + B mod 2 N = K bits A sadd bits B 0 ..^ N
126 125 fveq2d φ bits A + B mod 2 N = bits K bits A sadd bits B 0 ..^ N
127 126 115 eqtr2d φ bits A sadd bits B 0 ..^ N = bits A + B mod 2 N