@@ -43,7 +43,7 @@ open import Algebra.Definitions {A = ℕ} _≡_ as Algebra
43
43
44
44
gcd′ : ∀ m n → Acc _<_ m → n < m → ℕ
45
45
gcd′ m zero _ _ = m
46
- gcd′ m n@(suc _) (acc rec) n<m = gcd′ n (m % n) (rec _ n<m) (m%n<n m n)
46
+ gcd′ m n@(suc _) (acc rec) n<m = gcd′ n (m % n) (rec n<m) (m%n<n m n)
47
47
48
48
gcd : ℕ → ℕ → ℕ
49
49
gcd m n with <-cmp m n
@@ -55,15 +55,15 @@ gcd m n with <-cmp m n
55
55
-- Core properties of gcd′
56
56
57
57
gcd′[m,n]∣m,n : ∀ {m n} rec n<m → gcd′ m n rec n<m ∣ m × gcd′ m n rec n<m ∣ n
58
- gcd′[m,n]∣m,n {m} {zero} rec n<m = ∣-refl , m ∣0
59
- gcd′[m,n]∣m,n {m} {suc n } (acc rec) n<m
60
- with gcd∣n , gcd∣m%n ← gcd′[m,n]∣m,n (rec _ n<m) (m%n<n m (suc n) )
58
+ gcd′[m,n]∣m,n {m} {zero} rec n<m = ∣-refl , m ∣0
59
+ gcd′[m,n]∣m,n {m} {n@( suc _) } (acc rec) n<m
60
+ with gcd∣n , gcd∣m%n ← gcd′[m,n]∣m,n (rec n<m) (m%n<n m n )
61
61
= ∣n∣m%n⇒∣m gcd∣n gcd∣m%n , gcd∣n
62
62
63
63
gcd′-greatest : ∀ {m n c} rec n<m → c ∣ m → c ∣ n → c ∣ gcd′ m n rec n<m
64
- gcd′-greatest {m} {zero} rec n<m c∣m c∣n = c∣m
65
- gcd′-greatest {m} {suc n } (acc rec) n<m c∣m c∣n =
66
- gcd′-greatest (rec _ n<m) (m%n<n m (suc n) ) c∣n (%-presˡ-∣ c∣m c∣n)
64
+ gcd′-greatest {m} {zero} rec n<m c∣m c∣n = c∣m
65
+ gcd′-greatest {m} {n@( suc _) } (acc rec) n<m c∣m c∣n =
66
+ gcd′-greatest (rec n<m) (m%n<n m n ) c∣n (%-presˡ-∣ c∣m c∣n)
67
67
68
68
------------------------------------------------------------------------
69
69
-- Core properties of gcd
@@ -387,13 +387,13 @@ module Bézout where
387
387
P (m , n) = Lemma m n
388
388
389
389
gcd″ : ∀ p → (<′-Rec ⊗ <′-Rec) P p → P p
390
- gcd″ (zero , n) rec = Lemma.base n
391
- gcd″ (suc m , zero) rec = Lemma.sym (Lemma.base (suc m) )
392
- gcd″ (suc m , suc n) rec with compare m n
393
- ... | equal m = Lemma.refl (suc m)
394
- ... | less m k = Lemma.stepˡ $ proj₁ rec (suc k) ( lem₁ k m)
390
+ gcd″ (zero , n) rec = Lemma.base n
391
+ gcd″ (m@( suc _) , zero) rec = Lemma.sym (Lemma.base m )
392
+ gcd″ (m′@( suc m) , n′@( suc n) ) rec with compare m n
393
+ ... | equal m = Lemma.refl m′
394
+ ... | less m k = Lemma.stepˡ $ proj₁ rec (lem₁ k m)
395
395
-- "gcd (suc m) (suc k)"
396
- ... | greater n k = Lemma.stepʳ $ proj₂ rec (suc k) ( lem₁ k n) (suc n)
396
+ ... | greater n k = Lemma.stepʳ $ proj₂ rec (lem₁ k n) n′
397
397
-- "gcd (suc k) (suc n)"
398
398
399
399
-- Bézout's identity can be recovered from the GCD.
0 commit comments