# HG changeset patch # User Shinji KONO # Date 1624888887 -32400 # Node ID 61d9fdb22f2dcaff7e1f17b21090396cbfac030c # Parent 6cd80d8432ead8ee0d76dd240dc91737dfb1386d ... diff -r 6cd80d8432ea -r 61d9fdb22f2d automaton-in-agda/src/gcd.agda --- a/automaton-in-agda/src/gcd.agda Mon Jun 28 19:28:52 2021 +0900 +++ b/automaton-in-agda/src/gcd.agda Mon Jun 28 23:01:27 2021 +0900 @@ -372,9 +372,38 @@ (i + j ) - j ≡⟨ cong (λ k → k - j ) (+-comm i j ) ⟩ (j + i) - j ∎ } where open ≡-Reasoning +div→gcd : {n k : ℕ } → k > 1 → Dividable k n → gcd n k ≡ k +div→gcd {n} {k} k>1 = n-induction {_} {_} {ℕ} {λ m → Dividable k m → gcd m k ≡ k } (λ x → x) I n where + decl : {m : ℕ } → 0 < m → m - k < m + decl {m} 01 ) 01 d div= ) + ... | tri> ¬a ¬b c = subst (λ g → g ≡ k) ind1 ( prev (proj2 (div-div k>1 div= d))) where + ind1 : gcd (m - k) k ≡ gcd m k + ind1 = begin + gcd (m - k) k ≡⟨ sym (gcd+j (m - k) _) ⟩ + gcd (m - k + k) k ≡⟨ cong (λ g → gcd g k) (minus+n {m} {k} c) ⟩ + gcd m k ∎ where open ≡-Reasoning + ... | tri< a ¬b ¬c with <-cmp 0 m + ... | tri< a₁ ¬b₁ ¬c₁ = ⊥-elim ( div1 a₁ (<-trans a1 (s≤s z≤n) a d ) + ... | tri≈ ¬a refl ¬c = gcdmm k k + ... | tri> ¬a ¬b c = ⊥-elim ( nat-≡< (sym eq) (minus>0 c) ) + I : Ninduction ℕ _ (λ x → x) + I = record { + pnext = λ p → p - k + ; fzero = λ {m} eq → fzero m eq + ; decline = λ {m} lt → decl lt + ; ind = λ {p} prev → ind p prev + } GCDi : {i j : ℕ } → GCD i i j j -GCDi {i} {j} = record { i0 : { k i : ℕ } → (d : Dividable k i ) → 0 < i → 0 < Dividable.factor d +f-div>0 {k} {i} d 00 d (s≤s z≤n)) ⟩ + gcd (suc i) (suc j) * f ≡⟨ +-comm 0 _ ⟩ + gcd (suc i) (suc j) * f + 0 ≡⟨ cong (λ k → k + 0) (*-comm (gcd (suc i) (suc j)) _ ) ⟩ + Dividable.factor (proj1 (gcd-dividable (suc i) (suc j))) * gcd (suc i) (suc j) + 0 ≡⟨ Dividable.is-factor (proj1 (gcd-dividable (suc i) (suc j))) ⟩ + suc i ∎ where + d = proj1 (gcd-dividable (suc i) (suc j)) + f = Dividable.factor (proj1 (gcd-dividable (suc i) (suc j))) + open ≤-Reasoning + +gcd-≤ : { i j : ℕ } → 0 < i → 0 < j → gcd i j ≤ i +gcd-≤ {i} {j} 0 ¬a ¬b c = ≤-trans (subst (λ k → k ≤ j) (gcdsym {j} {i}) (gcd-≤i j i 0 a (s≤s (gcd>0 p x (<-trans a ¬a ¬b c = ⊥-elim ( nat-≡< (sym (prime (gcd p x) {!!} (gcd>0 p x (<-trans a ¬a ¬b c = ⊥-elim ( nat-≡< (sym (prime (gcd p x) ge13 ( ¬a ¬b c = ⊥-elim ( nat-≤> (gcd-≤ (<-trans a 1 + ge18 = subst (λ k → 1 < k ) (sym (div→gcd {p} {gcd p x} c ge19 )) c ge10 : gcd p a ≡ 1 ge10 with ge12 a 0 ( Euclid.eqb ge11 * a ) → (Dividable.factor div-ab * Euclid.eqb ge11 - b * Euclid.eqa ge11 ) * p + 0 ≡ b - ge15 = {!!} + ge15 lt = begin + (Dividable.factor div-ab * Euclid.eqb ge11 - b * Euclid.eqa ge11 ) * p + 0 ≡⟨ {!!} ⟩ + (Dividable.factor div-ab * Euclid.eqb ge11 - b * Euclid.eqa ge11 ) * p ≡⟨ {!!} ⟩ + ((Dividable.factor div-ab * Euclid.eqb ge11) * p) - ((b * Euclid.eqa ge11) * p) ≡⟨ cong (λ k → k - ((b * Euclid.eqa ge11) * p) ) ge18 ⟩ + (b * (a * Euclid.eqb ge11 )) - ((b * Euclid.eqa ge11) * p ) ≡⟨ {!!} ⟩ + (b * (a * Euclid.eqb ge11 )) - (b * (Euclid.eqa ge11 * p) ) ≡⟨ {!!} ⟩ + b * ( a * Euclid.eqb ge11 - (Euclid.eqa ge11 * p) ) ≡⟨ {!!} ⟩ + b * ( Euclid.eqb ge11 * a - Euclid.eqa ge11 * p ) ≡⟨ cong (b *_) {!!} ⟩ + b * gcd p a ≡⟨ cong (b *_) ge10 ⟩ + b * 1 ≡⟨ m*1=m ⟩ + b ∎ where open ≡-Reasoning ge17 : (x y : ℕ ) → x ≡ y → x ≤ y ge17 x x refl = refl-≤ ge16 : Dividable p b @@ -716,35 +793,6 @@ ... | tri> ¬a ¬b c = record { factor = Dividable.factor div-ab * Euclid.eqb ge11 - b * Euclid.eqa ge11 ; is-factor = ge15 c } -div→gcd : {n k : ℕ } → k > 1 → Dividable k n → gcd n k ≡ k -div→gcd {n} {k} k>1 = n-induction {_} {_} {ℕ} {λ m → Dividable k m → gcd m k ≡ k } (λ x → x) I n where - decl : {m : ℕ } → 0 < m → m - k < m - decl {m} 01 ) 01 d div= ) - ... | tri> ¬a ¬b c = subst (λ g → g ≡ k) ind1 ( prev (proj2 (div-div k>1 div= d))) where - ind1 : gcd (m - k) k ≡ gcd m k - ind1 = begin - gcd (m - k) k ≡⟨ sym (gcd+j (m - k) _) ⟩ - gcd (m - k + k) k ≡⟨ cong (λ g → gcd g k) (minus+n {m} {k} c) ⟩ - gcd m k ∎ where open ≡-Reasoning - ... | tri< a ¬b ¬c with <-cmp 0 m - ... | tri< a₁ ¬b₁ ¬c₁ = ⊥-elim ( div1 a₁ (<-trans a1 (s≤s z≤n) a d ) - ... | tri≈ ¬a refl ¬c = gcdmm k k - ... | tri> ¬a ¬b c = ⊥-elim ( nat-≡< (sym eq) (minus>0 c) ) - I : Ninduction ℕ _ (λ x → x) - I = record { - pnext = λ p → p - k - ; fzero = λ {m} eq → fzero m eq - ; decline = λ {m} lt → decl lt - ; ind = λ {p} prev → ind p prev - } gcdmul+1 : ( m n : ℕ ) → gcd (m * n + 1) n ≡ 1 gcdmul+1 zero n = gcd204 n @@ -764,29 +812,6 @@ --gcd-dividable : ( i j : ℕ ) -- → Dividable ( gcd i j ) i ∧ Dividable ( gcd i j ) j -f-div>0 : { k i : ℕ } → (d : Dividable k i ) → 0 < i → 0 < Dividable.factor d -f-div>0 {k} {i} d 00 d (s≤s z≤n)) ⟩ - gcd (suc i) (suc j) * f ≡⟨ +-comm 0 _ ⟩ - gcd (suc i) (suc j) * f + 0 ≡⟨ cong (λ k → k + 0) (*-comm (gcd (suc i) (suc j)) _ ) ⟩ - Dividable.factor (proj1 (gcd-dividable (suc i) (suc j))) * gcd (suc i) (suc j) + 0 ≡⟨ Dividable.is-factor (proj1 (gcd-dividable (suc i) (suc j))) ⟩ - suc i ∎ where - d = proj1 (gcd-dividable (suc i) (suc j)) - f = Dividable.factor (proj1 (gcd-dividable (suc i) (suc j))) - open ≤-Reasoning - -gcd-≥ : ( i j : ℕ ) → 0 < i → i ≤ j → gcd j i ≤ i -gcd-≥ i j 0