Pattern matching - new user question



Hi Robert

Thanks for your helpful comments.  It's odd that using apply1 gives an
infinite loop for you but just fails for me.

However, applyb1 does work for me in this case (I thought I'd already tried
it, but apparently not).  It doesn't work in all cases though.
Specifically, if I try to apply Bayes' rule twice (which should give the
original expression) it doesn't match:

(%i21) expr: bayes(a | b and c);
(%o21) ((a | c)*(b | a and c))/b | c

(%i23) applyb1(expr);
(%o23) ((a | c)*(b | a and c))/b | c

Surely "(b | a and c)" is a subexpression of "((a | c)*(b | a and c))/b |
c", so why doesn't applyb1 find it and apply the rule?

Best regards,
Nathaniel


2009/10/1 Robert Dodier <robert.dodier at gmail.com>

> On 10/1/09, Nathaniel Virgo <nathanielvirgo at gmail.com> wrote:
>
> > (%i6) apply1( (a|b and c)*x, bayes);
> > (%o6) (a | b and c)*x
>
> applyb1 (bottom-up) works for me here instead of apply1 (top-down).
> That's helpful, but not very satisfying; I can see why one
> works and the other doesn't, but it's far from obvious.
>
> best
>
> Robert Dodier
>