lean4-htt/library/data/pnat.lean
2017-05-28 02:32:23 -04:00

44 lines
1.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
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