Metamath Proof Explorer


Theorem eucalgval

Description: Euclid's Algorithm eucalg computes the greatest common divisor of two nonnegative integers by repeatedly replacing the larger of them with its remainder modulo the smaller until the remainder is 0.

The value of the step function E for Euclid's Algorithm. (Contributed by Paul Chapman, 31-Mar-2011) (Revised by Mario Carneiro, 28-May-2014)

Ref Expression
Hypothesis eucalgval.1 E=x0,y0ify=0xyyxmody
Assertion eucalgval X0×0EX=if2ndX=0X2ndXmodX

Proof

Step Hyp Ref Expression
1 eucalgval.1 E=x0,y0ify=0xyyxmody
2 df-ov 1stXE2ndX=E1stX2ndX
3 xp1st X0×01stX0
4 xp2nd X0×02ndX0
5 1 eucalgval2 1stX02ndX01stXE2ndX=if2ndX=01stX2ndX2ndX1stXmod2ndX
6 3 4 5 syl2anc X0×01stXE2ndX=if2ndX=01stX2ndX2ndX1stXmod2ndX
7 2 6 eqtr3id X0×0E1stX2ndX=if2ndX=01stX2ndX2ndX1stXmod2ndX
8 1st2nd2 X0×0X=1stX2ndX
9 8 fveq2d X0×0EX=E1stX2ndX
10 8 fveq2d X0×0modX=mod1stX2ndX
11 df-ov 1stXmod2ndX=mod1stX2ndX
12 10 11 eqtr4di X0×0modX=1stXmod2ndX
13 12 opeq2d X0×02ndXmodX=2ndX1stXmod2ndX
14 8 13 ifeq12d X0×0if2ndX=0X2ndXmodX=if2ndX=01stX2ndX2ndX1stXmod2ndX
15 7 9 14 3eqtr4d X0×0EX=if2ndX=0X2ndXmodX