Metamath Proof Explorer


Theorem modsubi

Description: Subtract from within a mod calculation. (Contributed by Mario Carneiro, 18-Feb-2014)

Ref Expression
Hypotheses modsubi.1 N
modsubi.2 A
modsubi.3 B 0
modsubi.4 M 0
modsubi.6 A mod N = K mod N
modsubi.5 M + B = K
Assertion modsubi A B mod N = M mod N

Proof

Step Hyp Ref Expression
1 modsubi.1 N
2 modsubi.2 A
3 modsubi.3 B 0
4 modsubi.4 M 0
5 modsubi.6 A mod N = K mod N
6 modsubi.5 M + B = K
7 2 nnrei A
8 4 3 nn0addcli M + B 0
9 8 nn0rei M + B
10 6 9 eqeltrri K
11 7 10 pm3.2i A K
12 3 nn0rei B
13 12 renegcli B
14 nnrp N N +
15 1 14 ax-mp N +
16 13 15 pm3.2i B N +
17 modadd1 A K B N + A mod N = K mod N A + B mod N = K + B mod N
18 11 16 5 17 mp3an A + B mod N = K + B mod N
19 2 nncni A
20 3 nn0cni B
21 19 20 negsubi A + B = A B
22 21 oveq1i A + B mod N = A B mod N
23 10 recni K
24 23 20 negsubi K + B = K B
25 4 nn0cni M
26 23 20 25 subadd2i K B = M M + B = K
27 6 26 mpbir K B = M
28 24 27 eqtri K + B = M
29 28 oveq1i K + B mod N = M mod N
30 18 22 29 3eqtr3i A B mod N = M mod N