Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 11cdccb

Browse files
Jon Eugsterjoneugster
andcommitted
feat(data/rat/defs): add denominator as pnat (#15101)
Option to bundle `x.denom` and `x.pos` into a pnat, which can be useful in defining functions using the denominator. Co-authored-by: Jon Eugster <eugster.jon@gmail.com>
1 parent feb34df commit 11cdccb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/data/rat/defs.lean

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,4 +891,22 @@ protected lemma «forall» {p : ℚ → Prop} : (∀ r, p r) ↔ ∀ a b : ℤ,
891891
protected lemma «exists» {p : ℚ → Prop} : (∃ r, p r) ↔ ∃ a b : ℤ, p (a / b) :=
892892
⟨λ ⟨r, hr⟩, ⟨r.num, r.denom, by rwa [← mk_eq_div, num_denom]⟩, λ ⟨a, b, h⟩, ⟨_, h⟩⟩
893893

894+
/-!
895+
### Denominator as `ℕ+`
896+
-/
897+
section pnat_denom
898+
899+
/-- Denominator as `ℕ+`. -/
900+
def pnat_denom (x : ℚ) : ℕ+ := ⟨x.denom, x.pos⟩
901+
902+
@[simp] lemma coe_pnat_denom (x : ℚ) : (x.pnat_denom : ℕ) = x.denom := rfl
903+
904+
@[simp] lemma mk_pnat_pnat_denom_eq (x : ℚ) : mk_pnat x.num x.pnat_denom = x :=
905+
by rw [pnat_denom, mk_pnat_eq, num_denom]
906+
907+
lemma pnat_denom_eq_iff_denom_eq {x : ℚ} {n : ℕ+} : x.pnat_denom = n ↔ x.denom = ↑n :=
908+
subtype.ext_iff
909+
910+
end pnat_denom
911+
894912
end rat

0 commit comments

Comments
 (0)