Skip to content

Commit

Permalink
a bit of instance engineering
Browse files Browse the repository at this point in the history
  • Loading branch information
plt-amy committed Sep 11, 2024
1 parent 730aefb commit 69bc402
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Data/Rational/Base.lagda.md
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,13 @@ abstract
to-nonzero-frac p = inc λ α p (sym (*ℤ-oner _) ∙ from-same-rational (unquotℚ α))

instance
Nonzero-pos : {x d} {p : Positive d} Nonzero (toℚ (possuc x / d [ p ]))
Nonzero-pos = inc (λ p absurd (suc≠zero (pos-injective (from-same-rational (unquotℚ p)))))

Nonzero-neg : {x d} {p : Positive d} Nonzero (toℚ (negsuc x / d [ p ]))
Nonzero-neg = inc (λ p absurd (negsuc≠pos (from-same-rational (unquotℚ p))))

Nonzero-pos : {x d} {p : Positive d} ⦃ _ : Positive x ⦄ Nonzero (toℚ (x / d [ p ]))
Nonzero-pos {.(possuc x)} ⦃ pos x ⦄ = inc (λ p absurd (suc≠zero (pos-injective (from-same-rational (unquotℚ p)))))
{-# OVERLAPPABLE Nonzero-pos #-}

-- Since we want invℚ to be injective as well, we re-wrap the result on
-- the RHS, to make sure the clause is headed by a constructor.
invℚ : (x : ℚ) ⦃ p : Nonzero x ⦄
Expand Down

0 comments on commit 69bc402

Please sign in to comment.