Metamath Proof Explorer < Previous   Next > Nearby theorems Mirrors  >  Home  >  MPE Home  >  Th. List  >  eucalg Structured version   Visualization version   GIF version

Theorem eucalg 15523
 Description: Euclid's Algorithm 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. Theorem 1.15 in [ApostolNT] p. 20. Upon halting, the 1st member of the final state (𝑅‘𝑁) is equal to the gcd of the values comprising the input state ⟨𝑀, 𝑁⟩. This is Metamath 100 proof #69 (greatest common divisor algorithm). (Contributed by Paul Chapman, 31-Mar-2011.) (Proof shortened by Mario Carneiro, 29-May-2014.)
Hypotheses
Ref Expression
eucalgval.1 𝐸 = (𝑥 ∈ ℕ0, 𝑦 ∈ ℕ0 ↦ if(𝑦 = 0, ⟨𝑥, 𝑦⟩, ⟨𝑦, (𝑥 mod 𝑦)⟩))
eucalg.2 𝑅 = seq0((𝐸 ∘ 1st ), (ℕ0 × {𝐴}))
eucalg.3 𝐴 = ⟨𝑀, 𝑁
Assertion
Ref Expression
eucalg ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (1st ‘(𝑅𝑁)) = (𝑀 gcd 𝑁))
Distinct variable groups:   𝑥,𝑦,𝑀   𝑥,𝑁,𝑦   𝑥,𝐴,𝑦   𝑥,𝑅
Allowed substitution hints:   𝑅(𝑦)   𝐸(𝑥,𝑦)

Proof of Theorem eucalg
Dummy variable 𝑧 is distinct from all other variables.
StepHypRef Expression
1 nn0uz 11936 . . . . . . . 8 0 = (ℤ‘0)
2 eucalg.2 . . . . . . . 8 𝑅 = seq0((𝐸 ∘ 1st ), (ℕ0 × {𝐴}))
3 0zd 11602 . . . . . . . 8 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → 0 ∈ ℤ)
4 eucalg.3 . . . . . . . . 9 𝐴 = ⟨𝑀, 𝑁
5 opelxpi 5306 . . . . . . . . 9 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → ⟨𝑀, 𝑁⟩ ∈ (ℕ0 × ℕ0))
64, 5syl5eqel 2844 . . . . . . . 8 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → 𝐴 ∈ (ℕ0 × ℕ0))
7 eucalgval.1 . . . . . . . . . 10 𝐸 = (𝑥 ∈ ℕ0, 𝑦 ∈ ℕ0 ↦ if(𝑦 = 0, ⟨𝑥, 𝑦⟩, ⟨𝑦, (𝑥 mod 𝑦)⟩))
87eucalgf 15519 . . . . . . . . 9 𝐸:(ℕ0 × ℕ0)⟶(ℕ0 × ℕ0)
98a1i 11 . . . . . . . 8 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → 𝐸:(ℕ0 × ℕ0)⟶(ℕ0 × ℕ0))
101, 2, 3, 6, 9algrf 15509 . . . . . . 7 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → 𝑅:ℕ0⟶(ℕ0 × ℕ0))
11 ffvelrn 6522 . . . . . . 7 ((𝑅:ℕ0⟶(ℕ0 × ℕ0) ∧ 𝑁 ∈ ℕ0) → (𝑅𝑁) ∈ (ℕ0 × ℕ0))
1210, 11sylancom 704 . . . . . 6 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (𝑅𝑁) ∈ (ℕ0 × ℕ0))
13 1st2nd2 7374 . . . . . 6 ((𝑅𝑁) ∈ (ℕ0 × ℕ0) → (𝑅𝑁) = ⟨(1st ‘(𝑅𝑁)), (2nd ‘(𝑅𝑁))⟩)
1412, 13syl 17 . . . . 5 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (𝑅𝑁) = ⟨(1st ‘(𝑅𝑁)), (2nd ‘(𝑅𝑁))⟩)
1514fveq2d 6358 . . . 4 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → ( gcd ‘(𝑅𝑁)) = ( gcd ‘⟨(1st ‘(𝑅𝑁)), (2nd ‘(𝑅𝑁))⟩))
16 df-ov 6818 . . . 4 ((1st ‘(𝑅𝑁)) gcd (2nd ‘(𝑅𝑁))) = ( gcd ‘⟨(1st ‘(𝑅𝑁)), (2nd ‘(𝑅𝑁))⟩)
1715, 16syl6eqr 2813 . . 3 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → ( gcd ‘(𝑅𝑁)) = ((1st ‘(𝑅𝑁)) gcd (2nd ‘(𝑅𝑁))))
184fveq2i 6357 . . . . . . . 8 (2nd𝐴) = (2nd ‘⟨𝑀, 𝑁⟩)
19 op2ndg 7348 . . . . . . . 8 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (2nd ‘⟨𝑀, 𝑁⟩) = 𝑁)
2018, 19syl5eq 2807 . . . . . . 7 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (2nd𝐴) = 𝑁)
2120fveq2d 6358 . . . . . 6 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (𝑅‘(2nd𝐴)) = (𝑅𝑁))
2221fveq2d 6358 . . . . 5 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (2nd ‘(𝑅‘(2nd𝐴))) = (2nd ‘(𝑅𝑁)))
23 xp2nd 7368 . . . . . . . . 9 (𝐴 ∈ (ℕ0 × ℕ0) → (2nd𝐴) ∈ ℕ0)
2423nn0zd 11693 . . . . . . . 8 (𝐴 ∈ (ℕ0 × ℕ0) → (2nd𝐴) ∈ ℤ)
25 uzid 11915 . . . . . . . 8 ((2nd𝐴) ∈ ℤ → (2nd𝐴) ∈ (ℤ‘(2nd𝐴)))
2624, 25syl 17 . . . . . . 7 (𝐴 ∈ (ℕ0 × ℕ0) → (2nd𝐴) ∈ (ℤ‘(2nd𝐴)))
27 eqid 2761 . . . . . . . 8 (2nd𝐴) = (2nd𝐴)
287, 2, 27eucalgcvga 15522 . . . . . . 7 (𝐴 ∈ (ℕ0 × ℕ0) → ((2nd𝐴) ∈ (ℤ‘(2nd𝐴)) → (2nd ‘(𝑅‘(2nd𝐴))) = 0))
2926, 28mpd 15 . . . . . 6 (𝐴 ∈ (ℕ0 × ℕ0) → (2nd ‘(𝑅‘(2nd𝐴))) = 0)
306, 29syl 17 . . . . 5 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (2nd ‘(𝑅‘(2nd𝐴))) = 0)
3122, 30eqtr3d 2797 . . . 4 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (2nd ‘(𝑅𝑁)) = 0)
3231oveq2d 6831 . . 3 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → ((1st ‘(𝑅𝑁)) gcd (2nd ‘(𝑅𝑁))) = ((1st ‘(𝑅𝑁)) gcd 0))
33 xp1st 7367 . . . 4 ((𝑅𝑁) ∈ (ℕ0 × ℕ0) → (1st ‘(𝑅𝑁)) ∈ ℕ0)
34 nn0gcdid0 15465 . . . 4 ((1st ‘(𝑅𝑁)) ∈ ℕ0 → ((1st ‘(𝑅𝑁)) gcd 0) = (1st ‘(𝑅𝑁)))
3512, 33, 343syl 18 . . 3 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → ((1st ‘(𝑅𝑁)) gcd 0) = (1st ‘(𝑅𝑁)))
3617, 32, 353eqtrrd 2800 . 2 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (1st ‘(𝑅𝑁)) = ( gcd ‘(𝑅𝑁)))
37 gcdf 15457 . . . . . . 7 gcd :(ℤ × ℤ)⟶ℕ0
38 ffn 6207 . . . . . . 7 ( gcd :(ℤ × ℤ)⟶ℕ0 → gcd Fn (ℤ × ℤ))
3937, 38ax-mp 5 . . . . . 6 gcd Fn (ℤ × ℤ)
40 nn0ssz 11611 . . . . . . 7 0 ⊆ ℤ
41 xpss12 5282 . . . . . . 7 ((ℕ0 ⊆ ℤ ∧ ℕ0 ⊆ ℤ) → (ℕ0 × ℕ0) ⊆ (ℤ × ℤ))
4240, 40, 41mp2an 710 . . . . . 6 (ℕ0 × ℕ0) ⊆ (ℤ × ℤ)
43 fnssres 6166 . . . . . 6 (( gcd Fn (ℤ × ℤ) ∧ (ℕ0 × ℕ0) ⊆ (ℤ × ℤ)) → ( gcd ↾ (ℕ0 × ℕ0)) Fn (ℕ0 × ℕ0))
4439, 42, 43mp2an 710 . . . . 5 ( gcd ↾ (ℕ0 × ℕ0)) Fn (ℕ0 × ℕ0)
457eucalginv 15520 . . . . . 6 (𝑧 ∈ (ℕ0 × ℕ0) → ( gcd ‘(𝐸𝑧)) = ( gcd ‘𝑧))
468ffvelrni 6523 . . . . . . 7 (𝑧 ∈ (ℕ0 × ℕ0) → (𝐸𝑧) ∈ (ℕ0 × ℕ0))
47 fvres 6370 . . . . . . 7 ((𝐸𝑧) ∈ (ℕ0 × ℕ0) → (( gcd ↾ (ℕ0 × ℕ0))‘(𝐸𝑧)) = ( gcd ‘(𝐸𝑧)))
4846, 47syl 17 . . . . . 6 (𝑧 ∈ (ℕ0 × ℕ0) → (( gcd ↾ (ℕ0 × ℕ0))‘(𝐸𝑧)) = ( gcd ‘(𝐸𝑧)))
49 fvres 6370 . . . . . 6 (𝑧 ∈ (ℕ0 × ℕ0) → (( gcd ↾ (ℕ0 × ℕ0))‘𝑧) = ( gcd ‘𝑧))
5045, 48, 493eqtr4d 2805 . . . . 5 (𝑧 ∈ (ℕ0 × ℕ0) → (( gcd ↾ (ℕ0 × ℕ0))‘(𝐸𝑧)) = (( gcd ↾ (ℕ0 × ℕ0))‘𝑧))
512, 8, 44, 50alginv 15511 . . . 4 ((𝐴 ∈ (ℕ0 × ℕ0) ∧ 𝑁 ∈ ℕ0) → (( gcd ↾ (ℕ0 × ℕ0))‘(𝑅𝑁)) = (( gcd ↾ (ℕ0 × ℕ0))‘(𝑅‘0)))
526, 51sylancom 704 . . 3 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (( gcd ↾ (ℕ0 × ℕ0))‘(𝑅𝑁)) = (( gcd ↾ (ℕ0 × ℕ0))‘(𝑅‘0)))
53 fvres 6370 . . . 4 ((𝑅𝑁) ∈ (ℕ0 × ℕ0) → (( gcd ↾ (ℕ0 × ℕ0))‘(𝑅𝑁)) = ( gcd ‘(𝑅𝑁)))
5412, 53syl 17 . . 3 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (( gcd ↾ (ℕ0 × ℕ0))‘(𝑅𝑁)) = ( gcd ‘(𝑅𝑁)))
55 0nn0 11520 . . . . 5 0 ∈ ℕ0
56 ffvelrn 6522 . . . . 5 ((𝑅:ℕ0⟶(ℕ0 × ℕ0) ∧ 0 ∈ ℕ0) → (𝑅‘0) ∈ (ℕ0 × ℕ0))
5710, 55, 56sylancl 697 . . . 4 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (𝑅‘0) ∈ (ℕ0 × ℕ0))
58 fvres 6370 . . . 4 ((𝑅‘0) ∈ (ℕ0 × ℕ0) → (( gcd ↾ (ℕ0 × ℕ0))‘(𝑅‘0)) = ( gcd ‘(𝑅‘0)))
5957, 58syl 17 . . 3 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (( gcd ↾ (ℕ0 × ℕ0))‘(𝑅‘0)) = ( gcd ‘(𝑅‘0)))
6052, 54, 593eqtr3d 2803 . 2 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → ( gcd ‘(𝑅𝑁)) = ( gcd ‘(𝑅‘0)))
611, 2, 3, 6algr0 15508 . . . . 5 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (𝑅‘0) = 𝐴)
6261, 4syl6eq 2811 . . . 4 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (𝑅‘0) = ⟨𝑀, 𝑁⟩)
6362fveq2d 6358 . . 3 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → ( gcd ‘(𝑅‘0)) = ( gcd ‘⟨𝑀, 𝑁⟩))
64 df-ov 6818 . . 3 (𝑀 gcd 𝑁) = ( gcd ‘⟨𝑀, 𝑁⟩)
6563, 64syl6eqr 2813 . 2 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → ( gcd ‘(𝑅‘0)) = (𝑀 gcd 𝑁))
6636, 60, 653eqtrd 2799 1 ((𝑀 ∈ ℕ0𝑁 ∈ ℕ0) → (1st ‘(𝑅𝑁)) = (𝑀 gcd 𝑁))
 Colors of variables: wff setvar class Syntax hints:   → wi 4   ∧ wa 383   = wceq 1632   ∈ wcel 2140   ⊆ wss 3716  ifcif 4231  {csn 4322  ⟨cop 4328   × cxp 5265   ↾ cres 5269   ∘ ccom 5271   Fn wfn 6045  ⟶wf 6046  ‘cfv 6050  (class class class)co 6815   ↦ cmpt2 6817  1st c1st 7333  2nd c2nd 7334  0cc0 10149  ℕ0cn0 11505  ℤcz 11590  ℤ≥cuz 11900   mod cmo 12883  seqcseq 13016   gcd cgcd 15439 This theorem was proved from axioms:  ax-mp 5  ax-1 6  ax-2 7  ax-3 8  ax-gen 1871  ax-4 1886  ax-5 1989  ax-6 2055  ax-7 2091  ax-8 2142  ax-9 2149  ax-10 2169  ax-11 2184  ax-12 2197  ax-13 2392  ax-ext 2741  ax-sep 4934  ax-nul 4942  ax-pow 4993  ax-pr 5056  ax-un 7116  ax-cnex 10205  ax-resscn 10206  ax-1cn 10207  ax-icn 10208  ax-addcl 10209  ax-addrcl 10210  ax-mulcl 10211  ax-mulrcl 10212  ax-mulcom 10213  ax-addass 10214  ax-mulass 10215  ax-distr 10216  ax-i2m1 10217  ax-1ne0 10218  ax-1rid 10219  ax-rnegex 10220  ax-rrecex 10221  ax-cnre 10222  ax-pre-lttri 10223  ax-pre-lttrn 10224  ax-pre-ltadd 10225  ax-pre-mulgt0 10226  ax-pre-sup 10227 This theorem depends on definitions:  df-bi 197  df-or 384  df-an 385  df-3or 1073  df-3an 1074  df-tru 1635  df-ex 1854  df-nf 1859  df-sb 2048  df-eu 2612  df-mo 2613  df-clab 2748  df-cleq 2754  df-clel 2757  df-nfc 2892  df-ne 2934  df-nel 3037  df-ral 3056  df-rex 3057  df-reu 3058  df-rmo 3059  df-rab 3060  df-v 3343  df-sbc 3578  df-csb 3676  df-dif 3719  df-un 3721  df-in 3723  df-ss 3730  df-pss 3732  df-nul 4060  df-if 4232  df-pw 4305  df-sn 4323  df-pr 4325  df-tp 4327  df-op 4329  df-uni 4590  df-iun 4675  df-br 4806  df-opab 4866  df-mpt 4883  df-tr 4906  df-id 5175  df-eprel 5180  df-po 5188  df-so 5189  df-fr 5226  df-we 5228  df-xp 5273  df-rel 5274  df-cnv 5275  df-co 5276  df-dm 5277  df-rn 5278  df-res 5279  df-ima 5280  df-pred 5842  df-ord 5888  df-on 5889  df-lim 5890  df-suc 5891  df-iota 6013  df-fun 6052  df-fn 6053  df-f 6054  df-f1 6055  df-fo 6056  df-f1o 6057  df-fv 6058  df-riota 6776  df-ov 6818  df-oprab 6819  df-mpt2 6820  df-om 7233  df-1st 7335  df-2nd 7336  df-wrecs 7578  df-recs 7639  df-rdg 7677  df-er 7914  df-en 8125  df-dom 8126  df-sdom 8127  df-sup 8516  df-inf 8517  df-pnf 10289  df-mnf 10290  df-xr 10291  df-ltxr 10292  df-le 10293  df-sub 10481  df-neg 10482  df-div 10898  df-nn 11234  df-2 11292  df-3 11293  df-n0 11506  df-z 11591  df-uz 11901  df-rp 12047  df-fz 12541  df-fl 12808  df-mod 12884  df-seq 13017  df-exp 13076  df-cj 14059  df-re 14060  df-im 14061  df-sqrt 14195  df-abs 14196  df-dvds 15204  df-gcd 15440 This theorem is referenced by: (None)
 Copyright terms: Public domain W3C validator