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

Theorem eucalgval 15920
Description: Euclid's Algorithm eucalg 15925 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 𝐸 for Euclid's Algorithm. (Contributed by Paul Chapman, 31-Mar-2011.) (Revised by Mario Carneiro, 28-May-2014.)

Hypothesis
Ref Expression
eucalgval.1 𝐸 = (𝑥 ∈ ℕ0, 𝑦 ∈ ℕ0 ↦ if(𝑦 = 0, ⟨𝑥, 𝑦⟩, ⟨𝑦, (𝑥 mod 𝑦)⟩))
Assertion
Ref Expression
eucalgval (𝑋 ∈ (ℕ0 × ℕ0) → (𝐸𝑋) = if((2nd𝑋) = 0, 𝑋, ⟨(2nd𝑋), ( mod ‘𝑋)⟩))
Distinct variable group:   𝑥,𝑦,𝑋
Allowed substitution hints:   𝐸(𝑥,𝑦)

Proof of Theorem eucalgval
StepHypRef Expression
1 df-ov 7153 . . 3 ((1st𝑋)𝐸(2nd𝑋)) = (𝐸‘⟨(1st𝑋), (2nd𝑋)⟩)
2 xp1st 7715 . . . 4 (𝑋 ∈ (ℕ0 × ℕ0) → (1st𝑋) ∈ ℕ0)
3 xp2nd 7716 . . . 4 (𝑋 ∈ (ℕ0 × ℕ0) → (2nd𝑋) ∈ ℕ0)
4 eucalgval.1 . . . . 5 𝐸 = (𝑥 ∈ ℕ0, 𝑦 ∈ ℕ0 ↦ if(𝑦 = 0, ⟨𝑥, 𝑦⟩, ⟨𝑦, (𝑥 mod 𝑦)⟩))
54eucalgval2 15919 . . . 4 (((1st𝑋) ∈ ℕ0 ∧ (2nd𝑋) ∈ ℕ0) → ((1st𝑋)𝐸(2nd𝑋)) = if((2nd𝑋) = 0, ⟨(1st𝑋), (2nd𝑋)⟩, ⟨(2nd𝑋), ((1st𝑋) mod (2nd𝑋))⟩))
62, 3, 5syl2anc 586 . . 3 (𝑋 ∈ (ℕ0 × ℕ0) → ((1st𝑋)𝐸(2nd𝑋)) = if((2nd𝑋) = 0, ⟨(1st𝑋), (2nd𝑋)⟩, ⟨(2nd𝑋), ((1st𝑋) mod (2nd𝑋))⟩))
71, 6syl5eqr 2870 . 2 (𝑋 ∈ (ℕ0 × ℕ0) → (𝐸‘⟨(1st𝑋), (2nd𝑋)⟩) = if((2nd𝑋) = 0, ⟨(1st𝑋), (2nd𝑋)⟩, ⟨(2nd𝑋), ((1st𝑋) mod (2nd𝑋))⟩))
8 1st2nd2 7722 . . 3 (𝑋 ∈ (ℕ0 × ℕ0) → 𝑋 = ⟨(1st𝑋), (2nd𝑋)⟩)
98fveq2d 6669 . 2 (𝑋 ∈ (ℕ0 × ℕ0) → (𝐸𝑋) = (𝐸‘⟨(1st𝑋), (2nd𝑋)⟩))
108fveq2d 6669 . . . . 5 (𝑋 ∈ (ℕ0 × ℕ0) → ( mod ‘𝑋) = ( mod ‘⟨(1st𝑋), (2nd𝑋)⟩))
11 df-ov 7153 . . . . 5 ((1st𝑋) mod (2nd𝑋)) = ( mod ‘⟨(1st𝑋), (2nd𝑋)⟩)
1210, 11syl6eqr 2874 . . . 4 (𝑋 ∈ (ℕ0 × ℕ0) → ( mod ‘𝑋) = ((1st𝑋) mod (2nd𝑋)))
1312opeq2d 4804 . . 3 (𝑋 ∈ (ℕ0 × ℕ0) → ⟨(2nd𝑋), ( mod ‘𝑋)⟩ = ⟨(2nd𝑋), ((1st𝑋) mod (2nd𝑋))⟩)
148, 13ifeq12d 4487 . 2 (𝑋 ∈ (ℕ0 × ℕ0) → if((2nd𝑋) = 0, 𝑋, ⟨(2nd𝑋), ( mod ‘𝑋)⟩) = if((2nd𝑋) = 0, ⟨(1st𝑋), (2nd𝑋)⟩, ⟨(2nd𝑋), ((1st𝑋) mod (2nd𝑋))⟩))
157, 9, 143eqtr4d 2866 1 (𝑋 ∈ (ℕ0 × ℕ0) → (𝐸𝑋) = if((2nd𝑋) = 0, 𝑋, ⟨(2nd𝑋), ( mod ‘𝑋)⟩))
Colors of variables: wff setvar class
Syntax hints:  wi 4   = wceq 1533  wcel 2110  ifcif 4467  cop 4567   × cxp 5548  cfv 6350  (class class class)co 7150  cmpo 7152  1st c1st 7681  2nd c2nd 7682  0cc0 10531  0cn0 11891   mod cmo 13231
This theorem was proved from axioms:  ax-mp 5  ax-1 6  ax-2 7  ax-3 8  ax-gen 1792  ax-4 1806  ax-5 1907  ax-6 1966  ax-7 2011  ax-8 2112  ax-9 2120  ax-10 2141  ax-11 2156  ax-12 2172  ax-ext 2793  ax-sep 5196  ax-nul 5203  ax-pow 5259  ax-pr 5322  ax-un 7455
This theorem depends on definitions:  df-bi 209  df-an 399  df-or 844  df-3an 1085  df-tru 1536  df-ex 1777  df-nf 1781  df-sb 2066  df-mo 2618  df-eu 2650  df-clab 2800  df-cleq 2814  df-clel 2893  df-nfc 2963  df-ral 3143  df-rex 3144  df-rab 3147  df-v 3497  df-sbc 3773  df-dif 3939  df-un 3941  df-in 3943  df-ss 3952  df-nul 4292  df-if 4468  df-sn 4562  df-pr 4564  df-op 4568  df-uni 4833  df-br 5060  df-opab 5122  df-mpt 5140  df-id 5455  df-xp 5556  df-rel 5557  df-cnv 5558  df-co 5559  df-dm 5560  df-rn 5561  df-iota 6309  df-fun 6352  df-fv 6358  df-ov 7153  df-oprab 7154  df-mpo 7155  df-1st 7683  df-2nd 7684
This theorem is referenced by:  eucalginv  15922  eucalglt  15923
  Copyright terms: Public domain W3C validator