Skip to content

Commit

Permalink
feat(tactic/positivity): Extension for int.nat_abs (#16787)
Browse files Browse the repository at this point in the history
Add `positivity_nat_abs`, a positivity extension for `int.nat_abs`.
  • Loading branch information
YaelDillies committed Oct 4, 2022
1 parent 16749fc commit 91df768
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/tactic/positivity.lean
Expand Up @@ -413,6 +413,21 @@ meta def positivity_abs : expr → tactic strictness
nonnegative <$> mk_app ``abs_nonneg [a] -- else report nonnegativity
| _ := failed

private lemma int_nat_abs_pos {n : ℤ} (hn : 0 < n) : 0 < n.nat_abs :=
int.nat_abs_pos_of_ne_zero hn.ne'

/-- Extension for the `positivity` tactic: `int.nat_abs` is positive when its input is.
Since the output type of `int.nat_abs` is `ℕ`, the nonnegative case is handled by the default
`positivity` tactic.
-/
@[positivity]
meta def positivity_nat_abs : expr → tactic strictness
| `(int.nat_abs %%a) := do
positive p ← core a,
positive <$> mk_app ``int_nat_abs_pos [p]
| _ := failed

private lemma nat_cast_pos [ordered_semiring α] [nontrivial α] {n : ℕ} : 0 < n → 0 < (n : α) :=
nat.cast_pos.2

Expand Down
2 changes: 2 additions & 0 deletions test/positivity.lean
Expand Up @@ -105,6 +105,8 @@ example {a : ℤ} : 0 ≤ |a| := by positivity

example {a : ℤ} : 0 < |a| + 3 := by positivity

example {n : ℤ} (hn : 0 < n) : 0 < n.nat_abs := by positivity

example {a : ℤ} (ha : 1 < a) : 0 < |(3:ℤ) + a| := by positivity

example {a : ℝ} (ha : 0 ≤ a) : 0 ≤ real.sqrt a := by positivity
Expand Down

0 comments on commit 91df768

Please sign in to comment.