Theorem: modify.arg_f.revDerivM_rule (SciLean/Core/Monads/StateT.lean)

State before:
K : Type
inst✝⁹ : RCLike K
m : Type → Type
m' : outParam (Type → Type)
inst✝⁸ : Monad m
inst✝⁷ : Monad m'
inst✝⁶ : RevDerivMonad K m m'
inst✝⁵ : LawfulMonad m
inst✝⁴ : LawfulMonad m'
S : Type
inst✝³ : SemiInnerProductSpace K S
X : Type
inst✝² : SemiInnerProductSpace K X
Y : Type ?u.264984
inst✝¹ : SemiInnerProductSpace K Y
Z : Type ?u.264995
inst✝ : SemiInnerProductSpace K Z
f : X → S → S
ha0 : HasAdjDiff K fun xs => f xs.1 xs.2
⊢ (revDerivM K fun x => modify (f x)) = fun x => do
    let __do_lift ← get
    let sdf : S × (S → X × S) := revDeriv K (fun xs => f xs.1 xs.2) (x, __do_lift)
    set sdf.1
    pure
        ((), fun x => do
          let __do_lift ← get
          let dxs : X × S := sdf.2 __do_lift
          set dxs.2
          pure dxs.1)
Tactic:
funext
State after:
case h.h
K : Type
inst✝⁹ : RCLike K
m : Type → Type
m' : outParam (Type → Type)
inst✝⁸ : Monad m
inst✝⁷ : Monad m'
inst✝⁶ : RevDerivMonad K m m'
inst✝⁵ : LawfulMonad m
inst✝⁴ : LawfulMonad m'
S : Type
inst✝³ : SemiInnerProductSpace K S
X : Type
inst✝² : SemiInnerProductSpace K X
Y : Type ?u.264984
inst✝¹ : SemiInnerProductSpace K Y
Z : Type ?u.264995
inst✝ : SemiInnerProductSpace K Z
f : X → S → S
ha0 : HasAdjDiff K fun xs => f xs.1 xs.2
x✝¹ : X
x✝ : S
⊢ revDerivM K (fun x => modify (f x)) x✝¹ x✝ =
    (get >>= fun __do_lift =>
        let sdf := revDeriv K (fun xs => f xs.1 xs.2) (x✝¹, __do_lift);
        do
        set sdf.1
        pure
            ((), fun x => do
              let __do_lift ← get
              let dxs : X × S := sdf.2 __do_lift
              set dxs.2
              pure dxs.1))
      x✝

State before:
case h.h
K : Type
inst✝⁹ : RCLike K
m : Type → Type
m' : outParam (Type → Type)
inst✝⁸ : Monad m
inst✝⁷ : Monad m'
inst✝⁶ : RevDerivMonad K m m'
inst✝⁵ : LawfulMonad m
inst✝⁴ : LawfulMonad m'
S : Type
inst✝³ : SemiInnerProductSpace K S
X : Type
inst✝² : SemiInnerProductSpace K X
Y : Type ?u.264984
inst✝¹ : SemiInnerProductSpace K Y
Z : Type ?u.264995
inst✝ : SemiInnerProductSpace K Z
f : X → S → S
ha0 : HasAdjDiff K fun xs => f xs.1 xs.2
x✝¹ : X
x✝ : S
⊢ revDerivM K (fun x => modify (f x)) x✝¹ x✝ =
    (get >>= fun __do_lift =>
        let sdf := revDeriv K (fun xs => f xs.1 xs.2) (x✝¹, __do_lift);
        do
        set sdf.1
        pure
            ((), fun x => do
              let __do_lift ← get
              let dxs : X × S := sdf.2 __do_lift
              set dxs.2
              pure dxs.1))
      x✝
Tactic:
simp[modifyThe, modifyGet, MonadStateOf.modifyGet, StateT.modifyGet,revDerivM, bind, StateT.bind, getThe, MonadStateOf.get, StateT.get, set, StateT.set, get, pure, StateT.pure, modify]
State after:
case h.h
K : Type
inst✝⁹ : RCLike K
m : Type → Type
m' : outParam (Type → Type)
inst✝⁸ : Monad m
inst✝⁷ : Monad m'
inst✝⁶ : RevDerivMonad K m m'
inst✝⁵ : LawfulMonad m
inst✝⁴ : LawfulMonad m'
S : Type
inst✝³ : SemiInnerProductSpace K S
X : Type
inst✝² : SemiInnerProductSpace K X
Y : Type ?u.264984
inst✝¹ : SemiInnerProductSpace K Y
Z : Type ?u.264995
inst✝ : SemiInnerProductSpace K Z
f : X → S → S
ha0 : HasAdjDiff K fun xs => f xs.1 xs.2
x✝¹ : X
x✝ : S
⊢ (do
      let ysdf ← revDerivM K (fun xs => pure (PUnit.unit, f xs.1 xs.2)) (x✝¹, x✝)
      pure ((ysdf.1.1, fun dx ds => ysdf.2 (dx, ds)), ysdf.1.2)) =
    pure
      (((), fun x =>
          StateT.bind StateT.get fun __do_lift =>
            StateT.bind (StateT.set ((revDeriv K (fun xs => f xs.1 xs.2) (x✝¹, x✝)).2 __do_lift).2) fun x =>
              StateT.pure ((revDeriv K (fun xs => f xs.1 xs.2) (x✝¹, x✝)).2 __do_lift).1),
        f x✝¹ x✝)

State before:
case h.h
K : Type
inst✝⁹ : RCLike K
m : Type → Type
m' : outParam (Type → Type)
inst✝⁸ : Monad m
inst✝⁷ : Monad m'
inst✝⁶ : RevDerivMonad K m m'
inst✝⁵ : LawfulMonad m
inst✝⁴ : LawfulMonad m'
S : Type
inst✝³ : SemiInnerProductSpace K S
X : Type
inst✝² : SemiInnerProductSpace K X
Y : Type ?u.264984
inst✝¹ : SemiInnerProductSpace K Y
Z : Type ?u.264995
inst✝ : SemiInnerProductSpace K Z
f : X → S → S
ha0 : HasAdjDiff K fun xs => f xs.1 xs.2
x✝¹ : X
x✝ : S
⊢ (do
      let ysdf ← revDerivM K (fun xs => pure (PUnit.unit, f xs.1 xs.2)) (x✝¹, x✝)
      pure ((ysdf.1.1, fun dx ds => ysdf.2 (dx, ds)), ysdf.1.2)) =
    pure
      (((), fun x =>
          StateT.bind StateT.get fun __do_lift =>
            StateT.bind (StateT.set ((revDeriv K (fun xs => f xs.1 xs.2) (x✝¹, x✝)).2 __do_lift).2) fun x =>
              StateT.pure ((revDeriv K (fun xs => f xs.1 xs.2) (x✝¹, x✝)).2 __do_lift).1),
        f x✝¹ x✝)
Tactic:
fun_trans
State after:
case h.h
K : Type
inst✝⁹ : RCLike K
m : Type → Type
m' : outParam (Type → Type)
inst✝⁸ : Monad m
inst✝⁷ : Monad m'
inst✝⁶ : RevDerivMonad K m m'
inst✝⁵ : LawfulMonad m
inst✝⁴ : LawfulMonad m'
S : Type
inst✝³ : SemiInnerProductSpace K S
X : Type
inst✝² : SemiInnerProductSpace K X
Y : Type ?u.264984
inst✝¹ : SemiInnerProductSpace K Y
Z : Type ?u.264995
inst✝ : SemiInnerProductSpace K Z
f : X → S → S
ha0 : HasAdjDiff K fun xs => f xs.1 xs.2
x✝¹ : X
x✝ : S
⊢ pure ((PUnit.unit, fun dx ds => pure ((revDeriv K (fun x => f x.1 x.2) (x✝¹, x✝)).2 ds)), f x✝¹ x✝) =
    pure
      (((), fun x =>
          StateT.bind StateT.get fun __do_lift =>
            StateT.bind (StateT.set ((revDeriv K (fun x => f x.1 x.2) (x✝¹, x✝)).2 __do_lift).2) fun x =>
              StateT.pure ((revDeriv K (fun x => f x.1 x.2) (x✝¹, x✝)).2 __do_lift).1),
        f x✝¹ x✝)

State before:
case h.h
K : Type
inst✝⁹ : RCLike K
m : Type → Type
m' : outParam (Type → Type)
inst✝⁸ : Monad m
inst✝⁷ : Monad m'
inst✝⁶ : RevDerivMonad K m m'
inst✝⁵ : LawfulMonad m
inst✝⁴ : LawfulMonad m'
S : Type
inst✝³ : SemiInnerProductSpace K S
X : Type
inst✝² : SemiInnerProductSpace K X
Y : Type ?u.264984
inst✝¹ : SemiInnerProductSpace K Y
Z : Type ?u.264995
inst✝ : SemiInnerProductSpace K Z
f : X → S → S
ha0 : HasAdjDiff K fun xs => f xs.1 xs.2
x✝¹ : X
x✝ : S
⊢ pure ((PUnit.unit, fun dx ds => pure ((revDeriv K (fun x => f x.1 x.2) (x✝¹, x✝)).2 ds)), f x✝¹ x✝) =
    pure
      (((), fun x =>
          StateT.bind StateT.get fun __do_lift =>
            StateT.bind (StateT.set ((revDeriv K (fun x => f x.1 x.2) (x✝¹, x✝)).2 __do_lift).2) fun x =>
              StateT.pure ((revDeriv K (fun x => f x.1 x.2) (x✝¹, x✝)).2 __do_lift).1),
        f x✝¹ x✝)
Tactic:
congr
State after:
case h.h.e_a.e_fst.e_snd
K : Type
inst✝⁹ : RCLike K
m : Type → Type
m' : outParam (Type → Type)
inst✝⁸ : Monad m
inst✝⁷ : Monad m'
inst✝⁶ : RevDerivMonad K m m'
inst✝⁵ : LawfulMonad m
inst✝⁴ : LawfulMonad m'
S : Type
inst✝³ : SemiInnerProductSpace K S
X : Type
inst✝² : SemiInnerProductSpace K X
Y : Type ?u.264984
inst✝¹ : SemiInnerProductSpace K Y
Z : Type ?u.264995
inst✝ : SemiInnerProductSpace K Z
f : X → S → S
ha0 : HasAdjDiff K fun xs => f xs.1 xs.2
x✝¹ : X
x✝ : S
⊢ (fun dx ds => pure ((revDeriv K (fun x => f x.1 x.2) (x✝¹, x✝)).2 ds)) = fun x =>
    StateT.bind StateT.get fun __do_lift =>
      StateT.bind (StateT.set ((revDeriv K (fun x => f x.1 x.2) (x✝¹, x✝)).2 __do_lift).2) fun x =>
        StateT.pure ((revDeriv K (fun x => f x.1 x.2) (x✝¹, x✝)).2 __do_lift).1

State before:
case h.h.e_a.e_fst.e_snd
K : Type
inst✝⁹ : RCLike K
m : Type → Type
m' : outParam (Type → Type)
inst✝⁸ : Monad m
inst✝⁷ : Monad m'
inst✝⁶ : RevDerivMonad K m m'
inst✝⁵ : LawfulMonad m
inst✝⁴ : LawfulMonad m'
S : Type
inst✝³ : SemiInnerProductSpace K S
X : Type
inst✝² : SemiInnerProductSpace K X
Y : Type ?u.264984
inst✝¹ : SemiInnerProductSpace K Y
Z : Type ?u.264995
inst✝ : SemiInnerProductSpace K Z
f : X → S → S
ha0 : HasAdjDiff K fun xs => f xs.1 xs.2
x✝¹ : X
x✝ : S
⊢ (fun dx ds => pure ((revDeriv K (fun x => f x.1 x.2) (x✝¹, x✝)).2 ds)) = fun x =>
    StateT.bind StateT.get fun __do_lift =>
      StateT.bind (StateT.set ((revDeriv K (fun x => f x.1 x.2) (x✝¹, x✝)).2 __do_lift).2) fun x =>
        StateT.pure ((revDeriv K (fun x => f x.1 x.2) (x✝¹, x✝)).2 __do_lift).1
Tactic:
funext
State after:
case h.h.e_a.e_fst.e_snd.h.h
K : Type
inst✝⁹ : RCLike K
m : Type → Type
m' : outParam (Type → Type)
inst✝⁸ : Monad m
inst✝⁷ : Monad m'
inst✝⁶ : RevDerivMonad K m m'
inst✝⁵ : LawfulMonad m
inst✝⁴ : LawfulMonad m'
S : Type
inst✝³ : SemiInnerProductSpace K S
X : Type
inst✝² : SemiInnerProductSpace K X
Y : Type ?u.264984
inst✝¹ : SemiInnerProductSpace K Y
Z : Type ?u.264995
inst✝ : SemiInnerProductSpace K Z
f : X → S → S
ha0 : HasAdjDiff K fun xs => f xs.1 xs.2
x✝³ : X
x✝² : S
x✝¹ : PUnit.{1}
x✝ : S
⊢ pure ((revDeriv K (fun x => f x.1 x.2) (x✝³, x✝²)).2 x✝) =
    StateT.bind StateT.get
      (fun __do_lift =>
        StateT.bind (StateT.set ((revDeriv K (fun x => f x.1 x.2) (x✝³, x✝²)).2 __do_lift).2) fun x =>
          StateT.pure ((revDeriv K (fun x => f x.1 x.2) (x✝³, x✝²)).2 __do_lift).1)
      x✝

State before:
case h.h.e_a.e_fst.e_snd.h.h
K : Type
inst✝⁹ : RCLike K
m : Type → Type
m' : outParam (Type → Type)
inst✝⁸ : Monad m
inst✝⁷ : Monad m'
inst✝⁶ : RevDerivMonad K m m'
inst✝⁵ : LawfulMonad m
inst✝⁴ : LawfulMonad m'
S : Type
inst✝³ : SemiInnerProductSpace K S
X : Type
inst✝² : SemiInnerProductSpace K X
Y : Type ?u.264984
inst✝¹ : SemiInnerProductSpace K Y
Z : Type ?u.264995
inst✝ : SemiInnerProductSpace K Z
f : X → S → S
ha0 : HasAdjDiff K fun xs => f xs.1 xs.2
x✝³ : X
x✝² : S
x✝¹ : PUnit.{1}
x✝ : S
⊢ pure ((revDeriv K (fun x => f x.1 x.2) (x✝³, x✝²)).2 x✝) =
    StateT.bind StateT.get
      (fun __do_lift =>
        StateT.bind (StateT.set ((revDeriv K (fun x => f x.1 x.2) (x✝³, x✝²)).2 __do_lift).2) fun x =>
          StateT.pure ((revDeriv K (fun x => f x.1 x.2) (x✝³, x✝²)).2 __do_lift).1)
      x✝
Tactic:
simp[StateT.bind,StateT.pure,StateT.get,StateT.set]
State after:
no goals