Skip to content

Commit

Permalink
fix notation precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
lecopivo committed Jan 3, 2024
1 parent 890d61c commit 67069e2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions SciLean/Core/Notation/CDeriv.lean
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ syntax diffBinderType := " : " term
syntax diffBinderValue := ":=" term (";" term)?
syntax diffBinder := ident (diffBinderType <|> diffBinderValue)?

scoped syntax "∂ " term+ : term
scoped syntax "∂ " term:66 : term
scoped syntax "∂ " diffBinder ", " term:66 : term
scoped syntax "∂ " "(" diffBinder ")" ", " term:66 : term

scoped syntax "∂! " term+ : term
scoped syntax "∂! " term:66 : term
scoped syntax "∂! " diffBinder ", " term:66 : term
scoped syntax "∂! " "(" diffBinder ")" ", " term:66 : term

Expand Down
8 changes: 4 additions & 4 deletions SciLean/Core/Notation/FwdCDeriv.lean
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import SciLean.Core.FunctionTransformations.FwdCDeriv
namespace SciLean.NotationOverField


scoped syntax "∂> " term+ : term
scoped syntax "∂> " term:66 : term
scoped syntax "∂> " diffBinder ", " term:66 : term
scoped syntax "∂> " "(" diffBinder ")" ", " term:66 : term

scoped syntax "∂>! " term+ : term
scoped syntax "∂>! " term:66 : term
scoped syntax "∂>! " diffBinder ", " term:66 : term
scoped syntax "∂>! " "(" diffBinder ")" ", " term:66 : term

open Lean Elab Term Meta in
elab_rules : term
| `(∂> $f $xs*) => do
| `(∂> $f $x $xs*) => do
let K := mkIdent (← currentFieldName.get)
elabTerm (← `(fwdCDeriv $K $f $xs*)) none
elabTerm (← `(fwdCDeriv $K $f $x $xs*)) none

| `(∂> $f) => do
let K := mkIdent (← currentFieldName.get)
Expand Down
4 changes: 2 additions & 2 deletions SciLean/Core/Notation/Gradient.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import SciLean.Core.Notation.CDeriv

namespace SciLean.NotationOverField

scoped syntax (name:=gradNotation1) "∇ " term+ : term
scoped syntax (name:=gradNotation1) "∇ " term:66 : term
scoped syntax "∇ " diffBinder ", " term:66 : term
scoped syntax "∇ " "(" diffBinder ")" ", " term:66 : term

scoped syntax "∇! " term+ : term
scoped syntax "∇! " term:66 : term
scoped syntax "∇! " diffBinder ", " term:66 : term
scoped syntax "∇! " "(" diffBinder ")" ", " term:66 : term

Expand Down
4 changes: 2 additions & 2 deletions SciLean/Core/Notation/RevCDeriv.lean
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import SciLean.Core.FunctionTransformations.RevCDeriv

namespace SciLean.NotationOverField

scoped syntax "<∂ " term+ : term
scoped syntax "<∂ " term:66 : term
scoped syntax "<∂ " diffBinder ", " term:66 : term
scoped syntax "<∂ " "(" diffBinder ")" ", " term:66 : term

scoped syntax "<∂! " term+ : term
scoped syntax "<∂! " term:66 : term
scoped syntax "<∂! " diffBinder ", " term:66 : term
scoped syntax "<∂! " "(" diffBinder ")" ", " term:66 : term

Expand Down
13 changes: 12 additions & 1 deletion test/deriv_notation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ set_default_scalar K
#check ∂ (x:=1), x*x
#check ∂ (x:=0.1), x*x
#check ∂ (x:=((1:K),(2:K))), (x + x)
#check
let df := ∂ (fun x : K×K => (x.1 + x.2*x.1)) (0,0)
df (0,0)


#check ∂! (fun x : K => x^2)
#check ∂! (fun x : K×K => x + x)
#check ∂! (fun x => x*x) 1
#check ∂! (x:=((1:K),(2:K))), (x + x)
#check ∂! (x:=1), x*x


#check ∂ (fun x : K => x*x)
=
(fun x => x + x)

variable {X} [Vec K X] (f : X → X)

#check ∂ (x:=0), f x
Expand Down Expand Up @@ -70,7 +79,9 @@ set_default_scalar K

#check ∂>! x : K×K, (x.1 + x.2*x.1)
#check ∂>! x:=(1:K);2, (x + x*x)

#check
let a := ∂> (fun x : K×K => (x.1 + x.2*x.1))
a (0,0)


--------------------------------------------------------------------------------
Expand Down

0 comments on commit 67069e2

Please sign in to comment.