Metamath Proof Explorer


Theorem gcdi

Description: Calculate a GCD via Euclid's algorithm. (Contributed by Mario Carneiro, 19-Feb-2014)

Ref Expression
Hypotheses gcdi.1 K0
gcdi.2 R0
gcdi.3 N0
gcdi.5 NgcdR=G
gcdi.4 K N+R=M
Assertion gcdi MgcdN=G

Proof

Step Hyp Ref Expression
1 gcdi.1 K0
2 gcdi.2 R0
3 gcdi.3 N0
4 gcdi.5 NgcdR=G
5 gcdi.4 K N+R=M
6 1 3 nn0mulcli K N0
7 6 nn0cni K N
8 2 nn0cni R
9 7 8 5 addcomli R+K N=M
10 9 oveq2i NgcdR+K N=NgcdM
11 1 nn0zi K
12 3 nn0zi N
13 2 nn0zi R
14 gcdaddm KNRNgcdR=NgcdR+K N
15 11 12 13 14 mp3an NgcdR=NgcdR+K N
16 1 3 2 numcl K N+R0
17 5 16 eqeltrri M0
18 17 nn0zi M
19 gcdcom MNMgcdN=NgcdM
20 18 12 19 mp2an MgcdN=NgcdM
21 10 15 20 3eqtr4i NgcdR=MgcdN
22 21 4 eqtr3i MgcdN=G