Browse Source

Some work on rationals.

gas-move-test
Thomas Kerber 9 months ago
parent
commit
437071102b
Signed by: Thomas Kerber <tk@drwx.org> GPG Key ID: 8489B911F9ED617B
1 changed files with 30 additions and 4 deletions
  1. 30
    4
      Yggdrasil/Rational.agda

+ 30
- 4
Yggdrasil/Rational.agda View File

@@ -3,23 +3,49 @@ module Yggdrasil.Rational where
open import Data.Bool using (true; false; T)
open import Data.Integer as ℤ using (ℤ; +_)
open import Data.Nat as ℕ using (ℕ; suc; zero)
open import Data.Nat.GCD using (GCD; gcd)
open import Data.Nat.GCD as GCD using (GCD; gcd)
open import Data.Nat.Divisibility using (_∣_; divides)
open import Data.Nat.Coprimality using (coprime?; gcd-coprime)
open import Data.Nat.Coprimality using (coprime?; gcd-coprime; Bézout-coprime)
open import Data.Nat.Properties using (*-comm; *-assoc)
open import Data.Product renaming (_,_ to ⟨_,_⟩)
open import Data.Rational using (ℚ) renaming (_÷_ to _÷†_)
open import Data.Unit using (⊤; tt)
open import Data.Empty using (⊥)
open import Data.Empty using (⊥; ⊥-elim)
open import Data.Sign using (Sign) renaming (+ to s+; - to s-)
open import Relation.Nullary using (yes; no; ¬_)
open import Relation.Nullary.Decidable using (True; False; ⌊_⌋; fromWitness)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; _≢_; refl; subst₂; sym; cong)
open Eq.≡-Reasoning using (_≡⟨_⟩_; _∎; begin_)

open ℚ

infixl 6 _+_ _-_
infixl 7 _*_ _÷_

1+≢*0 : ∀ x y → suc x ≢ y ℕ.* 0
1+≢*0 x zero ()
1+≢*0 x (suc y) = 1+≢*0 x y

simp : ∀ x y-1 → ℚ
simp x y-1 with GCD.Bézout.lemma x (suc y-1)
... | GCD.Bézout.result 0 (GCD.is ⟨ _ , divides y′ y-eq ⟩ _) _ = ⊥-elim (1+≢*0 y-1 y′ y-eq)
... | GCD.Bézout.result (suc d-1) (GCD.is ⟨ divides x′ x-eq , divides y′ y-eq ⟩ _) bézout = _÷†_ (+ x′) y′ {fromWitness {!(Bézout-coprime bézout′)!}}
where
y = suc y-1
d = suc d-1

bézout′ : GCD.Bézout.Identity d (x′ ℕ.* d) (y′ ℕ.* d)
bézout′ = subst₂ (GCD.Bézout.Identity d) x-eq y-eq bézout

eq-prf : x ℕ.* y′ ≡ x′ ℕ.* y
eq-prf = begin
x ℕ.* y′ ≡⟨ cong (λ z → z ℕ.* y′) x-eq ⟩
x′ ℕ.* d ℕ.* y′ ≡⟨ *-assoc x′ d y′ ⟩
x′ ℕ.* (d ℕ.* y′) ≡⟨ sym (cong (ℕ._*_ x′) (*-comm y′ d)) ⟩
x′ ℕ.* (y′ ℕ.* d) ≡⟨ sym (cong (ℕ._*_ x′) y-eq) ⟩
x′ ℕ.* y ∎

postulate
_÷_ : ℤ → (d : ℕ) → {d≢0 : False (d ℕ.≟ 0)} → ℚ


Loading…
Cancel
Save