1
$\begingroup$

How do you decorate or annotate a variable in a replacement rule?

For example

{(e[(-X + Y)^2 || f])} //. {e[(-a_ + b_)^2 || f] -> (-a + b)^2}

Would ideally return:

(-lagXdt + lagYdt)^2

Update: The following does not return lagXdt and lagYdt but rather lagadt and lagbdt:

{(e[(-X + Y)^2 || f])} //. {e[(-a_ + b_)^2 || 
     f] -> (-Symbol["lag" <> ToString@a <> "dt"] + 
      Symbol["lag" <> ToString@b <> "dt"])^2}
$\endgroup$
2
  • 1
    $\begingroup$ Your code sample is ... quite wrong. You should balance your parentheses and check what the // was supposed to be. $\endgroup$
    – MarcoB
    Dec 12, 2019 at 22:18
  • $\begingroup$ Thanks @MarcoB. Now fixed. $\endgroup$
    – Hedgehog
    Dec 12, 2019 at 22:51

1 Answer 1

2
$\begingroup$

Got it eventually, the key was to use :> instead of ->:

{(e[(-X + Y)^2 || f])} //. {e[(-a_ + b_)^2 || f] :> (-Symbol["lag" <> ToString@a <> "dt"] + Symbol["lag" <> ToString@b <> "dt"])^2}

{(-lagXdt + lagYdt)^2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.