log of a product(...) to be sum(...) of a log



On 5/17/10, ross kyprianou <ross7k at gmail.com> wrote:

> Ive spent about 6 hours reading thru the ref manual and an hour
> googling but the closest Ive got to trying to simplify a (ratio of a)
> product of (independent) normal distributed (variance==1) random
> variables i.e.
>
> p(x,m) := (2*%pi)^(-1/2) * exp((-1/2)*(x-m)^2)
>
> log(  product( p(x[k],m[1]), k,1,n ) )  ) -  log(   product(
> p(x[k],m[0]),k,1,n ) )   );

Try ev(foo, logexpand=all) where foo is some log(product(...)) expression.

There is some documentation for logexpand but it doesn't mention
product expressions ... I guess that's an oversight, sorry about that.

> (%i16) defrule(rule1, log(product(z,k,1,n)), sum(log(z),k,1,n) );
>
> (%o16)       rule1 : log(product(z, k, 1, n)) -> sum(log(z), k, 1, n)
> (%i17) disprule(all);
>
> (%t17)       rule1 : log(product(z, k, 1, n)) -> sum(log(z), k, 1, n)
>
> (%o17)                              [%t17]
> (%i18) rule1 (log(product(z,k,1,n)));
>
> (%o18)                               false

For the record, I find the following works as expected, sorry for the
messy ascii art.
(1) matchdeclare(z, all) matches z to any expression, otherwise
z matches only a literal symbol z.
(2) I've turned off simplification to prevent log('product(z,k,1,n)) => n log(z)
in the rule definition.
(3) I called apply1 to apply the rule instead of calling the rule
directly. rule1(foo) also works in this case but apply1 also works
when the log(product(...)) expression is not the top-level expression.

(%i1) matchdeclare (z, all);
(%o1)                                done
(%i2) simp : false;
(%o2)                                false
(%i3) defrule(rule1, log('product(z,k,1,n)), sum(log(z),k,1,n) );
                               n
                             /===\
                              ! !
(%o3)            rule1 : log( ! !  z) -> sum(log(z), k, 1, n)
                              ! !
                             k = 1
(%i4) simp : true;
(%o4)                                true
(%i5) foo : log (product (f(k), k, 1, n));
                                      n
                                    /===\
                                     ! !
(%o5)                           log( ! !  f(k))
                                     ! !
                                    k = 1
(%i6) apply1 (foo, rule1);
                                 n
                                ====
                                \
(%o6)                            >    log(f(k))
                                /
                                ====
                                k = 1


HTH

Robert Dodier