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

Theorem eucalginv 14065
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 14063 . . 3  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( E `
 X )  =  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. ) )
32fveq2d 5868 . 2  |-  ( X  e.  ( NN0  X.  NN0 )  ->  (  gcd  `  ( E `  X
) )  =  (  gcd  `  if (
( 2nd `  X
)  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. ) ) )
4 1st2nd2 6818 . . . . . . . . 9  |-  ( X  e.  ( NN0  X.  NN0 )  ->  X  = 
<. ( 1st `  X
) ,  ( 2nd `  X ) >. )
54adantr 465 . . . . . . . 8  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  X  =  <. ( 1st `  X
) ,  ( 2nd `  X ) >. )
65fveq2d 5868 . . . . . . 7  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (  mod  `  X )  =  (  mod  `  <. ( 1st `  X ) ,  ( 2nd `  X
) >. ) )
7 df-ov 6285 . . . . . . 7  |-  ( ( 1st `  X )  mod  ( 2nd `  X
) )  =  (  mod  `  <. ( 1st `  X ) ,  ( 2nd `  X )
>. )
86, 7syl6eqr 2526 . . . . . 6  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (  mod  `  X )  =  ( ( 1st `  X
)  mod  ( 2nd `  X ) ) )
98oveq2d 6298 . . . . 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 10882 . . . . . . 7  |-  ( ( 2nd `  X )  e.  NN  ->  ( 2nd `  X )  e.  ZZ )
1110adantl 466 . . . . . 6  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  ( 2nd `  X )  e.  ZZ )
12 xp1st 6811 . . . . . . . . . 10  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( 1st `  X )  e.  NN0 )
1312adantr 465 . . . . . . . . 9  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  ( 1st `  X )  e. 
NN0 )
1413nn0zd 10960 . . . . . . . 8  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  ( 1st `  X )  e.  ZZ )
15 zmodcl 11978 . . . . . . . 8  |-  ( ( ( 1st `  X
)  e.  ZZ  /\  ( 2nd `  X )  e.  NN )  -> 
( ( 1st `  X
)  mod  ( 2nd `  X ) )  e. 
NN0 )
1614, 15sylancom 667 . . . . . . 7  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (
( 1st `  X
)  mod  ( 2nd `  X ) )  e. 
NN0 )
1716nn0zd 10960 . . . . . 6  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (
( 1st `  X
)  mod  ( 2nd `  X ) )  e.  ZZ )
18 gcdcom 14010 . . . . . 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 661 . . . . 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 14026 . . . . . 6  |-  ( ( ( 1st `  X
)  e.  ZZ  /\  ( 2nd `  X )  e.  NN )  -> 
( ( ( 1st `  X )  mod  ( 2nd `  X ) )  gcd  ( 2nd `  X
) )  =  ( ( 1st `  X
)  gcd  ( 2nd `  X ) ) )
2114, 20sylancom 667 . . . . 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 2512 . . . 4  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (
( 2nd `  X
)  gcd  (  mod  `  X ) )  =  ( ( 1st `  X
)  gcd  ( 2nd `  X ) ) )
23 nnne0 10564 . . . . . . . . 9  |-  ( ( 2nd `  X )  e.  NN  ->  ( 2nd `  X )  =/=  0 )
2423adantl 466 . . . . . . . 8  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  ( 2nd `  X )  =/=  0 )
2524neneqd 2669 . . . . . . 7  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  -.  ( 2nd `  X )  =  0 )
26 iffalse 3948 . . . . . . 7  |-  ( -.  ( 2nd `  X
)  =  0  ->  if ( ( 2nd `  X
)  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. )  =  <. ( 2nd `  X ) ,  (  mod  `  X
) >. )
2725, 26syl 16 . . . . . 6  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  if ( ( 2nd `  X
)  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. )  =  <. ( 2nd `  X ) ,  (  mod  `  X
) >. )
2827fveq2d 5868 . . . . 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 ) >. )
)
29 df-ov 6285 . . . . 5  |-  ( ( 2nd `  X )  gcd  (  mod  `  X
) )  =  (  gcd  `  <. ( 2nd `  X ) ,  (  mod  `  X ) >. )
3028, 29syl6eqr 2526 . . . 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
) ) )
315fveq2d 5868 . . . . 5  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (  gcd  `  X )  =  (  gcd  `  <. ( 1st `  X ) ,  ( 2nd `  X
) >. ) )
32 df-ov 6285 . . . . 5  |-  ( ( 1st `  X )  gcd  ( 2nd `  X
) )  =  (  gcd  `  <. ( 1st `  X ) ,  ( 2nd `  X )
>. )
3331, 32syl6eqr 2526 . . . 4  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (  gcd  `  X )  =  ( ( 1st `  X
)  gcd  ( 2nd `  X ) ) )
3422, 30, 333eqtr4d 2518 . . 3  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  e.  NN )  ->  (  gcd  `  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X
) ,  (  mod  `  X ) >. )
)  =  (  gcd  `  X ) )
35 iftrue 3945 . . . . 5  |-  ( ( 2nd `  X )  =  0  ->  if ( ( 2nd `  X
)  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. )  =  X )
3635fveq2d 5868 . . . 4  |-  ( ( 2nd `  X )  =  0  ->  (  gcd  `  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X
) ,  (  mod  `  X ) >. )
)  =  (  gcd  `  X ) )
3736adantl 466 . . 3  |-  ( ( X  e.  ( NN0 
X.  NN0 )  /\  ( 2nd `  X )  =  0 )  ->  (  gcd  `  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X
) ,  (  mod  `  X ) >. )
)  =  (  gcd  `  X ) )
38 xp2nd 6812 . . . 4  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( 2nd `  X )  e.  NN0 )
39 elnn0 10793 . . . 4  |-  ( ( 2nd `  X )  e.  NN0  <->  ( ( 2nd `  X )  e.  NN  \/  ( 2nd `  X
)  =  0 ) )
4038, 39sylib 196 . . 3  |-  ( X  e.  ( NN0  X.  NN0 )  ->  ( ( 2nd `  X )  e.  NN  \/  ( 2nd `  X )  =  0 ) )
4134, 37, 40mpjaodan 784 . 2  |-  ( X  e.  ( NN0  X.  NN0 )  ->  (  gcd  `  if ( ( 2nd `  X )  =  0 ,  X ,  <. ( 2nd `  X ) ,  (  mod  `  X
) >. ) )  =  (  gcd  `  X
) )
423, 41eqtrd 2508 1  |-  ( X  e.  ( NN0  X.  NN0 )  ->  (  gcd  `  ( E `  X
) )  =  (  gcd  `  X )
)
Colors of variables: wff setvar class
Syntax hints:   -. wn 3    -> wi 4    \/ wo 368    /\ wa 369    = wceq 1379    e. wcel 1767    =/= wne 2662   ifcif 3939   <.cop 4033    X. cxp 4997   ` cfv 5586  (class class class)co 6282    |-> cmpt2 6284   1stc1st 6779   2ndc2nd 6780   0cc0 9488   NNcn 10532   NN0cn0 10791   ZZcz 10860    mod cmo 11959    gcd cgcd 13996
This theorem was proved from axioms:  ax-mp 5  ax-1 6  ax-2 7  ax-3 8  ax-gen 1601  ax-4 1612  ax-5 1680  ax-6 1719  ax-7 1739  ax-8 1769  ax-9 1771  ax-10 1786  ax-11 1791  ax-12 1803  ax-13 1968  ax-ext 2445  ax-sep 4568  ax-nul 4576  ax-pow 4625  ax-pr 4686  ax-un 6574  ax-cnex 9544  ax-resscn 9545  ax-1cn 9546  ax-icn 9547  ax-addcl 9548  ax-addrcl 9549  ax-mulcl 9550  ax-mulrcl 9551  ax-mulcom 9552  ax-addass 9553  ax-mulass 9554  ax-distr 9555  ax-i2m1 9556  ax-1ne0 9557  ax-1rid 9558  ax-rnegex 9559  ax-rrecex 9560  ax-cnre 9561  ax-pre-lttri 9562  ax-pre-lttrn 9563  ax-pre-ltadd 9564  ax-pre-mulgt0 9565  ax-pre-sup 9566
This theorem depends on definitions:  df-bi 185  df-or 370  df-an 371  df-3or 974  df-3an 975  df-tru 1382  df-ex 1597  df-nf 1600  df-sb 1712  df-eu 2279  df-mo 2280  df-clab 2453  df-cleq 2459  df-clel 2462  df-nfc 2617  df-ne 2664  df-nel 2665  df-ral 2819  df-rex 2820  df-reu 2821  df-rmo 2822  df-rab 2823  df-v 3115  df-sbc 3332  df-csb 3436  df-dif 3479  df-un 3481  df-in 3483  df-ss 3490  df-pss 3492  df-nul 3786  df-if 3940  df-pw 4012  df-sn 4028  df-pr 4030  df-tp 4032  df-op 4034  df-uni 4246  df-iun 4327  df-br 4448  df-opab 4506  df-mpt 4507  df-tr 4541  df-eprel 4791  df-id 4795  df-po 4800  df-so 4801  df-fr 4838  df-we 4840  df-ord 4881  df-on 4882  df-lim 4883  df-suc 4884  df-xp 5005  df-rel 5006  df-cnv 5007  df-co 5008  df-dm 5009  df-rn 5010  df-res 5011  df-ima 5012  df-iota 5549  df-fun 5588  df-fn 5589  df-f 5590  df-f1 5591  df-fo 5592  df-f1o 5593  df-fv 5594  df-riota 6243  df-ov 6285  df-oprab 6286  df-mpt2 6287  df-om 6679  df-1st 6781  df-2nd 6782  df-recs 7039  df-rdg 7073  df-er 7308  df-en 7514  df-dom 7515  df-sdom 7516  df-sup 7897  df-pnf 9626  df-mnf 9627  df-xr 9628  df-ltxr 9629  df-le 9630  df-sub 9803  df-neg 9804  df-div 10203  df-nn 10533  df-2 10590  df-3 10591  df-n0 10792  df-z 10861  df-uz 11079  df-rp 11217  df-fl 11893  df-mod 11960  df-seq 12071  df-exp 12130  df-cj 12889  df-re 12890  df-im 12891  df-sqrt 13025  df-abs 13026  df-dvds 13841  df-gcd 13997
This theorem is referenced by:  eucalg  14068
  Copyright terms: Public domain W3C validator