feat(data/pnat): positive natural numbers
This commit is contained in:
parent
d10a799b79
commit
92d76c22a5
2 changed files with 45 additions and 4 deletions
|
|
@ -3,13 +3,10 @@ Copyright (c) 2017 Microsoft Corporation. All rights reserved.
|
|||
Released under Apache 2.0 license as described in the file LICENSE.
|
||||
Authors: Leonardo de Moura, Mario Carneiro
|
||||
-/
|
||||
import data.list.set data.list.comb init.data.array
|
||||
import data.list.set data.list.comb init.data.array data.pnat
|
||||
|
||||
universes u v w
|
||||
|
||||
def pnat := {n : ℕ // n > 0}
|
||||
notation `ℕ+` := pnat
|
||||
|
||||
def bucket_array (α : Type u) (β : α → Type v) (n : ℕ+) :=
|
||||
array (list Σ a, β a) n.1
|
||||
|
||||
|
|
|
|||
44
library/data/pnat.lean
Normal file
44
library/data/pnat.lean
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/-
|
||||
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
|
||||
Released under Apache 2.0 license as described in the file LICENSE.
|
||||
Author: Mario Carneiro
|
||||
-/
|
||||
|
||||
def pnat := {n : ℕ // n > 0}
|
||||
notation `ℕ+` := pnat
|
||||
|
||||
instance coe_pnat_nat : has_coe ℕ+ ℕ := ⟨subtype.val⟩
|
||||
|
||||
meta def exact_dec_trivial : tactic unit := `[exact dec_trivial]
|
||||
|
||||
namespace nat
|
||||
|
||||
def to_pnat (n : ℕ) (h : n > 0 . exact_dec_trivial) : ℕ+ := ⟨n, h⟩
|
||||
|
||||
def succ_pnat (n : ℕ) : ℕ+ := ⟨succ n, succ_pos n⟩
|
||||
|
||||
def to_pnat' (n : ℕ) : ℕ+ := succ_pnat (pred n)
|
||||
end nat
|
||||
|
||||
instance coe_nat_pnat : has_coe ℕ ℕ+ := ⟨nat.to_pnat'⟩
|
||||
|
||||
namespace pnat
|
||||
open nat
|
||||
|
||||
instance : has_one ℕ+ := ⟨succ_pnat 0⟩
|
||||
|
||||
protected def add : ℕ+ → ℕ+ → ℕ+
|
||||
| ⟨m, m0⟩ ⟨n, n0⟩ := ⟨m + n, add_pos m0 n0⟩
|
||||
|
||||
instance : has_add ℕ+ := ⟨pnat.add⟩
|
||||
|
||||
protected def mul : ℕ+ → ℕ+ → ℕ+
|
||||
| ⟨m, m0⟩ ⟨n, n0⟩ := ⟨m * n, mul_pos m0 n0⟩
|
||||
|
||||
instance : has_mul ℕ+ := ⟨pnat.mul⟩
|
||||
|
||||
@[simp] theorem to_pnat'_val {n : ℕ} : n > 0 → n.to_pnat'.val = n := succ_pred_eq_of_pos
|
||||
@[simp] theorem nat_coe_val {n : ℕ} : n > 0 → (n : ℕ+).val = n := succ_pred_eq_of_pos
|
||||
@[simp] theorem to_pnat'_coe {n : ℕ} : n > 0 → (n.to_pnat' : ℕ) = n := succ_pred_eq_of_pos
|
||||
|
||||
end pnat
|
||||
Loading…
Add table
Reference in a new issue