Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.5K Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:

Using ReplaceAll with Dt[ ]?

Posted 3 years ago
Dt[x] /. Dt[h_] :> h (*surprisingly returns Dt[x], not x*)

It seems to work with any other function than Dt.

Log[x] /. Log[h_] :> h (*returns x*)

Also I can do the substitution if I don't use a pattern :

Dt[x] /. Dt[x] -> x (*returns x*)

Ridiculously enough, I can make it work if I replace Dt with a dummy variable first :

Dt[x] //. {Dt -> foo, foo[h_] :> h} (*returns x*)

What am I missing here?

POSTED BY: Lucien Grondin
2 Replies

Makes sense. I feel silly because I should have guessed that. Thanks.

POSTED BY: Lucien Grondin

The problem is that the rule gets evaluated before replacement. To prevent evaluation you can use HoldPattern:

Dt[x] /. HoldPattern[Dt[h_]] :> h
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard