1 /* First load the necessary file: */
3 /* For example, define the linearity properties of F.
4 F is to be linear in its first, third and fifth arguments.
5 The predicate to be used for distinguishing the coefficients
6 of these arguments will be called FVARP. */
7 declare_linear_operator(f,[1,3,5],fvarp);
8 fvarp(exp):=member(exp,[a,b,c]);
9 /* An example of an expression with the necessary property is: */
10 ff(x,e,y,f,z,g,x):=(k1*x+k2*y+k3*z)/(e+f)^g;
11 /* In this expression, FF is linear in [X, Y, Z], taken
12 as the components of a vector. Note that this is distinguished
13 from being linear in X, Y, or Z taken one at a time.
15 Here is an expression that is equivalent to 0. */
16 exp1:(f(a,x,b,y,c,z)*2-f(2*a,x,2*b,y,2*c,z))*h(q)/(a+b)*(f+h);
17 /* The function LINSIMP looks at sums contained in its
18 first argument and combines the F expressions whenever possible. */
20 /* The function LINSIMP extracts coefficients from the arguments
21 of F whenever it can. */
22 exp2:f(6*a,x,2*b,y,4*c,z);
24 /* To remove the LINEAR_OPERATOR property from F, use REM. */
25 rem(f,linear_operator);
26 /* Now verify that it is gone: */
27 errcatch(linsimp(exp,f));
28 /* LINSIMP can simplify with respect to several operators.
29 To illustrate this, we first make the
30 necessary declarations. */
31 declare_linear_operator(f,[1,2,3],fvarp);
32 declare_linear_operator(h,[1,2],hvarp);
33 hvarp(exp):=member(exp,[d,e,f])$
34 exp3:(f(2*a,-a*x,b/3,w)-f(a,b*x,c,w)
35 +h(w*e,f*(a+b),3)+2*h(-w*e,f*a,3))/a;
37 /* Notice that in the above example, LINSIMP was NOT confused
38 by the presence of F as both a variable and an undefined
40 LINSIMP will not combine forms that differ in the
41 arguments that are not specified in the linearity
43 exp4:f(a,b,c,d,e)-f(a,b,c,d,h);
45 /* But it will make combinations whenever possible, even
46 when the operator appears with varying numbers of
48 exp5:f(a,b,c,d,e)-f(a,b,2*c,d,e)+2*f(b,a,c)-h*f(c,2*b,a);
50 /* LINSIMP also recognizes the zero case: */
53 /* Here is an example with SUM: */
54 declare_linear_operator(nounify(sum),[1],'sumvarp);
55 sumvarp(exp):=not(freeof('n,exp));
56 a*'sum(f(n)*x^n,n,0,inf)+b*x*'sum(g(n)*x^(n-1),n,0,inf);
57 factor(linsimp(%,nounify('sum)));