# [Maxima] Rules and patterns for dummies??

Julien Martin balteo at gmail.com
Mon Nov 2 06:48:12 CST 2009

```Hello Robert,
1. No it was not old news and your reply was very welcome.
2. The reason why I posted this question is that I wanted to understand
better a post from another user.
3. I will most certainly have more questions about rules and patterns and
will post them here as they come along.
Julien.

2009/11/2 Robert Dodier <robert.dodier at gmail.com>

> On 10/30/09, Julien Martin <balteo at gmail.com> wrote:
>
> > Further to a prior post to me from another user, I would be extremely
> > grateful if someone could give me a brief example of how to use rules and
> > patterns.
> > A super basic example/use case would be great!!
>
> Not sure if this is still needed, but here is an example.
>
> A rule, in Maxima, is just an identity, i.e. a declaration that
> two different expressions are equivalent for values which
> satisfy some predicate or predicates.
>
> e.g. for positive integer values of n, foo(n) = n * foo(n - 1),
> and foo(0) = 1.
>
>  tellsimpafter (foo (0), 1);
>  matchdeclare (nn, lambda ([e], integerp (e) and e > 0));
>  tellsimpafter (foo (nn), nn * foo (nn - 1));
>
> Now we get this:
>
>  foo (x);
>    => foo (x);
>  foo (3);
>    => 3 * foo (2);
>  ''%;
>    => 6 * foo (1);
>  ''%;
>    => 6 * foo (0);
>  ''%;
>    => 6
>
> There are probably apparently-obvious variations on this which
> don't work. Also, maybe we'd like to have foo(3) => 6 immediately.
> But instead of trying to figure out this example, maybe you can
> say more about what you're trying to do. Sorry if this is old news,
> I've been out of the loop.
>
> HTH
>
> Robert Dodier
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.math.utexas.edu/pipermail/maxima/attachments/20091102/3c68ed29/attachment.htm
```