Arnoldo Muller wrote:
> X + Y = Y + X if isnum(Y) and not isnum(X);
> After running Q with this new equation, I get effectively what I want (I
> want all the integer values added):
> ==> a + 4 + a + 5;
> so my questions are:
> Is this the best way of grouping integers? Is there a better way
> of doing it in Q?
Well, that depends on the application. If you're going to implement a
full-blown symbolic algebra system then it's probably better to wrap up
your simplification rules in a function, i.e., something like
simplify (X + Y) = simplify (Y + X) if isnum(Y) and not isnum(X);
simplify X = X otherwise;
This way you can also have multiple simplification functions for
different set of simplification rules, which gives you better control
over which rulesets are invoked in which situations.
> Is there a library that has all these definitions (including more
> complicated algebraic simplification rules)?
Nothing yet, sorry.
> How a equation that returns 9 + 3a for (a + a + a + 5 + 4) would
> look like?
N*X+X = (N+1)*X if isnum N;
N*X+M*X = (N+M)*X if isnum N and then isnum M;
Y+N*X+X = Y+(N+1)*X if isnum N;
Y+N*X+M*X = Y+(N+M)*X if isnum N and then isnum M;
Note that when you're dealing with multivariate polynomials this soon
gets rather nasty and you need additional rules to bring the right terms
Dr. Albert Gr"af
Dept. of Music-Informatics, University of Mainz, Germany
Email: Dr.Graef@..., ag@...