Skip to content

Commit

Permalink
match on universe
Browse files Browse the repository at this point in the history
  • Loading branch information
YaelDillies committed May 9, 2024
1 parent a7e03d1 commit 392caf3
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions Mathlib/Tactic/Positivity/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -431,29 +431,25 @@ private alias ⟨_, NNRat.num_ne_zero_of_ne_zero⟩ := num_ne_zero
such that `positivity` successfully recognises `q`. -/
@[positivity NNRat.num _]
def evalNNRatNum : PositivityExt where eval {u α} _ _ e := do
if let 0 := u then -- lean4#3060 means we can't combine this with the match below
match α, e with
| ~q(ℕ), ~q(NNRat.num $a) =>
let zα : Q(Zero ℚ≥0) := q(inferInstance)
let pα : Q(PartialOrder ℚ≥0) := q(inferInstance)
assumeInstancesCommute
match ← core zα pα a with
| .positive pa => return .positive q(NNRat.num_pos_of_pos $pa)
| .nonzero pa => return .nonzero q(NNRat.num_ne_zero_of_ne_zero $pa)
| _ => return .none
| _, _ => throwError "not NNRat.num"
else throwError "not NNRat.num"
match u, α, e with
| 0, ~q(ℕ), ~q(NNRat.num $a) =>
let zα : Q(Zero ℚ≥0) := q(inferInstance)
let pα : Q(PartialOrder ℚ≥0) := q(inferInstance)
assumeInstancesCommute
match ← core zα pα a with
| .positive pa => return .positive q(NNRat.num_pos_of_pos $pa)
| .nonzero pa => return .nonzero q(NNRat.num_ne_zero_of_ne_zero $pa)
| _ => return .none
| _, _, _ => throwError "not NNRat.num"

/-- The `positivity` extension which identifies expressions of the form `Rat.den a`. -/
@[positivity NNRat.den _]
def evalNNRatDen : PositivityExt where eval {u α} _ _ e := do
if let 0 := u then -- lean4#3060 means we can't combine this with the match below
match α, e with
| ~q(ℕ), ~q(NNRat.den $a) =>
assumeInstancesCommute
return .positive q(den_pos $a)
| _, _ => throwError "not NNRat.num"
else throwError "not NNRat.num"
match u, α, e with
| 0, ~q(ℕ), ~q(NNRat.den $a) =>
assumeInstancesCommute
return .positive q(den_pos $a)
| _, _, _ => throwError "not NNRat.num"

variable {q : ℚ≥0}

Expand Down

0 comments on commit 392caf3

Please sign in to comment.