Arnoldo Jose Muller Molina wrote:
> dmatch(E1,E2) = (#expand(E1) + #expand(E2)) - (2 * dmatchAux(expand
> (E1),expand(E2)));
As Q functions may have side effects, it is not possible to optimize
away shared subexpressions like this. That's what where clauses are for.
Try something like:
dmatch(E1,E2) = (#X1 + #X2) - (2 * dmatchAux(X1,X2))
where X1 = expand(E1), X2 = expand(E2);
> I have executed some stats commands after executing this rule, with and
> without the "(#expand(E1) + #expand(E2))" and it seems that q is
> calculating expand(E1) and expand(E2) 2 times (1).
>
> 1) Is this true?
>
> 2) if that is so, is there a way of implementing a "let" so I can
> compute only once the results of expand(_)? Of course I could create an
> elaborate chain of rules and allow this, but is there a way that doesn't
> involve creating several rules?
>
> Thank you!
>
> --------------------------
> (1) (expand(...) is a deterministic rule, it will always return the same
> result for the same input)
--
Dr. Albert Gr"af
Dept. of Music-Informatics, University of Mainz, Germany
Email: Dr....@t-..., ag...@mu...
WWW: http://www.musikinformatik.uni-mainz.de/ag
|