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

Theorem eucalgval 12752
Description: Euclid's Algorithm eucalg 12757 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 5861 . . 3  |-  ( ( 1st `  X ) E ( 2nd `  X
) )  =  ( E `  <. ( 1st `  X ) ,  ( 2nd `  X
) >. )
2 xp1st 6149 . . . 4  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( 1st `  X )  e.  NN0 )
3 xp2nd 6150 . . . 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 12751 . . . 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 642 . . 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 2329 . 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 6159 . . 3  |-  ( X  e.  ( NN0  X.  NN0 )  ->  X  = 
<. ( 1st `  X
) ,  ( 2nd `  X ) >. )
98fveq2d 5529 . 2  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( E `
 X )  =  ( E `  <. ( 1st `  X ) ,  ( 2nd `  X
) >. ) )
108fveq2d 5529 . . . . 5  |-  ( X  e.  ( NN0  X.  NN0 )  ->  (  mod  `  X )  =  (  mod  `  <. ( 1st `  X ) ,  ( 2nd `  X )
>. ) )
11 df-ov 5861 . . . . 5  |-  ( ( 1st `  X )  mod  ( 2nd `  X
) )  =  (  mod  `  <. ( 1st `  X ) ,  ( 2nd `  X )
>. )
1210, 11syl6eqr 2333 . . . 4  |-  ( X  e.  ( NN0  X.  NN0 )  ->  (  mod  `  X )  =  ( ( 1st `  X
)  mod  ( 2nd `  X ) ) )
1312opeq2d 3803 . . 3  |-  ( X  e.  ( NN0  X.  NN0 )  ->  <. ( 2nd `  X ) ,  (  mod  `  X
) >.  =  <. ( 2nd `  X ) ,  ( ( 1st `  X
)  mod  ( 2nd `  X ) ) >.
)
148, 13ifeq12d 3581 . 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 2325 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 4    = wceq 1623    e. wcel 1684   ifcif 3565   <.cop 3643    X. cxp 4687   ` cfv 5255  (class class class)co 5858    e. cmpt2 5860   1stc1st 6120   2ndc2nd 6121   0cc0 8737   NN0cn0 9965    mod cmo 10973
This theorem is referenced by:  eucalginv  12754  eucalglt  12755
This theorem was proved from axioms:  ax-1 5  ax-2 6  ax-3 7  ax-mp 8  ax-gen 1533  ax-5 1544  ax-17 1603  ax-9 1635  ax-8 1643  ax-13 1686  ax-14 1688  ax-6 1703  ax-7 1708  ax-11 1715  ax-12 1866  ax-ext 2264  ax-sep 4141  ax-nul 4149  ax-pow 4188  ax-pr 4214  ax-un 4512
This theorem depends on definitions:  df-bi 177  df-or 359  df-an 360  df-3an 936  df-tru 1310  df-ex 1529  df-nf 1532  df-sb 1630  df-eu 2147  df-mo 2148  df-clab 2270  df-cleq 2276  df-clel 2279  df-nfc 2408  df-ne 2448  df-ral 2548  df-rex 2549  df-rab 2552  df-v 2790  df-sbc 2992  df-dif 3155  df-un 3157  df-in 3159  df-ss 3166  df-nul 3456  df-if 3566  df-sn 3646  df-pr 3647  df-op 3649  df-uni 3828  df-br 4024  df-opab 4078  df-mpt 4079  df-id 4309  df-xp 4695  df-rel 4696  df-cnv 4697  df-co 4698  df-dm 4699  df-rn 4700  df-iota 5219  df-fun 5257  df-fv 5263  df-ov 5861  df-oprab 5862  df-mpt2 5863  df-1st 6122  df-2nd 6123
  Copyright terms: Public domain W3C validator