Theorem: Array.SatisfiesM_foldrM
File: .lake/packages/batteries/Batteries/Data/Array/Monadic.lean

tactic: simp [foldrM]
state_before: m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
⊢ SatisfiesM (motive 0) (foldrM f init as as.size)
state_after: m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
⊢ SatisfiesM (motive 0) (if 0 < as.size then foldrM.fold f as 0 as.size ⋯ init else pure init)

tactic: split
state_before: m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
⊢ SatisfiesM (motive 0) (if 0 < as.size then foldrM.fold f as 0 as.size ⋯ init else pure init)
state_after: case isTrue
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
h✝ : 0 < as.size
⊢ SatisfiesM (motive 0) (foldrM.fold f as 0 as.size ⋯ init)

case isFalse
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
h✝ : ¬0 < as.size
⊢ SatisfiesM (motive 0) (pure init)

tactic: {exact go _ h0}
state_before: case isTrue
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
h✝ : 0 < as.size
⊢ SatisfiesM (motive 0) (foldrM.fold f as 0 as.size ⋯ init)

case isFalse
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
h✝ : ¬0 < as.size
⊢ SatisfiesM (motive 0) (pure init)
state_after: case isFalse
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
h✝ : ¬0 < as.size
⊢ SatisfiesM (motive 0) (pure init)

tactic: unfold foldrM.fold
state_before: m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
i : Nat
b : β
hi : i ≤ as.size
H : motive i b
⊢ SatisfiesM (motive 0) (foldrM.fold f as 0 i hi b)
state_after: m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
i : Nat
b : β
hi : i ≤ as.size
H : motive i b
⊢ SatisfiesM (motive 0)
    (if (i == 0) = true then pure b
    else
      match i, hi with
      | 0, x => pure b
      | i.succ, h =>
        let_fun this := ⋯;
        do
        let __do_lift ← f as[i] b
        foldrM.fold f as 0 i ⋯ __do_lift)

tactic: simp
state_before: m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
i : Nat
b : β
hi : i ≤ as.size
H : motive i b
⊢ SatisfiesM (motive 0)
    (if (i == 0) = true then pure b
    else
      match i, hi with
      | 0, x => pure b
      | i.succ, h =>
        let_fun this := ⋯;
        do
        let __do_lift ← f as[i] b
        foldrM.fold f as 0 i ⋯ __do_lift)
state_after: m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
i : Nat
b : β
hi : i ≤ as.size
H : motive i b
⊢ SatisfiesM (motive 0)
    (if i = 0 then pure b
    else
      match i, hi with
      | 0, x => pure b
      | i.succ, h => do
        let __do_lift ← f as[i] b
        foldrM.fold f as 0 i ⋯ __do_lift)

tactic: split
state_before: m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
i : Nat
b : β
hi : i ≤ as.size
H : motive i b
⊢ SatisfiesM (motive 0)
    (if i = 0 then pure b
    else
      match i, hi with
      | 0, x => pure b
      | i.succ, h => do
        let __do_lift ← f as[i] b
        foldrM.fold f as 0 i ⋯ __do_lift)
state_after: case isTrue
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
i : Nat
b : β
hi : i ≤ as.size
H : motive i b
h✝ : i = 0
⊢ SatisfiesM (motive 0) (pure b)

case isFalse
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
i : Nat
b : β
hi : i ≤ as.size
H : motive i b
h✝ : ¬i = 0
⊢ SatisfiesM (motive 0)
    (match i, hi with
    | 0, x => pure b
    | i.succ, h => do
      let __do_lift ← f as[i] b
      foldrM.fold f as 0 i ⋯ __do_lift)

tactic: next hi => exact .pure (hi ▸ H)
state_before: case isTrue
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
i : Nat
b : β
hi : i ≤ as.size
H : motive i b
h✝ : i = 0
⊢ SatisfiesM (motive 0) (pure b)
state_after: no goals

tactic: exact .pure (hi ▸ H)
state_before: m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
i : Nat
b : β
hi✝ : i ≤ as.size
H : motive i b
hi : i = 0
⊢ SatisfiesM (motive 0) (pure b)
state_after: no goals

tactic: split
state_before: m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
i : Nat
b : β
hi✝ : i ≤ as.size
H : motive i b
hi : ¬i = 0
⊢ SatisfiesM (motive 0)
    (match i, hi✝ with
    | 0, x => pure b
    | i.succ, h => do
      let __do_lift ← f as[i] b
      foldrM.fold f as 0 i ⋯ __do_lift)
state_after: case h_1
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
b : β
i✝ : Nat
h✝ : i✝ ≤ as.size
x✝ : 0 ≤ as.size
H : motive 0 b
hi : ¬0 = 0
⊢ SatisfiesM (motive 0) (pure b)

case h_2
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
b : β
i✝¹ : Nat
h✝¹ : i✝¹ ≤ as.size
i✝ : Nat
h✝ : i✝ + 1 ≤ as.size
H : motive i✝.succ b
hi : ¬i✝.succ = 0
⊢ SatisfiesM (motive 0) do
    let __do_lift ← f as[i✝] b
    foldrM.fold f as 0 i✝ ⋯ __do_lift

tactic: {simp at hi}
state_before: case h_1
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
b : β
i✝ : Nat
h✝ : i✝ ≤ as.size
x✝ : 0 ≤ as.size
H : motive 0 b
hi : ¬0 = 0
⊢ SatisfiesM (motive 0) (pure b)

case h_2
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
b : β
i✝¹ : Nat
h✝¹ : i✝¹ ≤ as.size
i✝ : Nat
h✝ : i✝ + 1 ≤ as.size
H : motive i✝.succ b
hi : ¬i✝.succ = 0
⊢ SatisfiesM (motive 0) do
    let __do_lift ← f as[i✝] b
    foldrM.fold f as 0 i✝ ⋯ __do_lift
state_after: case h_2
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
b : β
i✝¹ : Nat
h✝¹ : i✝¹ ≤ as.size
i✝ : Nat
h✝ : i✝ + 1 ≤ as.size
H : motive i✝.succ b
hi : ¬i✝.succ = 0
⊢ SatisfiesM (motive 0) do
    let __do_lift ← f as[i✝] b
    foldrM.fold f as 0 i✝ ⋯ __do_lift

tactic: simp at hi
state_before: case h_1
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
b : β
i✝ : Nat
h✝ : i✝ ≤ as.size
x✝ : 0 ≤ as.size
H : motive 0 b
hi : ¬0 = 0
⊢ SatisfiesM (motive 0) (pure b)
state_after: no goals

tactic: next i hi' =>
exact (hf ⟨i, hi'⟩ b H).bind fun _ => go _
state_before: case h_2
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
b : β
i✝¹ : Nat
h✝¹ : i✝¹ ≤ as.size
i✝ : Nat
h✝ : i✝ + 1 ≤ as.size
H : motive i✝.succ b
hi : ¬i✝.succ = 0
⊢ SatisfiesM (motive 0) do
    let __do_lift ← f as[i✝] b
    foldrM.fold f as 0 i✝ ⋯ __do_lift
state_after: no goals

tactic: exact (hf ⟨i, hi'⟩ b H).bind fun _ => go _
state_before: m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
b : β
i✝ : Nat
h✝ : i✝ ≤ as.size
i : Nat
hi' : i + 1 ≤ as.size
H : motive i.succ b
hi : ¬i.succ = 0
⊢ SatisfiesM (motive 0) do
    let __do_lift ← f as[i] b
    foldrM.fold f as 0 i ⋯ __do_lift
state_after: no goals

tactic: exact go _ h0
state_before: case isTrue
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
h✝ : 0 < as.size
⊢ SatisfiesM (motive 0) (foldrM.fold f as 0 as.size ⋯ init)
state_after: no goals

tactic: next h => exact .pure (Nat.eq_zero_of_not_pos h ▸ h0)
state_before: case isFalse
m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
h✝ : ¬0 < as.size
⊢ SatisfiesM (motive 0) (pure init)
state_after: no goals

tactic: exact .pure (Nat.eq_zero_of_not_pos h ▸ h0)
state_before: m : Type u_1 → Type u_2
α : Type u_3
β : Type u_1
inst✝¹ : Monad m
inst✝ : LawfulMonad m
as : Array α
motive : Nat → β → Prop
init : β
h0 : motive as.size init
f : α → β → m β
hf : ∀ (i : Fin as.size) (b : β), motive (↑i + 1) b → SatisfiesM (motive ↑i) (f as[i] b)
h : ¬0 < as.size
⊢ SatisfiesM (motive 0) (pure init)
state_after: no goals