Metamath Proof Explorer


Theorem modifeq2int

Description: If a nonnegative integer is less than twice a positive integer, the nonnegative integer modulo the positive integer equals the nonnegative integer or the nonnegative integer minus the positive integer. (Contributed by Alexander van der Vekens, 21-May-2018)

Ref Expression
Assertion modifeq2int A0BA<2BAmodB=ifA<BAAB

Proof

Step Hyp Ref Expression
1 nn0re A0A
2 nnrp BB+
3 1 2 anim12i A0BAB+
4 3 3adant3 A0BA<2BAB+
5 nn0ge0 A00A
6 5 3ad2ant1 A0BA<2B0A
7 6 anim1i A0BA<2BA<B0AA<B
8 7 ancoms A<BA0BA<2B0AA<B
9 modid AB+0AA<BAmodB=A
10 4 8 9 syl2an2 A<BA0BA<2BAmodB=A
11 iftrue A<BifA<BAAB=A
12 11 eqcomd A<BA=ifA<BAAB
13 12 adantr A<BA0BA<2BA=ifA<BAAB
14 10 13 eqtrd A<BA0BA<2BAmodB=ifA<BAAB
15 14 ex A<BA0BA<2BAmodB=ifA<BAAB
16 4 adantr A0BA<2B¬A<BAB+
17 nnre BB
18 lenlt BABA¬A<B
19 17 1 18 syl2anr A0BBA¬A<B
20 19 3adant3 A0BA<2BBA¬A<B
21 20 biimpar A0BA<2B¬A<BBA
22 simpl3 A0BA<2B¬A<BA<2B
23 2submod AB+BAA<2BAmodB=AB
24 16 21 22 23 syl12anc A0BA<2B¬A<BAmodB=AB
25 iffalse ¬A<BifA<BAAB=AB
26 25 adantl A0BA<2B¬A<BifA<BAAB=AB
27 26 eqcomd A0BA<2B¬A<BAB=ifA<BAAB
28 24 27 eqtrd A0BA<2B¬A<BAmodB=ifA<BAAB
29 28 expcom ¬A<BA0BA<2BAmodB=ifA<BAAB
30 15 29 pm2.61i A0BA<2BAmodB=ifA<BAAB