Metamath Proof Explorer


Theorem dvdsmodexp

Description: If a positive integer divides another integer, this other integer is equal to its positive powers modulo the positive integer. (Formerly part of the proof for fermltl ). (Contributed by Mario Carneiro, 28-Feb-2014) (Revised by AV, 19-Mar-2022)

Ref Expression
Assertion dvdsmodexp
|- ( ( N e. NN /\ B e. NN /\ N || A ) -> ( ( A ^ B ) mod N ) = ( A mod N ) )

Proof

Step Hyp Ref Expression
1 dvdszrcl
 |-  ( N || A -> ( N e. ZZ /\ A e. ZZ ) )
2 dvdsmod0
 |-  ( ( N e. NN /\ N || A ) -> ( A mod N ) = 0 )
3 2 3ad2antl2
 |-  ( ( ( A e. ZZ /\ N e. NN /\ B e. NN ) /\ N || A ) -> ( A mod N ) = 0 )
4 3 ex
 |-  ( ( A e. ZZ /\ N e. NN /\ B e. NN ) -> ( N || A -> ( A mod N ) = 0 ) )
5 simpl3
 |-  ( ( ( A e. ZZ /\ N e. NN /\ B e. NN ) /\ ( A mod N ) = 0 ) -> B e. NN )
6 5 0expd
 |-  ( ( ( A e. ZZ /\ N e. NN /\ B e. NN ) /\ ( A mod N ) = 0 ) -> ( 0 ^ B ) = 0 )
7 6 oveq1d
 |-  ( ( ( A e. ZZ /\ N e. NN /\ B e. NN ) /\ ( A mod N ) = 0 ) -> ( ( 0 ^ B ) mod N ) = ( 0 mod N ) )
8 simpl1
 |-  ( ( ( A e. ZZ /\ N e. NN /\ B e. NN ) /\ ( A mod N ) = 0 ) -> A e. ZZ )
9 0zd
 |-  ( ( ( A e. ZZ /\ N e. NN /\ B e. NN ) /\ ( A mod N ) = 0 ) -> 0 e. ZZ )
10 nnnn0
 |-  ( B e. NN -> B e. NN0 )
11 10 3ad2ant3
 |-  ( ( A e. ZZ /\ N e. NN /\ B e. NN ) -> B e. NN0 )
12 11 adantr
 |-  ( ( ( A e. ZZ /\ N e. NN /\ B e. NN ) /\ ( A mod N ) = 0 ) -> B e. NN0 )
13 nnrp
 |-  ( N e. NN -> N e. RR+ )
14 13 3ad2ant2
 |-  ( ( A e. ZZ /\ N e. NN /\ B e. NN ) -> N e. RR+ )
15 14 adantr
 |-  ( ( ( A e. ZZ /\ N e. NN /\ B e. NN ) /\ ( A mod N ) = 0 ) -> N e. RR+ )
16 simpr
 |-  ( ( ( A e. ZZ /\ N e. NN /\ B e. NN ) /\ ( A mod N ) = 0 ) -> ( A mod N ) = 0 )
17 0mod
 |-  ( N e. RR+ -> ( 0 mod N ) = 0 )
18 15 17 syl
 |-  ( ( ( A e. ZZ /\ N e. NN /\ B e. NN ) /\ ( A mod N ) = 0 ) -> ( 0 mod N ) = 0 )
19 16 18 eqtr4d
 |-  ( ( ( A e. ZZ /\ N e. NN /\ B e. NN ) /\ ( A mod N ) = 0 ) -> ( A mod N ) = ( 0 mod N ) )
20 modexp
 |-  ( ( ( A e. ZZ /\ 0 e. ZZ ) /\ ( B e. NN0 /\ N e. RR+ ) /\ ( A mod N ) = ( 0 mod N ) ) -> ( ( A ^ B ) mod N ) = ( ( 0 ^ B ) mod N ) )
21 8 9 12 15 19 20 syl221anc
 |-  ( ( ( A e. ZZ /\ N e. NN /\ B e. NN ) /\ ( A mod N ) = 0 ) -> ( ( A ^ B ) mod N ) = ( ( 0 ^ B ) mod N ) )
22 7 21 19 3eqtr4d
 |-  ( ( ( A e. ZZ /\ N e. NN /\ B e. NN ) /\ ( A mod N ) = 0 ) -> ( ( A ^ B ) mod N ) = ( A mod N ) )
23 22 ex
 |-  ( ( A e. ZZ /\ N e. NN /\ B e. NN ) -> ( ( A mod N ) = 0 -> ( ( A ^ B ) mod N ) = ( A mod N ) ) )
24 4 23 syld
 |-  ( ( A e. ZZ /\ N e. NN /\ B e. NN ) -> ( N || A -> ( ( A ^ B ) mod N ) = ( A mod N ) ) )
25 24 3exp
 |-  ( A e. ZZ -> ( N e. NN -> ( B e. NN -> ( N || A -> ( ( A ^ B ) mod N ) = ( A mod N ) ) ) ) )
26 25 com24
 |-  ( A e. ZZ -> ( N || A -> ( B e. NN -> ( N e. NN -> ( ( A ^ B ) mod N ) = ( A mod N ) ) ) ) )
27 26 adantl
 |-  ( ( N e. ZZ /\ A e. ZZ ) -> ( N || A -> ( B e. NN -> ( N e. NN -> ( ( A ^ B ) mod N ) = ( A mod N ) ) ) ) )
28 1 27 mpcom
 |-  ( N || A -> ( B e. NN -> ( N e. NN -> ( ( A ^ B ) mod N ) = ( A mod N ) ) ) )
29 28 3imp31
 |-  ( ( N e. NN /\ B e. NN /\ N || A ) -> ( ( A ^ B ) mod N ) = ( A mod N ) )