MPE Home Metamath Proof Explorer < Previous   Next >
Nearby theorems
Mirrors  >  Home  >  MPE Home  >  Th. List  >  eucalgval Unicode version

Theorem eucalgval 12700
Description: Euclid's Algorithm eucalg 12705 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.)

Hypothesis
Ref Expression
eucalgval.1  |-  E  =  ( x  e.  NN0 ,  y  e.  NN0  |->  if ( y  =  0 , 
<. x ,  y >. ,  <. y ,  ( x  mod  y )
>. ) )
Assertion
Ref Expression
eucalgval  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( E `
 X )  =  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. ) )
Distinct variable group:    x, y, X
Allowed substitution hints:    E( x, y)

Proof of Theorem eucalgval
StepHypRef Expression
1 df-ov 5781 . . 3  |-  ( ( 1st `  X ) E ( 2nd `  X
) )  =  ( E `  <. ( 1st `  X ) ,  ( 2nd `  X
) >. )
2 xp1st 6069 . . . 4  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( 1st `  X )  e.  NN0 )
3 xp2nd 6070 . . . 4  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( 2nd `  X )  e.  NN0 )
4 eucalgval.1 . . . . 5  |-  E  =  ( x  e.  NN0 ,  y  e.  NN0  |->  if ( y  =  0 , 
<. x ,  y >. ,  <. y ,  ( x  mod  y )
>. ) )
54eucalgval2 12699 . . . 4  |-  ( ( ( 1st `  X
)  e.  NN0  /\  ( 2nd `  X )  e.  NN0 )  -> 
( ( 1st `  X
) E ( 2nd `  X ) )  =  if ( ( 2nd `  X )  =  0 ,  <. ( 1st `  X
) ,  ( 2nd `  X ) >. ,  <. ( 2nd `  X ) ,  ( ( 1st `  X )  mod  ( 2nd `  X ) )
>. ) )
62, 3, 5syl2anc 645 . . 3  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( ( 1st `  X ) E ( 2nd `  X
) )  =  if ( ( 2nd `  X
)  =  0 , 
<. ( 1st `  X
) ,  ( 2nd `  X ) >. ,  <. ( 2nd `  X ) ,  ( ( 1st `  X )  mod  ( 2nd `  X ) )
>. ) )
71, 6syl5eqr 2302 . 2  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( E `
 <. ( 1st `  X
) ,  ( 2nd `  X ) >. )  =  if ( ( 2nd `  X )  =  0 ,  <. ( 1st `  X
) ,  ( 2nd `  X ) >. ,  <. ( 2nd `  X ) ,  ( ( 1st `  X )  mod  ( 2nd `  X ) )
>. ) )
8 1st2nd2 6079 . . 3  |-  ( X  e.  ( NN0  X.  NN0 )  ->  X  = 
<. ( 1st `  X
) ,  ( 2nd `  X ) >. )
98fveq2d 5448 . 2  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( E `
 X )  =  ( E `  <. ( 1st `  X ) ,  ( 2nd `  X
) >. ) )
108fveq2d 5448 . . . . 5  |-  ( X  e.  ( NN0  X.  NN0 )  ->  (  mod  `  X )  =  (  mod  `  <. ( 1st `  X ) ,  ( 2nd `  X )
>. ) )
11 df-ov 5781 . . . . 5  |-  ( ( 1st `  X )  mod  ( 2nd `  X
) )  =  (  mod  `  <. ( 1st `  X ) ,  ( 2nd `  X )
>. )
1210, 11syl6eqr 2306 . . . 4  |-  ( X  e.  ( NN0  X.  NN0 )  ->  (  mod  `  X )  =  ( ( 1st `  X
)  mod  ( 2nd `  X ) ) )
1312opeq2d 3763 . . 3  |-  ( X  e.  ( NN0  X.  NN0 )  ->  <. ( 2nd `  X ) ,  (  mod  `  X
) >.  =  <. ( 2nd `  X ) ,  ( ( 1st `  X
)  mod  ( 2nd `  X ) ) >.
)
148, 13ifeq12d 3541 . 2  |-  ( X  e.  ( NN0  X.  NN0 )  ->  if ( ( 2nd `  X
)  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. )  =  if ( ( 2nd `  X
)  =  0 , 
<. ( 1st `  X
) ,  ( 2nd `  X ) >. ,  <. ( 2nd `  X ) ,  ( ( 1st `  X )  mod  ( 2nd `  X ) )
>. ) )
157, 9, 143eqtr4d 2298 1  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( E `
 X )  =  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. ) )
Colors of variables: wff set class
Syntax hints:    -> wi 6    = wceq 1619    e. wcel 1621   ifcif 3525   <.cop 3603    X. cxp 4645   ` cfv 4659  (class class class)co 5778    e. cmpt2 5780   1stc1st 6040   2ndc2nd 6041   0cc0 8691   NN0cn0 9918    mod cmo 10925
This theorem is referenced by:  eucalginv  12702  eucalglt  12703
This theorem was proved from axioms:  ax-1 7  ax-2 8  ax-3 9  ax-mp 10  ax-5 1533  ax-6 1534  ax-7 1535  ax-gen 1536  ax-8 1623  ax-11 1624  ax-13 1625  ax-14 1626  ax-17 1628  ax-12o 1664  ax-10 1678  ax-9 1684  ax-4 1692  ax-16 1927  ax-ext 2237  ax-sep 4101  ax-nul 4109  ax-pr 4172  ax-un 4470
This theorem depends on definitions:  df-bi 179  df-or 361  df-an 362  df-3an 941  df-tru 1315  df-ex 1538  df-nf 1540  df-sb 1884  df-eu 2121  df-mo 2122  df-clab 2243  df-cleq 2249  df-clel 2252  df-nfc 2381  df-ne 2421  df-ral 2521  df-rex 2522  df-rab 2525  df-v 2759  df-sbc 2953  df-dif 3116  df-un 3118  df-in 3120  df-ss 3127  df-nul 3417  df-if 3526  df-sn 3606  df-pr 3607  df-op 3609  df-uni 3788  df-br 3984  df-opab 4038  df-mpt 4039  df-id 4267  df-xp 4661  df-rel 4662  df-cnv 4663  df-co 4664  df-dm 4665  df-rn 4666  df-res 4667  df-ima 4668  df-fun 4669  df-fv 4675  df-ov 5781  df-oprab 5782  df-mpt2 5783  df-1st 6042  df-2nd 6043
  Copyright terms: Public domain W3C validator