-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: port Data.Rat.Encodable (#1569)
- Loading branch information
1 parent
f7d4c2c
commit dceaab4
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |