Fix typo in display-html-help
[maxima.git] / tests / rtest_gcd.mac
blobc4e18ca1ea135d8e56d92b8f3a557081ce1e2754
1 (kill(all),0);
2 0$
4 (gcd_all_options(f,g) := append(makelist((gcd:option, gcd(f,g)), option, [ez, subres, red, spmod]),
5                                 makelist((gcd:option, gcd(g,f)), option, [ez, subres, red, spmod])),
6  check_gcd(f,g,expected_result) := block([gcds], gcds:gcd_all_options(expand(f), expand(g)),
7                                          if every (lambda ([e], equal (e, expected_result)), gcds)
8                                          then true
9                                          else FAILED_GCDS ('expected = expected_result, 'actual = gcds)),
10  0);
13 /* Basic tests: numbers */
15 check_gcd(1, 1, 1);
16 true$
18 check_gcd(1, -1, 1);
19 true$
21 check_gcd(6, 2, 2);
22 true$
24 check_gcd(6, -2, 2);
25 true$
27 check_gcd(3/2, 1/2, 1/2);
28 true$
30 check_gcd(3/2, -1/2, 1/2);
31 true$
33 check_gcd(1+%i, 2+2*%i, 1+%i);
34 true$
36 check_gcd(1+%i, -1/2-1/2*%i, 1/2+1/2*%i);
37 true$
39 /* Basic tests: univariate polynomials */
41 check_gcd(x, 1, 1);
42 true$
44 check_gcd(6*x, 2, 2);
45 true$
47 check_gcd(2*x*(3*x-1), 2*x, 2*x);
48 true$
50 check_gcd(2*x*(3*x-1), 3*x-1, 3*x-1);
51 true$
53 check_gcd(2*x*(3*x-1), 6*x*(3*x-1), 2*x*(3*x-1));
54 true$
56 check_gcd(2*x*(3*x-1), 3*x+1, 1);
57 true$
59 /* Basic tests: multivariate polynomials */
61 check_gcd(y*x, 1, 1);
62 true$
64 check_gcd(6*y*x, 2, 2);
65 true$
67 check_gcd(2*y*(3*x-1)*(y+1), 2*y, 2*y);
68 true$
70 check_gcd(2*y*(3*x-1)*(y+1), (3*x-1)*(y-1), 3*x-1);
71 true$
73 check_gcd(2*y*(3*x-1)*(y+1), 2*y*(3*x-1)*(y-1), 2*y*(3*x-1));
74 true$
76 check_gcd(2*y*(3*x-1)*(y+1), 6*y*(3*x-1)*(y+1), 2*y*(3*x-1)*(y+1));
77 true$
79 check_gcd(2*y*(3*x-1)*(y+1), (3*x+1)*(y-1), 1);
80 true$
82 /* Randomized tests */
84 (random_polynomial(var) := product(random(3)+1+sum((random(4)-2)*var^i, i, 1, random(3)), j, 0, random(3)),
85  check_gcd_common_factor(f,g,common_factor,vars) :=
86  block([gcds], gcds: gcd_all_options (expand (f), expand (g)),
87        if every (lambda ([x], equal (remainder (x, common_factor), 0)), gcds)
88        then true
89        else FAILED_GCDS ('common_factor = common_factor, 'gcd_results = gcds)),
90  0);
93 makelist(block([common_factor],
94                common_factor:random_polynomial(x),
95                check_gcd_common_factor(common_factor*random_polynomial(x),
96                                        common_factor*random_polynomial(x),
97                                        common_factor,
98                                        [x])),
99          10);
100 [true, true, true, true, true, true, true, true, true, true]$
102 makelist(block([common_factor],
103                common_factor:random_polynomial(x)*random_polynomial(y),
104                check_gcd_common_factor(common_factor*random_polynomial(x)*random_polynomial(y),
105                                        common_factor*random_polynomial(x)*random_polynomial(y),
106                                        common_factor,
107                                        [x, y])),
108          10);
109 [true, true, true, true, true, true, true, true, true, true]$
111 makelist(block([common_factor],
112                common_factor:random_polynomial(x)*random_polynomial(y)*random_polynomial(z),
113                check_gcd_common_factor(common_factor*random_polynomial(x)*random_polynomial(y)*random_polynomial(z),
114                                        common_factor*random_polynomial(x)*random_polynomial(y)*random_polynomial(z),
115                                        common_factor,
116                                        [x, y, z])),
117          10);
118 [true, true, true, true, true, true, true, true, true, true]$
120 /* SF bug 3832 and merge request 25 */
122 is(equal(gcd(expand((r^2-2*m+a^2)*(a^2*s^2+r^2)^3*(a^2*s^2+r^2-2*m)), expand((r^2-2*m+a^2)*(a^2*s^2+r^2)^2)),
123          expand((r^2-2*m+a^2)*(a^2*s^2+r^2)^2)));
124 true$