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

Theorem eucalginv 14422
Description: The invariant of the step function  E for Euclid's Algorithm is the  gcd operator applied to the state. (Contributed by Paul Chapman, 31-Mar-2011.) (Revised by Mario Carneiro, 29-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
eucalginv  |-  ( X  e.  ( NN0  X.  NN0 )  ->  (  gcd  `  ( E `  X
) )  =  (  gcd  `  X )
)
Distinct variable group:    x, y, X
Allowed substitution hints:    E( x, y)

Proof of Theorem eucalginv
StepHypRef Expression
1 eucalgval.1 . . . 4  |-  E  =  ( x  e.  NN0 ,  y  e.  NN0  |->  if ( y  =  0 , 
<. x ,  y >. ,  <. y ,  ( x  mod  y )
>. ) )
21eucalgval 14420 . . 3  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( E `
 X )  =  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. ) )
32fveq2d 5853 . 2  |-  ( X  e.  ( NN0  X.  NN0 )  ->  (  gcd  `  ( E `  X
) )  =  (  gcd  `  if (
( 2nd `  X
)  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. ) ) )
4 1st2nd2 6821 . . . . . . . . 9  |-  ( X  e.  ( NN0  X.  NN0 )  ->  X  = 
<. ( 1st `  X
) ,  ( 2nd `  X ) >. )
54adantr 463 . . . . . . . 8  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  X  =  <. ( 1st `  X
) ,  ( 2nd `  X ) >. )
65fveq2d 5853 . . . . . . 7  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (  mod  `  X )  =  (  mod  `  <. ( 1st `  X ) ,  ( 2nd `  X
) >. ) )
7 df-ov 6281 . . . . . . 7  |-  ( ( 1st `  X )  mod  ( 2nd `  X
) )  =  (  mod  `  <. ( 1st `  X ) ,  ( 2nd `  X )
>. )
86, 7syl6eqr 2461 . . . . . 6  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (  mod  `  X )  =  ( ( 1st `  X
)  mod  ( 2nd `  X ) ) )
98oveq2d 6294 . . . . 5  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (
( 2nd `  X
)  gcd  (  mod  `  X ) )  =  ( ( 2nd `  X
)  gcd  ( ( 1st `  X )  mod  ( 2nd `  X
) ) ) )
10 nnz 10927 . . . . . . 7  |-  ( ( 2nd `  X )  e.  NN  ->  ( 2nd `  X )  e.  ZZ )
1110adantl 464 . . . . . 6  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  ( 2nd `  X )  e.  ZZ )
12 xp1st 6814 . . . . . . . . . 10  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( 1st `  X )  e.  NN0 )
1312adantr 463 . . . . . . . . 9  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  ( 1st `  X )  e. 
NN0 )
1413nn0zd 11006 . . . . . . . 8  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  ( 1st `  X )  e.  ZZ )
15 zmodcl 12054 . . . . . . . 8  |-  ( ( ( 1st `  X
)  e.  ZZ  /\  ( 2nd `  X )  e.  NN )  -> 
( ( 1st `  X
)  mod  ( 2nd `  X ) )  e. 
NN0 )
1614, 15sylancom 665 . . . . . . 7  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (
( 1st `  X
)  mod  ( 2nd `  X ) )  e. 
NN0 )
1716nn0zd 11006 . . . . . 6  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (
( 1st `  X
)  mod  ( 2nd `  X ) )  e.  ZZ )
18 gcdcom 14367 . . . . . 6  |-  ( ( ( 2nd `  X
)  e.  ZZ  /\  ( ( 1st `  X
)  mod  ( 2nd `  X ) )  e.  ZZ )  ->  (
( 2nd `  X
)  gcd  ( ( 1st `  X )  mod  ( 2nd `  X
) ) )  =  ( ( ( 1st `  X )  mod  ( 2nd `  X ) )  gcd  ( 2nd `  X
) ) )
1911, 17, 18syl2anc 659 . . . . 5  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (
( 2nd `  X
)  gcd  ( ( 1st `  X )  mod  ( 2nd `  X
) ) )  =  ( ( ( 1st `  X )  mod  ( 2nd `  X ) )  gcd  ( 2nd `  X
) ) )
20 modgcd 14383 . . . . . 6  |-  ( ( ( 1st `  X
)  e.  ZZ  /\  ( 2nd `  X )  e.  NN )  -> 
( ( ( 1st `  X )  mod  ( 2nd `  X ) )  gcd  ( 2nd `  X
) )  =  ( ( 1st `  X
)  gcd  ( 2nd `  X ) ) )
2114, 20sylancom 665 . . . . 5  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (
( ( 1st `  X
)  mod  ( 2nd `  X ) )  gcd  ( 2nd `  X
) )  =  ( ( 1st `  X
)  gcd  ( 2nd `  X ) ) )
229, 19, 213eqtrd 2447 . . . 4  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (
( 2nd `  X
)  gcd  (  mod  `  X ) )  =  ( ( 1st `  X
)  gcd  ( 2nd `  X ) ) )
23 nnne0 10609 . . . . . . . . 9  |-  ( ( 2nd `  X )  e.  NN  ->  ( 2nd `  X )  =/=  0 )
2423adantl 464 . . . . . . . 8  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  ( 2nd `  X )  =/=  0 )
2524neneqd 2605 . . . . . . 7  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  -.  ( 2nd `  X )  =  0 )
2625iffalsed 3896 . . . . . 6  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  if ( ( 2nd `  X
)  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. )  =  <. ( 2nd `  X ) ,  (  mod  `  X
) >. )
2726fveq2d 5853 . . . . 5  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (  gcd  `  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X
) ,  (  mod  `  X ) >. )
)  =  (  gcd  `  <. ( 2nd `  X
) ,  (  mod  `  X ) >. )
)
28 df-ov 6281 . . . . 5  |-  ( ( 2nd `  X )  gcd  (  mod  `  X
) )  =  (  gcd  `  <. ( 2nd `  X ) ,  (  mod  `  X ) >. )
2927, 28syl6eqr 2461 . . . 4  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (  gcd  `  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X
) ,  (  mod  `  X ) >. )
)  =  ( ( 2nd `  X )  gcd  (  mod  `  X
) ) )
305fveq2d 5853 . . . . 5  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (  gcd  `  X )  =  (  gcd  `  <. ( 1st `  X ) ,  ( 2nd `  X
) >. ) )
31 df-ov 6281 . . . . 5  |-  ( ( 1st `  X )  gcd  ( 2nd `  X
) )  =  (  gcd  `  <. ( 1st `  X ) ,  ( 2nd `  X )
>. )
3230, 31syl6eqr 2461 . . . 4  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (  gcd  `  X )  =  ( ( 1st `  X
)  gcd  ( 2nd `  X ) ) )
3322, 29, 323eqtr4d 2453 . . 3  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (  gcd  `  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X
) ,  (  mod  `  X ) >. )
)  =  (  gcd  `  X ) )
34 iftrue 3891 . . . . 5  |-  ( ( 2nd `  X )  =  0  ->  if ( ( 2nd `  X
)  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. )  =  X )
3534fveq2d 5853 . . . 4  |-  ( ( 2nd `  X )  =  0  ->  (  gcd  `  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X
) ,  (  mod  `  X ) >. )
)  =  (  gcd  `  X ) )
3635adantl 464 . . 3  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  =  0 )  ->  (  gcd  `  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X
) ,  (  mod  `  X ) >. )
)  =  (  gcd  `  X ) )
37 xp2nd 6815 . . . 4  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( 2nd `  X )  e.  NN0 )
38 elnn0 10838 . . . 4  |-  ( ( 2nd `  X )  e.  NN0  <->  ( ( 2nd `  X )  e.  NN  \/  ( 2nd `  X
)  =  0 ) )
3937, 38sylib 196 . . 3  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( ( 2nd `  X )  e.  NN  \/  ( 2nd `  X )  =  0 ) )
4033, 36, 39mpjaodan 787 . 2  |-  ( X  e.  ( NN0  X.  NN0 )  ->  (  gcd  `  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. ) )  =  (  gcd  `  X
) )
413, 40eqtrd 2443 1  |-  ( X  e.  ( NN0  X.  NN0 )  ->  (  gcd  `  ( E `  X
) )  =  (  gcd  `  X )
)
Colors of variables: wff setvar class
Syntax hints:    -> wi 4    \/ wo 366    /\ wa 367    = wceq 1405    e. wcel 1842    =/= wne 2598   ifcif 3885   <.cop 3978    X. cxp 4821   ` cfv 5569  (class class class)co 6278    |-> cmpt2 6280   1stc1st 6782   2ndc2nd 6783   0cc0 9522   NNcn 10576   NN0cn0 10836   ZZcz 10905    mod cmo 12034    gcd cgcd 14353
This theorem was proved from axioms:  ax-mp 5  ax-1 6  ax-2 7  ax-3 8  ax-gen 1639  ax-4 1652  ax-5 1725  ax-6 1771  ax-7 1814  ax-8 1844  ax-9 1846  ax-10 1861  ax-11 1866  ax-12 1878  ax-13 2026  ax-ext 2380  ax-sep 4517  ax-nul 4525  ax-pow 4572  ax-pr 4630  ax-un 6574  ax-cnex 9578  ax-resscn 9579  ax-1cn 9580  ax-icn 9581  ax-addcl 9582  ax-addrcl 9583  ax-mulcl 9584  ax-mulrcl 9585  ax-mulcom 9586  ax-addass 9587  ax-mulass 9588  ax-distr 9589  ax-i2m1 9590  ax-1ne0 9591  ax-1rid 9592  ax-rnegex 9593  ax-rrecex 9594  ax-cnre 9595  ax-pre-lttri 9596  ax-pre-lttrn 9597  ax-pre-ltadd 9598  ax-pre-mulgt0 9599  ax-pre-sup 9600
This theorem depends on definitions:  df-bi 185  df-or 368  df-an 369  df-3or 975  df-3an 976  df-tru 1408  df-ex 1634  df-nf 1638  df-sb 1764  df-eu 2242  df-mo 2243  df-clab 2388  df-cleq 2394  df-clel 2397  df-nfc 2552  df-ne 2600  df-nel 2601  df-ral 2759  df-rex 2760  df-reu 2761  df-rmo 2762  df-rab 2763  df-v 3061  df-sbc 3278  df-csb 3374  df-dif 3417  df-un 3419  df-in 3421  df-ss 3428  df-pss 3430  df-nul 3739  df-if 3886  df-pw 3957  df-sn 3973  df-pr 3975  df-tp 3977  df-op 3979  df-uni 4192  df-iun 4273  df-br 4396  df-opab 4454  df-mpt 4455  df-tr 4490  df-eprel 4734  df-id 4738  df-po 4744  df-so 4745  df-fr 4782  df-we 4784  df-xp 4829  df-rel 4830  df-cnv 4831  df-co 4832  df-dm 4833  df-rn 4834  df-res 4835  df-ima 4836  df-pred 5367  df-ord 5413  df-on 5414  df-lim 5415  df-suc 5416  df-iota 5533  df-fun 5571  df-fn 5572  df-f 5573  df-f1 5574  df-fo 5575  df-f1o 5576  df-fv 5577  df-riota 6240  df-ov 6281  df-oprab 6282  df-mpt2 6283  df-om 6684  df-1st 6784  df-2nd 6785  df-wrecs 7013  df-recs 7075  df-rdg 7113  df-er 7348  df-en 7555  df-dom 7556  df-sdom 7557  df-sup 7935  df-pnf 9660  df-mnf 9661  df-xr 9662  df-ltxr 9663  df-le 9664  df-sub 9843  df-neg 9844  df-div 10248  df-nn 10577  df-2 10635  df-3 10636  df-n0 10837  df-z 10906  df-uz 11128  df-rp 11266  df-fl 11966  df-mod 12035  df-seq 12152  df-exp 12211  df-cj 13081  df-re 13082  df-im 13083  df-sqrt 13217  df-abs 13218  df-dvds 14196  df-gcd 14354
This theorem is referenced by:  eucalg  14425
  Copyright terms: Public domain W3C validator