Metamath Proof Explorer < Previous   Next > Nearby theorems Mirrors  >  Home  >  MPE Home  >  Th. List  >  bitsres Structured version   Visualization version   GIF version

Theorem bitsres 15832
 Description: Restrict the bits of a number to an upper integer set. (Contributed by Mario Carneiro, 5-Sep-2016.)
Assertion
Ref Expression
bitsres ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((bits‘𝐴) ∩ (ℤ𝑁)) = (bits‘((⌊‘(𝐴 / (2↑𝑁))) · (2↑𝑁))))

Proof of Theorem bitsres
StepHypRef Expression
1 simpl 486 . . . . . 6 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → 𝐴 ∈ ℤ)
2 2nn 11716 . . . . . . . 8 2 ∈ ℕ
32a1i 11 . . . . . . 7 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → 2 ∈ ℕ)
4 simpr 488 . . . . . . 7 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → 𝑁 ∈ ℕ0)
53, 4nnexpcld 13622 . . . . . 6 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (2↑𝑁) ∈ ℕ)
61, 5zmodcld 13275 . . . . 5 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (𝐴 mod (2↑𝑁)) ∈ ℕ0)
76nn0zd 12093 . . . 4 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (𝐴 mod (2↑𝑁)) ∈ ℤ)
87znegcld 12097 . . 3 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → -(𝐴 mod (2↑𝑁)) ∈ ℤ)
9 sadadd 15826 . . 3 ((-(𝐴 mod (2↑𝑁)) ∈ ℤ ∧ 𝐴 ∈ ℤ) → ((bits‘-(𝐴 mod (2↑𝑁))) sadd (bits‘𝐴)) = (bits‘(-(𝐴 mod (2↑𝑁)) + 𝐴)))
108, 1, 9syl2anc 587 . 2 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((bits‘-(𝐴 mod (2↑𝑁))) sadd (bits‘𝐴)) = (bits‘(-(𝐴 mod (2↑𝑁)) + 𝐴)))
11 sadadd 15826 . . . . . 6 ((-(𝐴 mod (2↑𝑁)) ∈ ℤ ∧ (𝐴 mod (2↑𝑁)) ∈ ℤ) → ((bits‘-(𝐴 mod (2↑𝑁))) sadd (bits‘(𝐴 mod (2↑𝑁)))) = (bits‘(-(𝐴 mod (2↑𝑁)) + (𝐴 mod (2↑𝑁)))))
128, 7, 11syl2anc 587 . . . . 5 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((bits‘-(𝐴 mod (2↑𝑁))) sadd (bits‘(𝐴 mod (2↑𝑁)))) = (bits‘(-(𝐴 mod (2↑𝑁)) + (𝐴 mod (2↑𝑁)))))
138zcnd 12096 . . . . . . . . 9 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → -(𝐴 mod (2↑𝑁)) ∈ ℂ)
147zcnd 12096 . . . . . . . . 9 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (𝐴 mod (2↑𝑁)) ∈ ℂ)
1513, 14addcomd 10849 . . . . . . . 8 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (-(𝐴 mod (2↑𝑁)) + (𝐴 mod (2↑𝑁))) = ((𝐴 mod (2↑𝑁)) + -(𝐴 mod (2↑𝑁))))
1614negidd 10994 . . . . . . . 8 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((𝐴 mod (2↑𝑁)) + -(𝐴 mod (2↑𝑁))) = 0)
1715, 16eqtrd 2833 . . . . . . 7 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (-(𝐴 mod (2↑𝑁)) + (𝐴 mod (2↑𝑁))) = 0)
1817fveq2d 6659 . . . . . 6 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (bits‘(-(𝐴 mod (2↑𝑁)) + (𝐴 mod (2↑𝑁)))) = (bits‘0))
19 0bits 15798 . . . . . 6 (bits‘0) = ∅
2018, 19eqtrdi 2849 . . . . 5 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (bits‘(-(𝐴 mod (2↑𝑁)) + (𝐴 mod (2↑𝑁)))) = ∅)
2112, 20eqtrd 2833 . . . 4 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((bits‘-(𝐴 mod (2↑𝑁))) sadd (bits‘(𝐴 mod (2↑𝑁)))) = ∅)
2221oveq1d 7160 . . 3 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (((bits‘-(𝐴 mod (2↑𝑁))) sadd (bits‘(𝐴 mod (2↑𝑁)))) sadd ((bits‘𝐴) ∩ (ℤ𝑁))) = (∅ sadd ((bits‘𝐴) ∩ (ℤ𝑁))))
23 bitsss 15785 . . . . 5 (bits‘-(𝐴 mod (2↑𝑁))) ⊆ ℕ0
24 bitsss 15785 . . . . 5 (bits‘(𝐴 mod (2↑𝑁))) ⊆ ℕ0
25 inss1 4158 . . . . . 6 ((bits‘𝐴) ∩ (ℤ𝑁)) ⊆ (bits‘𝐴)
26 bitsss 15785 . . . . . . 7 (bits‘𝐴) ⊆ ℕ0
2726a1i 11 . . . . . 6 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (bits‘𝐴) ⊆ ℕ0)
2825, 27sstrid 3928 . . . . 5 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((bits‘𝐴) ∩ (ℤ𝑁)) ⊆ ℕ0)
29 sadass 15830 . . . . 5 (((bits‘-(𝐴 mod (2↑𝑁))) ⊆ ℕ0 ∧ (bits‘(𝐴 mod (2↑𝑁))) ⊆ ℕ0 ∧ ((bits‘𝐴) ∩ (ℤ𝑁)) ⊆ ℕ0) → (((bits‘-(𝐴 mod (2↑𝑁))) sadd (bits‘(𝐴 mod (2↑𝑁)))) sadd ((bits‘𝐴) ∩ (ℤ𝑁))) = ((bits‘-(𝐴 mod (2↑𝑁))) sadd ((bits‘(𝐴 mod (2↑𝑁))) sadd ((bits‘𝐴) ∩ (ℤ𝑁)))))
3023, 24, 28, 29mp3an12i 1462 . . . 4 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (((bits‘-(𝐴 mod (2↑𝑁))) sadd (bits‘(𝐴 mod (2↑𝑁)))) sadd ((bits‘𝐴) ∩ (ℤ𝑁))) = ((bits‘-(𝐴 mod (2↑𝑁))) sadd ((bits‘(𝐴 mod (2↑𝑁))) sadd ((bits‘𝐴) ∩ (ℤ𝑁)))))
31 bitsmod 15795 . . . . . . 7 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (bits‘(𝐴 mod (2↑𝑁))) = ((bits‘𝐴) ∩ (0..^𝑁)))
3231oveq1d 7160 . . . . . 6 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((bits‘(𝐴 mod (2↑𝑁))) sadd ((bits‘𝐴) ∩ (ℤ𝑁))) = (((bits‘𝐴) ∩ (0..^𝑁)) sadd ((bits‘𝐴) ∩ (ℤ𝑁))))
33 inss1 4158 . . . . . . . . . 10 ((bits‘𝐴) ∩ (0..^𝑁)) ⊆ (bits‘𝐴)
3433, 27sstrid 3928 . . . . . . . . 9 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((bits‘𝐴) ∩ (0..^𝑁)) ⊆ ℕ0)
35 fzouzdisj 13088 . . . . . . . . . . . 12 ((0..^𝑁) ∩ (ℤ𝑁)) = ∅
3635ineq2i 4139 . . . . . . . . . . 11 ((bits‘𝐴) ∩ ((0..^𝑁) ∩ (ℤ𝑁))) = ((bits‘𝐴) ∩ ∅)
37 inindi 4156 . . . . . . . . . . 11 ((bits‘𝐴) ∩ ((0..^𝑁) ∩ (ℤ𝑁))) = (((bits‘𝐴) ∩ (0..^𝑁)) ∩ ((bits‘𝐴) ∩ (ℤ𝑁)))
38 in0 4302 . . . . . . . . . . 11 ((bits‘𝐴) ∩ ∅) = ∅
3936, 37, 383eqtr3i 2829 . . . . . . . . . 10 (((bits‘𝐴) ∩ (0..^𝑁)) ∩ ((bits‘𝐴) ∩ (ℤ𝑁))) = ∅
4039a1i 11 . . . . . . . . 9 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (((bits‘𝐴) ∩ (0..^𝑁)) ∩ ((bits‘𝐴) ∩ (ℤ𝑁))) = ∅)
4134, 28, 40saddisj 15824 . . . . . . . 8 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (((bits‘𝐴) ∩ (0..^𝑁)) sadd ((bits‘𝐴) ∩ (ℤ𝑁))) = (((bits‘𝐴) ∩ (0..^𝑁)) ∪ ((bits‘𝐴) ∩ (ℤ𝑁))))
42 indi 4203 . . . . . . . 8 ((bits‘𝐴) ∩ ((0..^𝑁) ∪ (ℤ𝑁))) = (((bits‘𝐴) ∩ (0..^𝑁)) ∪ ((bits‘𝐴) ∩ (ℤ𝑁)))
4341, 42eqtr4di 2851 . . . . . . 7 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (((bits‘𝐴) ∩ (0..^𝑁)) sadd ((bits‘𝐴) ∩ (ℤ𝑁))) = ((bits‘𝐴) ∩ ((0..^𝑁) ∪ (ℤ𝑁))))
44 nn0uz 12288 . . . . . . . . . 10 0 = (ℤ‘0)
454, 44eleqtrdi 2900 . . . . . . . . . . 11 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → 𝑁 ∈ (ℤ‘0))
46 fzouzsplit 13087 . . . . . . . . . . 11 (𝑁 ∈ (ℤ‘0) → (ℤ‘0) = ((0..^𝑁) ∪ (ℤ𝑁)))
4745, 46syl 17 . . . . . . . . . 10 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (ℤ‘0) = ((0..^𝑁) ∪ (ℤ𝑁)))
4844, 47syl5eq 2845 . . . . . . . . 9 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ℕ0 = ((0..^𝑁) ∪ (ℤ𝑁)))
4926, 48sseqtrid 3969 . . . . . . . 8 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (bits‘𝐴) ⊆ ((0..^𝑁) ∪ (ℤ𝑁)))
50 df-ss 3900 . . . . . . . 8 ((bits‘𝐴) ⊆ ((0..^𝑁) ∪ (ℤ𝑁)) ↔ ((bits‘𝐴) ∩ ((0..^𝑁) ∪ (ℤ𝑁))) = (bits‘𝐴))
5149, 50sylib 221 . . . . . . 7 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((bits‘𝐴) ∩ ((0..^𝑁) ∪ (ℤ𝑁))) = (bits‘𝐴))
5243, 51eqtrd 2833 . . . . . 6 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (((bits‘𝐴) ∩ (0..^𝑁)) sadd ((bits‘𝐴) ∩ (ℤ𝑁))) = (bits‘𝐴))
5332, 52eqtrd 2833 . . . . 5 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((bits‘(𝐴 mod (2↑𝑁))) sadd ((bits‘𝐴) ∩ (ℤ𝑁))) = (bits‘𝐴))
5453oveq2d 7161 . . . 4 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((bits‘-(𝐴 mod (2↑𝑁))) sadd ((bits‘(𝐴 mod (2↑𝑁))) sadd ((bits‘𝐴) ∩ (ℤ𝑁)))) = ((bits‘-(𝐴 mod (2↑𝑁))) sadd (bits‘𝐴)))
5530, 54eqtrd 2833 . . 3 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (((bits‘-(𝐴 mod (2↑𝑁))) sadd (bits‘(𝐴 mod (2↑𝑁)))) sadd ((bits‘𝐴) ∩ (ℤ𝑁))) = ((bits‘-(𝐴 mod (2↑𝑁))) sadd (bits‘𝐴)))
56 sadid2 15828 . . . 4 (((bits‘𝐴) ∩ (ℤ𝑁)) ⊆ ℕ0 → (∅ sadd ((bits‘𝐴) ∩ (ℤ𝑁))) = ((bits‘𝐴) ∩ (ℤ𝑁)))
5728, 56syl 17 . . 3 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (∅ sadd ((bits‘𝐴) ∩ (ℤ𝑁))) = ((bits‘𝐴) ∩ (ℤ𝑁)))
5822, 55, 573eqtr3d 2841 . 2 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((bits‘-(𝐴 mod (2↑𝑁))) sadd (bits‘𝐴)) = ((bits‘𝐴) ∩ (ℤ𝑁)))
591zcnd 12096 . . . . 5 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → 𝐴 ∈ ℂ)
6013, 59addcomd 10849 . . . 4 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (-(𝐴 mod (2↑𝑁)) + 𝐴) = (𝐴 + -(𝐴 mod (2↑𝑁))))
6159, 14negsubd 11010 . . . . 5 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (𝐴 + -(𝐴 mod (2↑𝑁))) = (𝐴 − (𝐴 mod (2↑𝑁))))
6259, 14subcld 11004 . . . . . 6 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (𝐴 − (𝐴 mod (2↑𝑁))) ∈ ℂ)
635nncnd 11659 . . . . . 6 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (2↑𝑁) ∈ ℂ)
645nnne0d 11693 . . . . . 6 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (2↑𝑁) ≠ 0)
6562, 63, 64divcan1d 11424 . . . . 5 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (((𝐴 − (𝐴 mod (2↑𝑁))) / (2↑𝑁)) · (2↑𝑁)) = (𝐴 − (𝐴 mod (2↑𝑁))))
661zred 12095 . . . . . . 7 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → 𝐴 ∈ ℝ)
675nnrpd 12437 . . . . . . 7 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (2↑𝑁) ∈ ℝ+)
68 moddiffl 13265 . . . . . . 7 ((𝐴 ∈ ℝ ∧ (2↑𝑁) ∈ ℝ+) → ((𝐴 − (𝐴 mod (2↑𝑁))) / (2↑𝑁)) = (⌊‘(𝐴 / (2↑𝑁))))
6966, 67, 68syl2anc 587 . . . . . 6 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((𝐴 − (𝐴 mod (2↑𝑁))) / (2↑𝑁)) = (⌊‘(𝐴 / (2↑𝑁))))
7069oveq1d 7160 . . . . 5 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (((𝐴 − (𝐴 mod (2↑𝑁))) / (2↑𝑁)) · (2↑𝑁)) = ((⌊‘(𝐴 / (2↑𝑁))) · (2↑𝑁)))
7161, 65, 703eqtr2d 2839 . . . 4 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (𝐴 + -(𝐴 mod (2↑𝑁))) = ((⌊‘(𝐴 / (2↑𝑁))) · (2↑𝑁)))
7260, 71eqtrd 2833 . . 3 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (-(𝐴 mod (2↑𝑁)) + 𝐴) = ((⌊‘(𝐴 / (2↑𝑁))) · (2↑𝑁)))
7372fveq2d 6659 . 2 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → (bits‘(-(𝐴 mod (2↑𝑁)) + 𝐴)) = (bits‘((⌊‘(𝐴 / (2↑𝑁))) · (2↑𝑁))))
7410, 58, 733eqtr3d 2841 1 ((𝐴 ∈ ℤ ∧ 𝑁 ∈ ℕ0) → ((bits‘𝐴) ∩ (ℤ𝑁)) = (bits‘((⌊‘(𝐴 / (2↑𝑁))) · (2↑𝑁))))