feat(data/pnat): positive natural numbers

This commit is contained in:
Mario Carneiro 2017-05-28 02:32:10 -04:00
parent d10a799b79
commit 92d76c22a5
2 changed files with 45 additions and 4 deletions

View file

@ -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
View 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