I have been trying to understand how mathematica does pattern matching:
{Sin[x] + 1} /. Sin -> Cos
returns
Cos[x] + 1
I am guessing that the program searches for the expression in the expression tree and then replaces the pattern once it finds it.
Thanks
ReplaceAll: ReplaceAll looks at each part of expr, tries all the rules on it, and then goes on to the next part of expr. The first rule that applies to a particular part is used; no further rules are tried on that part or on any of its subparts. – vapor Mar 21 '17 at 17:17look at each part of the expresisondoes it traverse down the expression tree or it has some other mechanism? – Arihant Parsoya Mar 21 '17 at 17:32Replace,Cases, etc. ForReplaceAllit is actually BFS. – Leonid Shifrin Mar 21 '17 at 17:52ReplaceAllis not a BFS but rather a depth-first preorder traversal? – Mr.Wizard Mar 21 '17 at 18:28