1 /* Original version of this file copyright 1999 by Michael Wester,
2 * and retrieved from http://www.math.unm.edu/~wester/demos/Algebra/problems.macsyma
5 * Released under the terms of the GNU General Public License, version 2,
6 * per message dated 2007-06-03 from Michael Wester to Robert Dodier
7 * (contained in the file wester-gpl-permission-message.txt).
9 * See: "A Critique of the Mathematical Abilities of CA Systems"
10 * by Michael Wester, pp 25--60 in
11 * "Computer Algebra Systems: A Practical Guide", edited by Michael J. Wester
12 * and published by John Wiley and Sons, Chichester, United Kingdom, 1999.
14 /* ---------- Algebra ---------- */
15 /* One would think that the simplification 2 2^n => 2^(n + 1) would happen
16 automatically or at least easily ... */
20 subst(a = 2, subst(2 = a, 2*2^n));
23 /* And how about 4 2^n => 2^(n + 2)? [Richard Fateman] */
27 (declare(n,integer),0);
30 map('factor, 2^(n + 2));
36 (remove(n, integer),0)
42 /* Univariate gcd: gcd(p1, p2) => 1, gcd(p1 q, p2 q) => q [Richard Liska] */
43 (p1: 64*x^34 - 21*x^47 - 126*x^8 - 46*x^5 - 16*x^60 - 81,
44 p2: 72*x^60 - 25*x^25 - 19*x^23 - 22*x^39 - 83*x^52 + 54*x^10 + 81,
45 q: 34*x^19 - 25*x^16 + 70*x^7 + 20*x^3 - 91*x - 86,
49 gcd(expand(p1*q), expand(p2*q)) - q;
52 resultant(expand(p1*q), expand(p2*q), x);
55 /* How about factorization? => p1 * p2 */
56 factor(expand(p1 * p2));
59 (remvalue(p1, p2, q),0);
62 /* Multivariate gcd: gcd(p1, p2) => 1, gcd(p1 q, p2 q) => q */
63 (p1: 24*x*y^19*z^8 - 47*x^17*y^5*z^8 + 6*x^15*y^9*z^2 - 3*x^22 + 5,
64 p2: 34*x^5*y^8*z^13 + 20*x^7*y^7*z^7 + 12*x^9*y^16*z^4 + 80*y^14*z,
65 q: 11*x^12*y^7*z^13 - 23*x^2*y^8*z^10 + 47*x^17*y^5*z^8,
69 gcd(expand(p1*q), expand(p2*q)) - q;
72 /* How about factorization? => p1 * p2 */
73 factor(expand(p1 * p2));
76 (remvalue(p1, p2, q),0);
79 /* => x^n for n > 0 [Chris Hurlburt] */
80 gcd(2*x^(n + 4) - x^(n + 2), 4*x^(n + 1) + 3*x^n);
83 /* Resultants. If the resultant of two polynomials is zero, this implies they
84 have a common factor. See Keith O. Geddes, Stephen R. Czapor and George
85 Labahn, _Algorithms for Computer Algebra_, Kluwer Academic Publishers, 1992,
87 resultant(3*x^4 + 3*x^3 + x^2 - x - 2, x^3 - 3*x^2 + x + 5, x);
90 /* Numbers are nice, but symbols allow for variability---try some high school
91 algebra: rational simplification => (x - 2)/(x + 2) */
92 ((x^2 - 4)/(x^2 + 4*x + 4),
96 /* This example requires more sophistication => e^(x/2) - 1 */
97 radcan([(%e^x - 1)/(%e^(x/2) + 1), (exp(x) - 1)/(exp(x/2) + 1)]);
100 /* Expand and factor polynomials */
105 /* Completely factor this polynomial, then try to multiply it back together! */
106 solve(x^3 + x^2 - 7 = 0, x);
107 apply("*", map(lambda([e], lhs(e) - rhs(e)), %));
111 /* Factorization over the complex rationals
112 => (2 x + 3 i) (2 x - 3 i) (x + 1 + 4 i) (x + 1 - 4 i) */
113 gfactor(4*x^4 + 8*x^3 + 77*x^2 + 18*x + 153);
114 /* Algebraic extensions */
116 tellrat(sqrt2^2 - 2);
119 /* => (x^2 - 2 x - 3)/(x - sqrt2) = (x + 1) (x - 3)/(x - sqrt2)
121 (x^3 + (sqrt2 - 2)*x^2 - (2*sqrt2 + 3)*x - 3*sqrt2)/(x^2 - 2);
124 factor(%, sqrt2^2 - 2);
126 /* Multiple algebraic extensions */
127 tellrat(sqrt3^2 - 3, cbrt2^3 - 2);
128 /* => 2 cbrt2 + 8 sqrt3 + 18 cbrt2^2 + 12 cbrt2 sqrt3 + 9 */
129 rat((cbrt2 + sqrt3)^4);
130 untellrat(sqrt3, cbrt2)$
132 /* Factor polynomials over finite fields and field extensions */
135 /* => (x - 2)^2 (x + 2)^2 mod 5 */
136 ev(factor(p), modulus:5);
138 /* => (x^2 + x + 1) (x^9 - x^8 + x^6 - x^5 + x^3 - x^2 + 1) mod 65537
140 ev(factor(x^11 + x + 1), modulus:65537);
141 /* => (x - phi) (x + phi) (x - phi + 1) (x + phi - 1)
142 where phi^2 - phi - 1 = 0 or phi = (1 +- sqrt(5))/2 */
143 factor(p, phi^2 - phi - 1);
145 expand((x - 2*y^2 + 3*z^3)^20)$
147 expand((sin(x) - 2*cos(y)^2 + 3*tan(z)^3)^20)$
149 /* expand[(1 - c^2)^5 (1 - s^2)^5 (c^2 + s^2)^10] => c^10 s^10 when
150 c^2 + s^2 = 1 [modification of a problem due to Richard Liska] */
151 expand((1 - c^2)^5 * (1 - s^2)^5 * (c^2 + s^2)^10)$
152 grobner([%, c^2 + s^2 - 1]);
154 /* => (x + y) (x - y) mod 3 */
155 ev(factor(4*x^2 - 21*x*y + 20*y^2), modulus:3);
156 /* => 1/4 (x + y) (2 x + y [-1 + i sqrt(3)]) (2 x + y [-1 - i sqrt(3)]) */
157 factor(x^3 + y^3, isqrt3^2 + 3);
158 /* Partial fraction decomposition => 3/(x + 2) - 2/(x + 1) + 2/(x + 1)^2 */
159 (x^2 + 2*x + 3)/(x^3 + 4*x^2 + 5*x + 2);
161 /* Noncommutative algebra: note that (A B C)^(-1) = C^(-1) B^(-1) A^(-1)
162 => A B C A C B - C^(-1) B^(-1) C B */
163 (A.B.C - (A.B.C)^^(-1)) . A.C.B;
165 /* Jacobi's identity: [A, B, C] + [B, C, A] + [C, A, B] = 0 where [A, B, C] =
166 [A, [B, C]] and [A, B] = A B - B A is the commutator of A and B */
167 comm2(A, B):= A . B - B . A$
168 comm3(A, B, C):= comm2(A, comm2(B, C))$
170 comm3(A, B, C) + comm3(B, C, A) + comm3(C, A, B);
172 remfunction(comm2, comm3)$