Skip to content

Commit

Permalink
feat: port Data.Rat.Encodable (#1569)
Browse files Browse the repository at this point in the history
  • Loading branch information
qawbecrdtey committed Jan 14, 2023
1 parent f7d4c2c commit dceaab4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions Mathlib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ import Mathlib.Data.Quot
import Mathlib.Data.Rat.Basic
import Mathlib.Data.Rat.Cast
import Mathlib.Data.Rat.Defs
import Mathlib.Data.Rat.Encodable
import Mathlib.Data.Rat.Floor
import Mathlib.Data.Rat.Init
import Mathlib.Data.Rat.Lemmas
Expand Down
31 changes: 31 additions & 0 deletions Mathlib/Data/Rat/Encodable.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
! This file was ported from Lean 3 source module data.rat.encodable
! leanprover-community/mathlib commit 9003f28797c0664a49e4179487267c494477d853
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Logic.Encodable.Basic
import Mathlib.Data.Nat.GCD.Basic
import Mathlib.Data.Rat.Init

/-! # The rationals are `Encodable`.
As a consequence we also get the instance `Countable ℚ`.
This is kept separate from `Data.Rat.Defs` in order to minimize imports.
-/


namespace Rat

instance : Encodable ℚ :=
Encodable.ofEquiv (Σn : ℤ, { d : ℕ // 0 < d ∧ n.natAbs.coprime d })
fun ⟨a, b, c, d⟩ => ⟨a, b, Nat.pos_of_ne_zero c, d⟩,
fun ⟨a, b, c, d⟩ => ⟨a, b, Nat.pos_iff_ne_zero.mp c, d⟩,
fun _ => rfl, fun ⟨_, _, _, _⟩ => rfl⟩

end Rat

0 comments on commit dceaab4

Please sign in to comment.