Skip to content

Commit

Permalink
revDeriv for Neg.neg
Browse files Browse the repository at this point in the history
  • Loading branch information
lecopivo committed Nov 27, 2023
1 parent 7b3d9e5 commit 231672c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
51 changes: 48 additions & 3 deletions SciLean/Core/FunctionTransformations/RevDeriv.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,6 @@ theorem HSub.hSub.arg_a0a1.revDerivProj_rule
by
unfold revDerivProjUpdate; unfold revDerivProj
ftrans; simp[revDerivUpdate, neg_pull,revDeriv]
sorry_proof


@[ftrans]
Expand All @@ -1200,5 +1199,51 @@ theorem HSub.hSub.arg_a0a1.revDerivProjUpdate_rule
(ydf.1 - ydg.1, fun i dy dx => ydg.2 i (-dy) (ydf.2 i dy dx)) :=
by
unfold revDerivProjUpdate
ftrans; simp[revDerivProjUpdate]
sorry_proof
ftrans; simp[revDerivProjUpdate, neg_pull, revDerivProj, revDeriv,add_assoc]


-- Neg.neg ---------------------------------------------------------------------
--------------------------------------------------------------------------------

@[ftrans]
theorem Neg.neg.arg_a0.revDeriv_rule
(f : X → Y) (x : X)
: (revDeriv K fun x => - f x) x
=
let ydf := revDeriv K f x
(-ydf.1, fun dy => - ydf.2 dy) :=
by
unfold revDeriv; simp; ftrans; ftrans

@[ftrans]
theorem Neg.neg.arg_a0.revDerivUpdate_rule
(f : X → Y)
: (revDerivUpdate K fun x => - f x)
=
fun x =>
let ydf := revDerivUpdate K f x
(-ydf.1, fun dy dx => ydf.2 (-dy) dx) :=
by
unfold revDerivUpdate; funext x; ftrans; simp[neg_pull,revDeriv]

@[ftrans]
theorem Neg.neg.arg_a0.revDerivProj_rule
(f : X → Y)
: (revDerivProj K fun x => - f x)
=
fun x =>
let ydf := revDerivProj K f x
(-ydf.1, fun i dy => ydf.2 i (-dy)) :=
by
unfold revDerivProj; ftrans; simp[neg_pull,revDeriv]

@[ftrans]
theorem Neg.neg.arg_a0.revDerivProjUpdate_rule
(f : X → Y)
: (revDerivProjUpdate K fun x => - f x)
=
fun x =>
let ydf := revDerivProjUpdate K f x
(-ydf.1, fun i dy dx => ydf.2 i (-dy) dx) :=
by
unfold revDerivProjUpdate; ftrans
5 changes: 5 additions & 0 deletions SciLean/Data/StructLike/Algebra.lean
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SciLean.Core.Objects.SemiInnerProductSpace
import SciLean.Core.Objects.FinVec
import SciLean.Core.Simp
import SciLean.Data.StructLike.Basic

set_option linter.unusedVariables false
Expand All @@ -25,6 +26,10 @@ class VecStruct (K X I XI) [StructLike X I XI] [IsROrC K] [Vec K X] [∀ i, Vec

attribute [simp] VecStruct.proj_add VecStruct.proj_smul VecStruct.proj_zero

@[neg_pull]
theorem oneHot.arg_xi.neg_pull [StructLike X I XI] [DecidableEq I] [∀ i, Vec K (XI i)] [Vec K X] [VecStruct K X I XI] (i : I) (xi : XI i)
: StructLike.oneHot (X:=X) i (- xi) = - StructLike.oneHot (X:=X) i xi := sorry_proof

@[simp]
theorem oneHot_zero [StructLike X I XI] [DecidableEq I] [∀ i, Vec K (XI i)] [Vec K X] [VecStruct K X I XI] (i : I)
: StructLike.oneHot (X:=X) i 0 = (0 : X) := sorry_proof
Expand Down

0 comments on commit 231672c

Please sign in to comment.