-- Mathlib/.lake/packages/lean4/src/lean/Init/Internal/Order/Lemmas.lean
theorem monotone_findIdxM?
    {m : Type → Type v} [Monad m] [∀ α, PartialOrder (m α)] [MonoBind m] {α : Type u}
    (f : γ → α → m Bool) (xs : Array α) (hmono : monotone f) :
    monotone (fun x => xs.findIdxM? (f x))

Proof state:
case hmono₁.hmono
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type v
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type u
f : γ → α → m Bool
xs : Array α
hmono : monotone f
⊢ monotone fun x a r =>
    let r := r.snd;
    let i := r;
    do
    let __do_lift ← f x a
    let __do_jp : Nat → PUnit → m (ForInStep (MProd (Option (Option Nat)) Nat)) := fun i y =>
      let i := i + 1;
      do
      pure PUnit.unit
      pure (ForInStep.yield ⟨none, i⟩)
    if __do_lift = true then pure (ForInStep.done ⟨some (some i), i⟩)
      else do
        let y ← pure PUnit.unit
        __do_jp i y

Tactic:
apply monotone_of_monotone_apply

Result:
case hmono₁.hmono.h
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type v
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type u
f : γ → α → m Bool
xs : Array α
hmono : monotone f
⊢ ∀ (y : α),
    monotone fun x r =>
      let r := r.snd;
      let i := r;
      do
      let __do_lift ← f x y
      let __do_jp : Nat → PUnit → m (ForInStep (MProd (Option (Option Nat)) Nat)) := fun i y =>
        let i := i + 1;
        do
        pure PUnit.unit
        pure (ForInStep.yield ⟨none, i⟩)
      if __do_lift = true then pure (ForInStep.done ⟨some (some i), i⟩)
        else do
          let y ← pure PUnit.unit
          __do_jp i y

Proof state:
case hmono₁
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type v
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type u
f : γ → α → m Bool
xs : Array α
hmono : monotone f
⊢ monotone fun x =>
    forIn xs ⟨none, 0⟩ fun a r =>
      let r := r.snd;
      let i := r;
      do
      let __do_lift ← f x a
      let __do_jp : Nat → PUnit → m (ForInStep (MProd (Option (Option Nat)) Nat)) := fun i y =>
        let i := i + 1;
        do
        pure PUnit.unit
        pure (ForInStep.yield ⟨none, i⟩)
      if __do_lift = true then pure (ForInStep.done ⟨some (some i), i⟩)
        else do
          let y ← pure PUnit.unit
          __do_jp i y

Tactic:
apply monotone_forIn

Result:
case hmono₁.hmono
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type v
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type u
f : γ → α → m Bool
xs : Array α
hmono : monotone f
⊢ monotone fun x a r =>
    let r := r.snd;
    let i := r;
    do
    let __do_lift ← f x a
    let __do_jp : Nat → PUnit → m (ForInStep (MProd (Option (Option Nat)) Nat)) := fun i y =>
      let i := i + 1;
      do
      pure PUnit.unit
      pure (ForInStep.yield ⟨none, i⟩)
    if __do_lift = true then pure (ForInStep.done ⟨some (some i), i⟩)
      else do
        let y ← pure PUnit.unit
        __do_jp i y

Proof state:
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type v
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type u
f : γ → α → m Bool
xs : Array α
hmono : monotone f
⊢ monotone fun x =>
    let i := 0;
    do
    let r ←
      forIn xs ⟨none, i⟩ fun a r =>
          let r := r.snd;
          let i := r;
          do
          let __do_lift ← f x a
          let __do_jp : Nat → PUnit → m (ForInStep (MProd (Option (Option Nat)) Nat)) := fun i y =>
            let i := i + 1;
            do
            pure PUnit.unit
            pure (ForInStep.yield ⟨none, i⟩)
          if __do_lift = true then pure (ForInStep.done ⟨some (some i), i⟩)
            else do
              let y ← pure PUnit.unit
              __do_jp i y
    let i : Nat := r.snd
    let __do_jp : PUnit → m (Option Nat) := fun y => pure none
    match r.fst with
      | none => do
        let y ← pure PUnit.unit
        __do_jp y
      | some a => pure a

Tactic:
apply monotone_bind

Result:
case hmono₁
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type v
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type u
f : γ → α → m Bool
xs : Array α
hmono : monotone f
⊢ monotone fun x =>
    forIn xs ⟨none, 0⟩ fun a r =>
      let r := r.snd;
      let i := r;
      do
      let __do_lift ← f x a
      let __do_jp : Nat → PUnit → m (ForInStep (MProd (Option (Option Nat)) Nat)) := fun i y =>
        let i := i + 1;
        do
        pure PUnit.unit
        pure (ForInStep.yield ⟨none, i⟩)
      if __do_lift = true then pure (ForInStep.done ⟨some (some i), i⟩)
        else do
          let y ← pure PUnit.unit
          __do_jp i y

case hmono₂
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type v
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type u
f : γ → α → m Bool
xs : Array α
hmono : monotone f
⊢ monotone fun x r =>
    let i := r.snd;
    let __do_jp := fun y => pure none;
    match r.fst with
    | none => do
      let y ← pure PUnit.unit
      __do_jp y
    | some a => pure a

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

Tactic:
unfold Array.findIdxM?

Result:
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type v
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type u
f : γ → α → m Bool
xs : Array α
hmono : monotone f
⊢ monotone fun x =>
    let i := 0;
    do
    let r ←
      forIn xs ⟨none, i⟩ fun a r =>
          let r := r.snd;
          let i := r;
          do
          let __do_lift ← f x a
          let __do_jp : Nat → PUnit → m (ForInStep (MProd (Option (Option Nat)) Nat)) := fun i y =>
            let i := i + 1;
            do
            pure PUnit.unit
            pure (ForInStep.yield ⟨none, i⟩)
          if __do_lift = true then pure (ForInStep.done ⟨some (some i), i⟩)
            else do
              let y ← pure PUnit.unit
              __do_jp i y
    let i : Nat := r.snd
    let __do_jp : PUnit → m (Option Nat) := fun y => pure none
    match r.fst with
      | none => do
        let y ← pure PUnit.unit
        __do_jp y
      | some a => pure a

Proof state:
case hmono₂
γ : Type w
inst✝³ : PartialOrder γ
m : Type → Type v
inst✝² : Monad m
inst✝¹ : (α : Type) → PartialOrder (m α)
inst✝ : MonoBind m
α : Type u
f : γ → α → m Bool
xs : Array α
hmono : monotone f
⊢ monotone fun x r =>
    let i := r.snd;
    let __do_jp := fun y => pure none;
    match r.fst with
    | none => do
      let y ← pure PUnit.unit
      __do_jp y
    | some a => pure a

Tactic:
apply monotone_const

Result:
no goals