Metamath Proof Explorer


Theorem sadadd3

Description: Sum of initial segments of the sadd sequence. (Contributed by Mario Carneiro, 9-Sep-2016)

Ref Expression
Hypotheses sadval.a φ A 0
sadval.b φ B 0
sadval.c C = seq 0 c 2 𝑜 , m 0 if cadd m A m B c 1 𝑜 n 0 if n = 0 n 1
sadcp1.n φ N 0
sadcadd.k K = bits 0 -1
Assertion sadadd3 φ K A sadd B 0 ..^ N mod 2 N = K A 0 ..^ N + K B 0 ..^ N mod 2 N

Proof

Step Hyp Ref Expression
1 sadval.a φ A 0
2 sadval.b φ B 0
3 sadval.c C = seq 0 c 2 𝑜 , m 0 if cadd m A m B c 1 𝑜 n 0 if n = 0 n 1
4 sadcp1.n φ N 0
5 sadcadd.k K = bits 0 -1
6 2nn 2
7 6 a1i φ 2
8 7 4 nnexpcld φ 2 N
9 8 nnzd φ 2 N
10 iddvds 2 N 2 N 2 N
11 9 10 syl φ 2 N 2 N
12 dvds0 2 N 2 N 0
13 9 12 syl φ 2 N 0
14 breq2 2 N = if C N 2 N 0 2 N 2 N 2 N if C N 2 N 0
15 breq2 0 = if C N 2 N 0 2 N 0 2 N if C N 2 N 0
16 14 15 ifboth 2 N 2 N 2 N 0 2 N if C N 2 N 0
17 11 13 16 syl2anc φ 2 N if C N 2 N 0
18 inss1 A sadd B 0 ..^ N A sadd B
19 1 2 3 sadfval φ A sadd B = k 0 | hadd k A k B C k
20 ssrab2 k 0 | hadd k A k B C k 0
21 19 20 eqsstrdi φ A sadd B 0
22 18 21 sstrid φ A sadd B 0 ..^ N 0
23 fzofi 0 ..^ N Fin
24 23 a1i φ 0 ..^ N Fin
25 inss2 A sadd B 0 ..^ N 0 ..^ N
26 ssfi 0 ..^ N Fin A sadd B 0 ..^ N 0 ..^ N A sadd B 0 ..^ N Fin
27 24 25 26 sylancl φ A sadd B 0 ..^ N Fin
28 elfpw A sadd B 0 ..^ N 𝒫 0 Fin A sadd B 0 ..^ N 0 A sadd B 0 ..^ N Fin
29 22 27 28 sylanbrc φ A sadd B 0 ..^ N 𝒫 0 Fin
30 bitsf1o bits 0 : 0 1-1 onto 𝒫 0 Fin
31 f1ocnv bits 0 : 0 1-1 onto 𝒫 0 Fin bits 0 -1 : 𝒫 0 Fin 1-1 onto 0
32 f1of bits 0 -1 : 𝒫 0 Fin 1-1 onto 0 bits 0 -1 : 𝒫 0 Fin 0
33 30 31 32 mp2b bits 0 -1 : 𝒫 0 Fin 0
34 5 feq1i K : 𝒫 0 Fin 0 bits 0 -1 : 𝒫 0 Fin 0
35 33 34 mpbir K : 𝒫 0 Fin 0
36 35 ffvelrni A sadd B 0 ..^ N 𝒫 0 Fin K A sadd B 0 ..^ N 0
37 29 36 syl φ K A sadd B 0 ..^ N 0
38 37 nn0cnd φ K A sadd B 0 ..^ N
39 8 nncnd φ 2 N
40 0cn 0
41 ifcl 2 N 0 if C N 2 N 0
42 39 40 41 sylancl φ if C N 2 N 0
43 38 42 pncan2d φ K A sadd B 0 ..^ N + if C N 2 N 0 - K A sadd B 0 ..^ N = if C N 2 N 0
44 17 43 breqtrrd φ 2 N K A sadd B 0 ..^ N + if C N 2 N 0 - K A sadd B 0 ..^ N
45 37 nn0zd φ K A sadd B 0 ..^ N
46 9 adantr φ C N 2 N
47 0zd φ ¬ C N 0
48 46 47 ifclda φ if C N 2 N 0
49 45 48 zaddcld φ K A sadd B 0 ..^ N + if C N 2 N 0
50 moddvds 2 N K A sadd B 0 ..^ N + if C N 2 N 0 K A sadd B 0 ..^ N K A sadd B 0 ..^ N + if C N 2 N 0 mod 2 N = K A sadd B 0 ..^ N mod 2 N 2 N K A sadd B 0 ..^ N + if C N 2 N 0 - K A sadd B 0 ..^ N
51 8 49 45 50 syl3anc φ K A sadd B 0 ..^ N + if C N 2 N 0 mod 2 N = K A sadd B 0 ..^ N mod 2 N 2 N K A sadd B 0 ..^ N + if C N 2 N 0 - K A sadd B 0 ..^ N
52 44 51 mpbird φ K A sadd B 0 ..^ N + if C N 2 N 0 mod 2 N = K A sadd B 0 ..^ N mod 2 N
53 1 2 3 4 5 sadadd2 φ K A sadd B 0 ..^ N + if C N 2 N 0 = K A 0 ..^ N + K B 0 ..^ N
54 53 oveq1d φ K A sadd B 0 ..^ N + if C N 2 N 0 mod 2 N = K A 0 ..^ N + K B 0 ..^ N mod 2 N
55 52 54 eqtr3d φ K A sadd B 0 ..^ N mod 2 N = K A 0 ..^ N + K B 0 ..^ N mod 2 N