Read Online
Download PDF
Additional resources
Revision history
Known typos/bugs
Report a bug
License terms
About the author
"node87_1.gif" "node87_2.gif" "node87_3.gif"

1.2.8        Automatic rule reordering

What is less trivial is that in this example we would get similar behavior even if we defined this rule first:



To see the order in which the rules are kept, we again use DownValues :



We see that the rule with Sine again is at the end, despite having been defined first. The reason is that Mathematica pattern-matching engine has a built-in rule analyzer which sorts the rules such that more general rules come after more specific ones, when it can determine it. This is not always possible to do automatically (and not always possible to unambiguously do at all), so in general the programmer should take care of it. But in practice, it is seldom  needed to manipulate the  rules by hand.

"node87_8.gif" "node87_9.gif" "node87_10.gif"

Created by Wolfram Mathematica 6.0  (05 February 2009) Valid XHTML 1.1!