Metamath Proof Explorer


Theorem divalgmod

Description: The result of the mod operator satisfies the requirements for the remainder R in the division algorithm for a positive divisor (compare divalg2 and divalgb ). This demonstration theorem justifies the use of mod to yield an explicit remainder from this point forward. (Contributed by Paul Chapman, 31-Mar-2011) (Revised by AV, 21-Aug-2021)

Ref Expression
Assertion divalgmod N D R = N mod D R 0 R < D D N R

Proof

Step Hyp Ref Expression
1 ovex N mod D V
2 1 snid N mod D N mod D
3 eleq1 R = N mod D R N mod D N mod D N mod D
4 2 3 mpbiri R = N mod D R N mod D
5 elsni R N mod D R = N mod D
6 4 5 impbii R = N mod D R N mod D
7 zre N N
8 nnrp D D +
9 modlt N D + N mod D < D
10 7 8 9 syl2an N D N mod D < D
11 nnre D D
12 nnne0 D D 0
13 redivcl N D D 0 N D
14 7 11 12 13 syl3an N D D N D
15 14 3anidm23 N D N D
16 15 flcld N D N D
17 nnz D D
18 17 adantl N D D
19 zmodcl N D N mod D 0
20 19 nn0zd N D N mod D
21 zsubcl N N mod D N N mod D
22 20 21 syldan N D N N mod D
23 nncn D D
24 23 adantl N D D
25 16 zcnd N D N D
26 24 25 mulcomd N D D N D = N D D
27 modval N D + N mod D = N D N D
28 7 8 27 syl2an N D N mod D = N D N D
29 19 nn0cnd N D N mod D
30 zmulcl D N D D N D
31 17 16 30 syl2an2 N D D N D
32 31 zcnd N D D N D
33 zcn N N
34 33 adantr N D N
35 29 32 34 subexsub N D N mod D = N D N D D N D = N N mod D
36 28 35 mpbid N D D N D = N N mod D
37 26 36 eqtr3d N D N D D = N N mod D
38 dvds0lem N D D N N mod D N D D = N N mod D D N N mod D
39 16 18 22 37 38 syl31anc N D D N N mod D
40 divalg2 N D ∃! z 0 z < D D N z
41 breq1 z = N mod D z < D N mod D < D
42 oveq2 z = N mod D N z = N N mod D
43 42 breq2d z = N mod D D N z D N N mod D
44 41 43 anbi12d z = N mod D z < D D N z N mod D < D D N N mod D
45 44 riota2 N mod D 0 ∃! z 0 z < D D N z N mod D < D D N N mod D ι z 0 | z < D D N z = N mod D
46 19 40 45 syl2anc N D N mod D < D D N N mod D ι z 0 | z < D D N z = N mod D
47 10 39 46 mpbi2and N D ι z 0 | z < D D N z = N mod D
48 47 eqcomd N D N mod D = ι z 0 | z < D D N z
49 48 sneqd N D N mod D = ι z 0 | z < D D N z
50 snriota ∃! z 0 z < D D N z z 0 | z < D D N z = ι z 0 | z < D D N z
51 40 50 syl N D z 0 | z < D D N z = ι z 0 | z < D D N z
52 49 51 eqtr4d N D N mod D = z 0 | z < D D N z
53 52 eleq2d N D R N mod D R z 0 | z < D D N z
54 6 53 syl5bb N D R = N mod D R z 0 | z < D D N z
55 breq1 z = R z < D R < D
56 oveq2 z = R N z = N R
57 56 breq2d z = R D N z D N R
58 55 57 anbi12d z = R z < D D N z R < D D N R
59 58 elrab R z 0 | z < D D N z R 0 R < D D N R
60 54 59 bitrdi N D R = N mod D R 0 R < D D N R