Metamath Proof Explorer


Theorem modaddmodup

Description: The sum of an integer modulo a positive integer and another integer minus the positive integer equals the sum of the two integers modulo the positive integer if the other integer is in the upper part of the range between 0 and the positive integer. (Contributed by AV, 30-Oct-2018)

Ref Expression
Assertion modaddmodup A M B M A mod M ..^ M B + A mod M - M = B + A mod M

Proof

Step Hyp Ref Expression
1 elfzoelz B M A mod M ..^ M B
2 1 zred B M A mod M ..^ M B
3 2 adantr B M A mod M ..^ M A M B
4 zmodcl A M A mod M 0
5 4 nn0red A M A mod M
6 5 adantl B M A mod M ..^ M A M A mod M
7 3 6 readdcld B M A mod M ..^ M A M B + A mod M
8 7 ancoms A M B M A mod M ..^ M B + A mod M
9 nnrp M M +
10 9 ad2antlr A M B M A mod M ..^ M M +
11 elfzo2 B M A mod M ..^ M B M A mod M M B < M
12 eluz2 B M A mod M M A mod M B M A mod M B
13 nnre M M
14 13 adantl A M M
15 14 adantl B A M M
16 5 adantl B A M A mod M
17 zre B B
18 17 adantr B A M B
19 15 16 18 lesubaddd B A M M A mod M B M B + A mod M
20 19 biimpd B A M M A mod M B M B + A mod M
21 20 impancom B M A mod M B A M M B + A mod M
22 21 3adant1 M A mod M B M A mod M B A M M B + A mod M
23 12 22 sylbi B M A mod M A M M B + A mod M
24 23 3ad2ant1 B M A mod M M B < M A M M B + A mod M
25 11 24 sylbi B M A mod M ..^ M A M M B + A mod M
26 25 impcom A M B M A mod M ..^ M M B + A mod M
27 eluzelz B M A mod M B
28 17 5 anim12i B A M B A mod M
29 13 13 jca M M M
30 29 adantl A M M M
31 30 adantl B A M M M
32 28 31 jca B A M B A mod M M M
33 32 adantr B A M B < M B A mod M M M
34 simpr B A M B < M B < M
35 zre A A
36 modlt A M + A mod M < M
37 35 9 36 syl2an A M A mod M < M
38 5 14 37 ltled A M A mod M M
39 38 ad2antlr B A M B < M A mod M M
40 34 39 jca B A M B < M B < M A mod M M
41 ltleadd B A mod M M M B < M A mod M M B + A mod M < M + M
42 33 40 41 sylc B A M B < M B + A mod M < M + M
43 nncn M M
44 43 2timesd M 2 M = M + M
45 44 adantl A M 2 M = M + M
46 45 ad2antlr B A M B < M 2 M = M + M
47 42 46 breqtrrd B A M B < M B + A mod M < 2 M
48 47 exp31 B A M B < M B + A mod M < 2 M
49 48 com23 B B < M A M B + A mod M < 2 M
50 27 49 syl B M A mod M B < M A M B + A mod M < 2 M
51 50 imp B M A mod M B < M A M B + A mod M < 2 M
52 51 3adant2 B M A mod M M B < M A M B + A mod M < 2 M
53 11 52 sylbi B M A mod M ..^ M A M B + A mod M < 2 M
54 53 impcom A M B M A mod M ..^ M B + A mod M < 2 M
55 2submod B + A mod M M + M B + A mod M B + A mod M < 2 M B + A mod M mod M = B + A mod M - M
56 55 eqcomd B + A mod M M + M B + A mod M B + A mod M < 2 M B + A mod M - M = B + A mod M mod M
57 8 10 26 54 56 syl22anc A M B M A mod M ..^ M B + A mod M - M = B + A mod M mod M
58 35 adantr A M A
59 58 adantr A M B M A mod M ..^ M A
60 2 adantl A M B M A mod M ..^ M B
61 modadd2mod A B M + B + A mod M mod M = B + A mod M
62 59 60 10 61 syl3anc A M B M A mod M ..^ M B + A mod M mod M = B + A mod M
63 57 62 eqtrd A M B M A mod M ..^ M B + A mod M - M = B + A mod M
64 63 ex A M B M A mod M ..^ M B + A mod M - M = B + A mod M