Timeline for Why does Replace function not work the first time I try it?
Current License: CC BY-SA 4.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 16 at 9:44 | answer | added | Sjoerd Smit | timeline score: 4 | |
Jul 16 at 8:35 | history | edited | Prem | CC BY-SA 4.0 |
Added more notes
|
Jul 16 at 8:30 | history | edited | Prem | CC BY-SA 4.0 |
Added more notes
|
Jul 16 at 8:21 | comment | added | Prem | @BobHanlon You are right. I forgot to mention in the question the ReplaceRepeated works. | |
Jul 16 at 8:18 | comment | added | Prem | @creidhne Do you mean that Replace will only work once for one of the rule that is found to apply? I tested this using following code 1 + x + y /. {x -> x1, y -> y1}. The result is 1 + x1 + y1. Both the replacements happened here without any problem. | |
Jul 15 at 18:12 | answer | added | Roland F | timeline score: 2 | |
Jul 15 at 16:46 | history | edited | creidhne |
The bugs tag is reserved for questions where the problem has been vetted by this community and the observed behavior is confirmed to be a bug. Please do not use this tag for new questions
|
|
Jul 15 at 16:43 | comment | added | creidhne |
These results are not a bug. Replace documentation explains that when a list of rules is given, the result with the first rule that applies is returned. Your expected result is given by Replace Repeated , which repeatedly performs replacements until the expression no longer changes.
|
|
Jul 15 at 16:06 | history | edited | user64494 | CC BY-SA 4.0 |
edited title
|
Jul 15 at 15:17 | comment | added | edinorog2196 |
A workaround is to replace g[x] -> x D[g[x]/x, x] . In my experience it is better to just substitute a single thing rather than an expression g[x]/x which could not be found in the code (you have (Cos[x]g[x])/x )
|
|
Jul 15 at 14:39 | comment | added | AsukaMinato |
1/x // FullForm gives Power[x,-1]
|
|
Jul 15 at 14:38 | comment | added | Bob Hanlon |
I don't know why it doesn't work, but you can use ReplaceRepeated (//. ) instead of ReplaceAll (/. )
|
|
S Jul 15 at 14:20 | review | First questions | |||
Jul 15 at 15:00 | |||||
S Jul 15 at 14:20 | history | asked | Prem | CC BY-SA 4.0 |