-- Mathlib/.lake/packages/lean4/src/lean/Init/Internal/Order/Lemmas.lean
theorem monotone_findSomeRevM?
    (f : γ → α → m (Option β)) (xs : Array α) (hmono : monotone f) :
    monotone (fun x => xs.findSomeRevM? (f x))

Proof state:
case case1
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
i : Nat
x✝¹ x✝ : 0 ≤ xs.size
⊢ monotone fun x => Array.findSomeRevM?.find (f x) xs 0 x✝¹

Tactic:
unfold Array.findSomeRevM?.find

Result:
case case1
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
i : Nat
x✝¹ x✝ : 0 ≤ xs.size
⊢ monotone fun x => pure none

Proof state:
case case2.hmono₂.h
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
i i✝ : Nat
h✝ : i✝ + 1 ≤ xs.size
this✝ : i✝ < xs.size
x✝ : i✝.succ ≤ xs.size
ih : monotone fun x => Array.findSomeRevM?.find (f x) xs i✝ ⋯
y : Option β
⊢ monotone fun x =>
    match y with
    | some val => pure y
    | none =>
      let_fun this := ⋯;
      Array.findSomeRevM?.find (f x) xs i✝ this

Tactic:
cases y with
| none => apply ih
| some y => apply monotone_const

Result:
no goals

Proof state:
case case2.hmono₂.h.some
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
i i✝ : Nat
h✝ : i✝ + 1 ≤ xs.size
this✝ : i✝ < xs.size
x✝ : i✝.succ ≤ xs.size
ih : monotone fun x => Array.findSomeRevM?.find (f x) xs i✝ ⋯
y : β
⊢ monotone fun x =>
    match some y with
    | some val => pure (some y)
    | none =>
      let_fun this := ⋯;
      Array.findSomeRevM?.find (f x) xs i✝ this

Tactic:
apply monotone_const

Result:
no goals

Proof state:
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
this : ∀ (i : Nat) (h : i ≤ xs.size), monotone fun x => Array.findSomeRevM?.find (f x) xs i h
⊢ monotone fun x => Array.findSomeRevM?.find (f x) xs xs.size ⋯

Tactic:
apply this

Result:
no goals

Proof state:
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
⊢ monotone fun x => Array.findSomeRevM?.find (f x) xs xs.size ⋯

Tactic:
suffices ∀ i (h : i ≤ xs.size), monotone (fun x => Array.findSomeRevM?.find (f x) xs i h) by apply this

Result:
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
⊢ ∀ (i : Nat) (h : i ≤ xs.size), monotone fun x => Array.findSomeRevM?.find (f x) xs i h

Proof state:
case case2.hmono₁.h
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
i i✝ : Nat
h✝ : i✝ + 1 ≤ xs.size
this✝ : i✝ < xs.size
x✝ : i✝.succ ≤ xs.size
ih : monotone fun x => Array.findSomeRevM?.find (f x) xs i✝ ⋯
⊢ monotone f

Tactic:
apply hmono

Result:
no goals

Proof state:
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
⊢ monotone fun x => Array.findSomeRevM? (f x) xs

Tactic:
unfold Array.findSomeRevM?

Result:
m : Type u → Type v
inst✝³ : Monad m
inst✝² : (α : Type u) → PartialOrder (m α)
inst✝¹ : MonoBind m
α β : Type u
γ : Type w
inst✝ : PartialOrder γ
f : γ → α → m (Option β)
xs : Array α
hmono : monotone f
⊢ monotone fun x => Array.findSomeRevM?.find (f x) xs xs.size ⋯