[Maxima] Pattern matching - new user question
nathanielvirgo at gmail.com
Fri Oct 2 07:51:00 CDT 2009
Actually, on second thoughts, my workaround isn't very helpful since it
applies Bayes' rule exactly once to _every_ subexpression of the form (a|b
and c), whereas to simplify a formula you often want to apply it to just one
of them. So I really do need a way to apply the rule exactly once - and
there also needs to be a way to specify which match it should be applied
2009/10/1 Nathaniel Virgo <nathanielvirgo at gmail.com>
> Ah, I see. That trace thing is handy.
> I've found a workaround to make the rule apply only once - I'm not sure how
> sensible it is but it seems to work for now:
> defrule(bayes1, (AA|BB and CC), (BB | _identity(AA and
> defrule(bayes2, _identity(AA), AA);
> apply1(a|b and c, bayes1, bayes2)
> apply1(%, bayes1, bayes2)
> returns the original expression, because the _identity function prevents
> the pattern from being matched twice. I'll continue with this workaround
> and see how far I get.
> 2009/10/1 Robert Dodier <robert.dodier at gmail.com>
>> On Thu, Oct 1, 2009 at 10:24 AM, Nathaniel Virgo
>> <nathanielvirgo at gmail.com> wrote:
>> > If I type exactly what you wrote it works --- but if I remove the '*x'
>> > it doesn't:
>> > (%i6) applyb1( (a|b and c), bayes);
>> > (%o6) ((a | c)*(b | a and c))/b | c
>> > (%i7) applyb1 (%, bayes);
>> > (%o7) ((a | c)*(b | a and c))/b | c
>> OK, in this case it appears (to judge by what's shown by
>> :lisp (trace $bayes) and then redoing the example) that applyb1
>> applies the rule twice, with zero net effect.
>> As before, it seems desirable to cause exactly one application of
>> the rule. I'll have to think about that.
>> Robert Dodier
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Maxima