4 (assume_pos_save: assume_pos, assume_pos: true);
7 /* Known failure: concat (q, k) => gensym
9 sum (concat (q, k), k, a, b);
12 /* Known failure: concat (q, k) => gensym
14 product (concat (q, k), k, a, b);
17 /* Known failure: causes asksign to ask an unanswerable question about index variable;
18 * this is a bug in integrate and/or asksign.
19 (assume (b > 0, a > 0, b > a), sum (integrate (1/x^k, x, a, b), k, 1, n));
20 integrate (1/x, x, a, b) + sum (integrate (1/x^k, x, a, b), k, 2, n);
23 /* Known failure: causes asksign to ask an unanswerable question about index variable;
24 * this is a bug in integrate and/or asksign.
25 product (integrate (1/x^k, x, a, b), k, 1, n);
26 integrate (1/x, x, a, b) * product (integrate (1/x^k, x, a, b), k, 2, n);
29 block ([prederror: false], sum(if k < 1 then a else b,k,0,n));
30 '( 'sum(if k < 1 then a else b,k,0,n));
32 /* see SF bug report # 625278 */
34 'sum(binomial(2,2-k)-binomial(2,1-k),k,1,2),simpsum;
37 'sum(binomial(2,2-k)-binomial(2,1-k),k,1,2),sum;
40 'sum(binomial(x,2-k)-binomial(x,1-k),k,1,2),simpsum;
43 'sum(binomial(x,2-k)-binomial(x,1-k),k,1,2),sum;
46 sum (f(k) + 1, k, 1, n), simpsum;
47 n + 'sum (f(k), k, 1, n);
49 /* further examples in the same vein: part of summand depends on index, part doesn't. */
51 sum (sin(g(j)) - %pi^j + cos(h(k)) - %e^l, j, 1, m), simpsum;
52 m*cos(h(k)) - m*%e^l + sum (sin(g(j)), j, 1, m) - ((%pi^(m + 1) - %pi)/(%pi - 1));
54 sum (sum (f(j) + g(k), j, 1, m), k, 1, n), simpsum;
55 m * 'sum (g(k), k, 1, n) + n * 'sum (f(j), j, 1, m);
57 sum (sum (f(j) + g(k) - %pi^l + 2, j, 1, m), k, 1, n), simpsum;
58 m * 'sum (g(k), k, 1, n) + n * 'sum (f(j), j, 1, m) - m*n*%pi^l + 2*m*n;
60 sum (sum (sum (%pi + %phi - 1, i, 1, n_i), j, 1, n_j), k, 1, n_k);
61 n_i * n_j * n_k * (%pi + %phi - 1);
63 sum (sum (sum (f(%pi, i) + g(%phi, j) - h(k), i, 1, n_i), j, 1, n_j), k, 1, n_k);
64 'sum ('sum ('sum (f(%pi, i) + g(%phi, j) - h(k), i, 1, n_i), j, 1, n_j), k, 1, n_k);
66 /* see SF bug report # 649428 */
68 (factsum3 (mt, ej) := sum ((-1)^(k + 1)/(k*mt^k)*sum((1 - l)^k - l^k, l, 1, ej),k,1,inf), t% : taylor (factsum3 (mt, ej), [mt, 0, 3, asymp]));
69 'sum(1-2*l,l,1,ej)/mt-('sum(1-2*l,l,1,ej)/(2*mt^2))+'sum(-2*l^3+3*l^2-3*l+1,l,1,ej)/(3*mt^3);
72 -((6*ej^2*mt^2-3*ej^2*mt+ej^4+ej^2)/(6*mt^3));
74 /* Known failure: interaction of taylor and simpsum
76 taylor (factsum3 (mt, ej), [mt, 0, 3, asymp]), simpsum;
77 -(6*ej^2*mt^2-3*ej^2*mt+ej^4+ej^2)/(6*mt^3);
79 /* see SF bug report # 740134 */
81 (foo: i^2, [sum ('foo, i, 0, 2), sum (foo, i, 0, 2), sum (foo, i, 0, n)]);
82 [3*foo, 5, 'sum (i^2, i, 0, n)];
84 /* summand is a function which has a side effect --
85 * outcome here differs from recommendation by Stavros in 740134
87 block ([L:[]], f(i) := (L: append (L, [i]), i), S: sum (f (i), i, 1, 3), [S, L]);
90 sum (integrate (x^i ,x), i, 0, 2);
93 sum (integrate (1/(x^i + 1), x), i, 0, 1);
96 (f[i](x) := x^i, g[i](x) := x^i, h[i](x) := x^i, 0);
102 sum (f[i](x), i, 0, n);
105 sum (g[i](x), i, 0, n);
108 sum (h[i](x), i, 0, n);
111 /* see SF bug report # 817521 */
113 (kill (foo), foo (n):= block([aaa,m], modedeclare([m,n], fixnum), m:n, [ aaa[1], aaa[n], aaa[m], aaa[1]+aaa[2], sum(aaa[i],i,1,m) ] ), foo (2));
114 [aaa[1],aaa[2],aaa[2],aaa[2]+aaa[1], aaa[2]+aaa[1]];
120 [aaa[1],aaa[2],aaa[2],aaa[2]+aaa[1], aaa[2]+aaa[1]];
122 /* see SF bug report # 851765 */
124 (apply (forget, facts ()), assume (i >= a), sum (i, i, a, b), facts ());
130 (assume (i < 0), sum (abs (i), i, 1, a));
133 (apply (forget, facts ()), 0);
136 /* see SF bug report # 1007094 */
138 (u: 'sum((-1/(8*i+6)-1/(8*i+5)-2/(8*i+4)+4/ (8*i+1))/16^i,i,1,a), 0);
145 0.0082540570132481894$
147 u, a=2, simpsum, numer;
148 0.0082540570132481911$
150 u, a=2, simpsum, bfloat;
153 /* see SF bug report # 1192935 */
155 (f(x) := x^2, b: 1/10, Ak: b*f(k*b), sum (Ak, k, 0, 9));
158 /* When A(k) is defined as A(k) := b*f(k*b) instead of define(A(k), b*f(k*b)),
159 * A(k) evaluates to k^2/n^3 even if n is bound to something;
160 * this is a consequence of Maxima's evaluation policies:
161 * rhs of := is not evaluated, and variables (b in this case)
162 * are evaluated just once.
164 (b:1/n, define (A(k), b*f(k*b)), A(k));
167 sum (A(k), k, 0, n-1);
168 ('sum (k^2, k, 0, n-1))/n^3;
170 sum (A(k), k, 0, n-1), simpsum;
171 (n+2*(n-1)^3+3*(n-1)^2-1)/(6*n^3);
173 [''%, sum (A(k), k, 0, n-1)], n=10;
176 (B(k) := k*f(k*b), B(k));
179 sum (B(k), k, 0, n-1), simpsum;
180 ((n-1)^4 + 2*(n-1)^3 + (n-1)^2) / (4*n^2);
182 /* see SF bug report # 1363411 */
184 (kill (f), 'sum(1+f(k),k,1,2)), simpsum;
187 is(equal(block([gcd:subres], ratsimp((-x^3+1)/(2*x^5+2) + (-sqrt(5)+5)/(20*x^2+(-10*sqrt(5)-10)*x+20))),
188 block([gcd:spmod], ratsimp((-x^3+1)/(2*x^5+2) + (-sqrt(5)+5)/(20*x^2+(-10*sqrt(5)-10)*x+20)))));
191 /* General tests from here on */
193 sum (x, x, p, p + 2);
194 p + (p + 1) + (p + 2);
196 product (x, x, p, p + 2);
197 p * (p + 1) * (p + 2);
199 sum (x, x, %i, %i + 2);
200 %i + (%i + 1) + (%i + 2);
202 product (x, x, %i, %i + 2);
203 %i * (%i + 1) * (%i + 2);
205 sum (imagpart (1 + %i*k), k, 1, n), simpsum;
208 product (imagpart (1 + %i*k), k, 1, n), simpproduct;
211 (g(x) := q(x^2), sum (g(k), k, 1, n));
212 'sum (q (k^2), k, 1, n);
214 (g(x) := q(x^2), product (g(k), k, 1, n));
215 'product (q (k^2), k, 1, n);
217 sum (integrate (x^k, x, 0, 1), k, 1, n);
218 'sum (1/(k + 1), k, 1, n);
220 product (integrate (x^k, x, 0, 1), k, 1, n);
221 'product (1/(k + 1), k, 1, n);
223 (kill(b), sum ('concat (q, k), k, a, b));
224 'sum ('concat (q, k), k, a, b);
226 sum ('concat (q, k), k, a, b), nouns, a=1, b=5;
227 q5 + q4 + q3 + q2 + q1;
229 product ('concat (q, k), k, a, b);
230 'product ('concat (q, k), k, a, b);
232 product ('concat (q, k), k, a, b), nouns, a=1, b=5;
233 q5 * q4 * q3 * q2 * q1;
235 (assume (n>= 1), sum (if k <= n then a else b, k, 1, n));
238 product (if k <= n then a else b, k, 1, n);
241 sum (sin (%pi * k), k, 0, nn);
244 product (cos (2 * %pi * k), k, 0, nn);
247 sum (lambda ([x], x^i), i, 1, 3);
248 lambda ([x], x) + lambda ([x], x^2) + lambda ([x], x^3);
250 sum (k: k^2, k, 1, 3);
253 sum (a, k, inf, minf);
256 (assume (i < 0, j < 0, n > 0), sum(sum(abs(i) + abs(j),i,1,j),j,1,n));
257 'sum ('sum (i + j, i, 1, j), j, 1, n);
259 sum (sum (sqrt (i + j), i, 1, j), j, 1, n), simpsum;
260 'sum ('sum (sqrt (i + j), i, 1, j), j, 1, n);
262 sum (1/k, k, rat(1), rat(n));
265 sum (taylor (x^i, x, 0, 5), i, 0, 5);
266 ''(taylor (x^5 + x^4 + x^3 + x^2 + x + 1,x,0,5));
268 (i: 888, sum (lambda ([i], i^2), i, 1, 3));
269 3 * lambda ([i], i^2);
271 sum (lambda ([i], i^2), i, 1, n);
272 n * lambda ([i], i^2);
274 (f(x) := sum (x, i, 1, 3), f(-x));
277 (ak : k^2, g(a,n) := sum(a,k,1,n), g(ak, 5));
280 (translate (g), g(ak,5));
283 sum (integrate (x^i, x), i, 0, n);
284 'sum (x^(i+1) / (i+1), i, 0, n);
286 (assume (k < 0), assume (0 < n, m > n), sum (sqrt (k^2), k, n, m));
289 (assume (i >= n_1, i <= n_2), sum (z(i), i, n_1, n_2));
290 'sum (z(i), i, n_1, n_2);
292 block ([prederror: false], [is (i >= n_1), is (i <= n_2)]);
295 /* some examples adapted from describe("sum") */
297 (old_facts: facts (), foo: 42, bar: 12 + exp(7), baz: 1/quux, 0);
300 sum (foo^2, foo, 1, 7);
303 sum (aa[bar], bar, 1, 7);
304 aa[7] + aa[6] + aa[5] + aa[4] + aa[3] + aa[2] + aa[1];
306 sum (aa(baz), baz, 1, 7);
307 aa(7) + aa(6) + aa(5) + aa(4) + aa(3) + aa(2) + aa(1);
309 sum (aa(foo), foo, 1, n);
310 'sum (aa(foo), foo, 1, n);
312 sum (2^bar + bar^2, bar, 0, n), simpsum;
313 2^(n + 1) + (2*n^3 + 3*n^2 + n)/6 - 1;
315 sum (1/3^baz, baz, 1, inf), simpsum;
318 sum (foo^2, foo, 1, 4) * sum (1/foo^2, foo, 1, inf), simpsum;
321 (gg(bar) := 1/bar^2, sum (gg(bar)^2, bar, 1, inf));
322 sum (1/bar^4, bar, 1, inf);
324 sum (gg(baz)^2, baz, 1, inf), simpsum;
327 [is (foo = 42), is (bar = 12 + exp(7)), is (baz = 1/quux)];
330 (new_facts: facts(), is (sort (old_facts) = sort (new_facts)));
333 /* redo all of the tests, this time with product */
335 product (lambda ([x], x^i), i, 1, 3);
336 lambda ([x], x) * lambda ([x], x^2) * lambda ([x], x^3);
338 product (k: k^2, k, 1, 3);
341 product (a, k, inf, minf);
344 (assume (i < 0, j < 0, n > 0), product(product(abs(i) + abs(j),i,1,j),j,1,n));
345 'product ('product (i + j, i, 1, j), j, 1, n);
347 product (1/k, k, rat(1), rat(n));
348 'product (1/k, k, 1, n);
350 product (taylor (x^i, x, 0, 5), i, 0, 5);
351 ''(taylor (x^15,x,0,15));
353 (i: 888, product (lambda ([i], i^2), i, 1, 3));
354 (lambda ([i], i^2))^3;
356 product (lambda ([i], i^2), i, 1, n);
359 (f(x) := product (x, i, 1, 3), f(-x));
362 (f(x) := x^2, b: 1/10, Ak: b*f(k*b), product (Ak, k, 1, 9));
365 (A(k) := k*f(k*b), b:1/n, A(k));
368 product (A(k), k, 0, n-1);
369 ('product (k^3/n^2, k, 0, n-1));
371 (assume (n > 0, m > n), ev (product (k, k, n, m), simpproduct));
374 (ak : k^2, g(a,n) := product(a,k,1,n), g(ak, 5));
377 (translate (g), g(ak,5));
380 /* multiplicand is a function which has a side effect */
382 block ([L:[]], f(i) := (L: append (L, [i]), i), S: product (f (i), i, 1, 3), [S, L]);
385 product (integrate (x^i ,x), i, 0, 2);
388 product (integrate (1/(x^i + 1), x), i, 0, 1);
391 (f[i](x) := x^i, g[i](x) := x^i, h[i](x) := x^i, 0);
394 /* reference f[i] and g[i] -- see 740134 for the effect this has on previous defn of sum */
399 product (f[i](x), i, 0, n);
400 'product (x^i, i, 0, n);
402 product (g[i](x), i, 0, n);
403 'product (x^i, i, 0, n);
405 product (h[i](x), i, 0, n);
406 'product (x^i, i, 0, n);
408 product (integrate (x^i, x), i, 0, n);
409 'product (x^(i+1) / (i+1), i, 0, n);
411 (assume (k < 0), assume (0 < n, m > n), ev (product (sqrt (k^2), k, n, m), simpproduct));
414 (assume (i >= n_1, i <= n_2), product (z(i), i, n_1, n_2));
415 'product (z(i), i, n_1, n_2);
417 block ([prederror: false], [is (i >= n_1), is (i <= n_2)]);
420 /* some examples adapted from describe("sum") */
422 (old_facts: facts (), foo: 42, bar: 12 + exp(7), baz: 1/quux, 0);
425 product (foo^2, foo, 1, 7);
428 product (aa[bar], bar, 1, 7);
429 aa[7] * aa[6] * aa[5] * aa[4] * aa[3] * aa[2] * aa[1];
431 product (aa(baz), baz, 1, 7);
432 aa(7) * aa(6) * aa(5) * aa(4) * aa(3) * aa(2) * aa(1);
434 product (aa(foo), foo, 1, n);
435 product (aa(foo), foo, 1, n);
437 product (2^bar + bar^2, bar, 0, n), simpsum;
438 product (2^bar + bar^2, bar, 0, n);
440 product (1/3^baz, baz, 1, inf), simpsum;
441 product (1/3^baz, baz, 1, inf);
443 product (foo^2, foo, 1, 4) * product (1/foo^2, foo, 1, inf), simpsum;
444 (4!)^2 * 'product (1/'foo^2, 'foo, 1, inf);
446 (gg(bar) := 1/bar^2, product (gg(bar)^2, bar, 1, inf));
447 'product (1/'bar^4, 'bar, 1, inf);
449 product (gg(baz)^2, baz, 1, inf), simpsum;
450 'product (1/'baz^4, 'baz, 1, inf);
452 [is (foo = 42), is (bar = 12 + exp(7)), is (baz = 1/quux)];
455 (new_facts: facts(), is (sort (old_facts) = sort (new_facts)));
458 /*---- new tests from bw ------*/
469 sum(sqrt(3),i,0,inf);
472 sum(sqrt(3),i,-1932,inf);
478 sum(-sqrt(3),i,0,inf);
487 sum(p(i + 1) - p(i),i,1,5);
493 product(1,i,minf,inf);
496 product(1,i,-42,inf);
505 product(%pi,i,0,inf);
508 product(%pi - 3,i,0,inf);
511 product(%pi - 3,i,minf,inf);
514 product(-%pi,i,0,inf);
520 product(-%pi,i,minf,inf);
523 product((1 + %i)/sqrt(2),k,1,inf);
532 product(p(i + 1) / p(i),i,1,5);
535 sum(lambda([x],x^i),i,1,3);
536 lambda([x],x) + lambda([x],x^2) + lambda([x],x^3);
538 product(lambda([x],x^i),i,1,3);
539 lambda([x],x) * lambda([x],x^2) * lambda([x],x^3);
544 sum([1,k],k,1,n),simpsum;
547 (old_facts : facts(),0);
550 errcatch(sum(1/k,k,-1,1));
553 (new_facts: facts(), is (sort (old_facts) = sort (new_facts)));
556 (old_facts : facts(),0);
559 errcatch(product(1/k,k,-1,1));
562 (new_facts: facts(), is (sort (old_facts) = sort (new_facts)));
565 sum(diff(log(x),x,k),k,1,2);
568 product(diff(log(x),x,k),k,1,2);
571 sum(x^k * at(diff(sin(x),x,k)/k!,x=0),k,0,5) - taylor(sin(x),x,0,5);
574 product(%i-x,k,1,inf);
575 'product(%i-x,k,1,inf);
589 product(%i,k,inf,minf);
592 product(%i,k, 0, minf);
610 product(k,k,%i,%i+1);
619 sum(k,k,1,entier(4/3));
622 sum(k,k,entier(4/3),1);
625 sum(a,k,entier(4/3),entier(5/2));
628 product(k,k,1,entier(4/3));
631 product(k,k,entier(4/3),1);
634 product(a,k,entier(4/3),entier(5/2));
637 sum(q(k),k,n^2 + 1,-n^2 - 1); /* It's an empty sum */
640 product(q(k),k,n^2 + 1,-n^2 - 1);
643 sum(concat(q,k),k,1,3);
646 (s : sum('concat(q,k),k,1,n),0);
649 (s : subst(n=3,s), ev(s,nouns));
652 sum(product(concat(q,i),i,1,j),j,1,3);
653 q1 + q1 * q2 + q1 * q2 * q3$
655 product(concat(q,k),k,1,3);
658 (s : product('concat(q,k),k,1,n),0);
661 (s : subst(n=3,s), ev(s,nouns));
667 sum(realpart(a + %i * k),k,1,3);
673 sum(sum(abs(k),k,1,n),n,1,m);
674 sum(sum(k,k,1,n),n,1,m)$
676 sum(sum(k,k,1,i),i,1,n),simpsum,ratsimp;
677 ''(ratsimp(n^3/6+n^2/2+n/3))$
679 sum(sum(abs(k),k,1,n) + sum(abs(k),k,1,n),n,1,m);
680 2 * sum(sum(k,k,1,n),n,1,m)$
688 sum(if k < 1 then a else b,k,0,2);
691 block ([prederror : true], sum(if k < 1 then a else b,k,0,2));
694 sum(1/3^k,k,1,inf),simpsum;
697 sum(3^-i,i,1,inf),simpsum;
700 (kill(x), assume(abs(x)-1 < 0));
703 sum(x^k,k,0,inf),simpsum;
706 (forget(abs(x) - 1 < 0),0);
709 /*--- A few challenging sums ----*/
711 (assume (n >= 1), sum (if k <= n then a else b, k, 1, n));
714 (declare(nn,integer), sum(sin(%pi * k),k,0,nn));
717 sum(sin(x),x,1/2,1/2 + nn);
718 'sum(sin(x),x,1/2,1/2 + nn);
720 remove (nn, integer);
723 (assume_pos: assume_pos_save, apply (forget, facts ()), 0);
726 nusum ((n - 1)*(n - 1)!, n, 1, n);
732 nusum ((2*m)!/(m!*(m + 1)!), m, 0, n);
733 'sum ((2*m)!/(m!*(m + 1)!), m, 0, n);
736 /*--- A test for sumcontract ---*/
738 sumcontract(sum(k,k,1,n) + sum(k^2, k, 1, n));
741 /* Bug ID: 2770575 - rtestsum test 226
742 * This test simplifies correctly after revision 1.12 of sumcon.lisp.
744 sumcontract(sum(k, k, 1, n) + sum(k, k, 1, n+1));
747 /* Tests for bug report [ 1497706 ] sum(1/k^2,k,2,inf), simpsum; */
749 /* sum (1/k^2, ...) not simplified unless specifically requested */
750 (sum (1/k^2, k, 1, inf), [op (%%), args (%%)]);
751 [''(nounify (sum)), [1/k^2, k, 1, inf]];
753 sum (1/k^2, k, 1, inf), simpsum;
756 /* this is the case cited in the bug report */
757 sum (1/k^2, k, 2, inf), simpsum;
760 sum (1/k^2, k, 1, 9);
763 sum (1/k^2, k, 10, inf), simpsum;
764 %pi^2/6 - 9778141/6350400;
766 sum (1/k^4, k, 1, 5);
769 sum (1/k^4, k, 6, inf), simpsum;
770 %pi^4/90 - 14001361/12960000;
772 sum (1/k^7, k, 1, inf), simpsum;
775 sum (1/k^7, k, 1, 3);
778 sum (1/k^7, k, 4, inf), simpsum;
779 zeta (7) - 282251/279936;
781 /* Tests for bug report [ 1550985 ] niceindices
782 * Test the cases mentioned in the bug report & some others for good measure
785 (reset (niceindicespref), 0);
788 niceindices (sum (1/kk, kk, 1, n) - sum (1/ii, ii, 1, n));
791 niceindices (sum (1/k, k, 1, n) - sum(1/i, i, 1, n));
794 niceindices (sum (F(foo), foo, 1, inf));
795 'sum (F(i), i, 1, inf);
797 (niceindicespref : '[foo, bar, baz, quux], 0);
800 niceindices (sum (1/kk, kk, 1, n) - sum (1/ii, ii, 1, n));
803 niceindices (sum (1/k, k, 1, n) - sum(1/i, i, 1, n));
806 niceindices (sum (F(foo), foo, 1, inf));
807 'sum (F(foo), foo, 1, inf);
809 niceindices (product (sum (product (sum (product (m*F(i) + cos(G(j))^k/sin(l), m, 1, n5), l, 1, n4), k, 1, n3), j, 1, n2), i, 1, n1));
810 'product ('sum ('product ('sum ('product (foo*F(foo0) + cos(G(quux))^baz/sin(bar), foo, 1, n5), bar, 1, n4), baz, 1, n3), quux, 1, n2), foo0, 1, n1);
812 niceindices (sum (sum (foo/foo0, foo, 1, n), foo0, 1, m));
813 ('sum (1/foo, foo, 1, m)) * 'sum (foo, foo, 1, n);
815 niceindices (sum (sum (1/(foo + foo0), foo, 1, n), foo0, 1, m));
816 'sum ('sum (1/(foo + bar), foo, 1, n), bar, 1, m);
818 (reset (niceindicespref), 0);
821 /* Tests for bashindices, which used to not transform all indices in nested
822 * sums and products (only the outermost)
825 (reset (gensumnum), 0);
828 bashindices (sum (product (sum (F (l, m, n), l, 0, m), m, 0, n), n, 0, N));
829 'sum ('product ('sum (F (j1, j2, j3), j1, 0, j2), j2, 0, j3), j3, 0, N);
831 (reset (gensumnum), 0);
834 /* Test for bug report [ 1552710 ] product(sum(f(i),i,1,inf),j,1,inf) => inf (wrong) */
836 /* Since sum(f(i), i, 1, inf) is free of j, another result
837 * such as limit(sum(f(i), i, 1, inf)^n, n, inf) would be OK, too.
838 * In any event, inf (observed in the bug report) is not OK.
840 (kill(f), block ([x : product (sum (f(i), i, 1, inf), j, 1, inf)], block ([simp : false], is (x = 'product ('sum (f(i), i, 1, inf), j, 1, inf)))));
844 /* Test for bug reported by Amit Aronovitch to mailing list 2006/01/06
847 (kill(f), f(x) := sum (x^n/n!, n, 0, inf), f(2*x));
848 'sum (2^n*x^n/n!, n, 0, inf);
851 /* Test for intosum */
853 intosum(2*sum(k,k,1,inf));
856 /* correct a bug in SUBST-IF-NOT-FREEOF (src/asum.lisp):
857 * array flag in CAR was lost before, but it's OK now
859 (kill (a, i), x : a[i], sum (x, i, 1, 3));
862 /* Restore treatment of definite summations as it was before summation
863 * revisions of December 2005: simplify definite summation to explicit
864 * sum only if simpsum is true.
867 (kill (f), sum (f(i), i, 1, 3));
870 'sum (f(i), i, 1, 3);
871 'sum (f(i), i, 1, 3);
873 'sum (f(i), i, 1, 3), simpsum;
876 /* (analogous tests for product) */
878 product (f(i), i, 1, 3);
881 'product (f(i), i, 1, 3);
882 'product (f(i), i, 1, 3);
884 'product (f(i), i, 1, 3), simpproduct;
887 /* Differentiate wrt a subscripted symbol in a summation.
888 * Should work the same as for an ordinary symbol.
890 (kill (x, a, a1), 0);
893 diff ('sum (sin (a1 * x[i]), i, 1, n), a1);
894 'sum (x[i] * cos (a1 * x[i]), i, 1, n);
896 diff ('sum (x[i]^a1, i, 1, n), a1);
897 'sum (x[i]^a1 * log(x[i]), i, 1, n);
899 diff ('sum (sin (a[1] * x[i]), i, 1, n), a[1]);
900 'sum (x[i] * cos (a[1] * x[i]), i, 1, n);
902 diff ('sum (x[i]^a[1], i, 1, n), a[1]);
903 'sum (x[i]^a[1] * log(x[i]), i, 1, n);
905 /* Feature request 1848704: no way to convert log(product(...)) to sum(log(...)...)
908 (kill (u, a, x, T), 0);
911 log (product (u[k], k, 1, n));
912 log (product (u[k], k, 1, n));
914 log (product (u[k], k, 1, n)), logexpand=true;
915 log (product (u[k], k, 1, n));
917 log (product (u[k], k, 1, n)), logexpand=all;sum (log (u[k]), k, 1, n);
919 log (product (u[k], k, 1, n)), logexpand=super;
920 sum (log (u[k]), k, 1, n);
922 log (product (a*%e^x(i), i, 1, T));
923 log (product (a*%e^x(i), i, 1, T));
925 log (product (a*%e^x(i), i, 1, T)), logexpand=all;
926 /* Yields sum(const + ...) instead of const*T + sum(...)
927 * since sum is not known to be linear by default.
928 * Change this result if default ever changes.
930 sum (log(a) + x(i), i, 1, T);
932 /* bug reported to mailing list 2008-04-17:
933 * simpsum causes two evaluations of summand, should be only one
935 (bar (x, y) := sum (F (i, x, y), i, 1, n),
936 ev (bar (y, x), simpsum=false));
937 'sum (F (i, y, x), i, 1, n);
939 ev (bar (y, x), simpsum=true);
940 'sum (F (i, y, x), i, 1, n);
942 /* original problem */
945 geom(x,m,n):= (x^m-x^(n+1))/(1-x),
946 B(s,sp):=-phi[1](s)*phi[1](s+sp)*phi[0](s+sp)/(1-phi[1](s+sp)*phi[0](s +sp))
947 +(1-phi[1](s))*sum((phi[1](s)*phi[0](s))^n*(
948 geom( (phi[0](s+sp)*phi[1](s+sp))/(phi[0](s)*phi[1](s)), 1, n-1 )
949 -phi[1](s+sp)/phi[1](s)
950 *geom((phi[0](s+sp)*phi[1](s+sp))/(phi[0](s)*phi[1](s)), 0, n-1))
952 A(s):=phi[1](s)*(1+phi[0](s))/(1-phi[1](s)*phi[0](s)),
953 C(s,sp):=A(s+sp)+B(s,sp)+B(sp,s),
957 (expr_1 : ev (C (s, sp), simpsum=false),
958 expr_2 : ev (C (s, sp), simpsum=true),
959 is (expr_1 = expr_2));
962 (expr_1 : ev (C (sp, s), simpsum=false),
963 expr_2 : ev (C (sp, s), simpsum=true),
964 is (expr_1 = expr_2));
967 is (sublis ([s=sp, sp=s], C (s, sp)) = C (s, sp)), simpsum;
970 is (sublis ([s=sp, sp=s], C (sp, s)) = C (sp, s)), simpsum;
973 is (C (sp, s) = C (s, sp)), simpsum;
976 /* Tests for fbino in combin.lisp */
977 sum(binomial(2*n-k,k), k, 0, n), simpsum;
980 sum(binomial(n-k,k), k, 1, n), simpsum;
986 sum(binomial(n-k,k+1), k, 1, n-1), simpsum;
989 sum(binomial(2*n,2*k), k, 0, n), simpsum;
992 sum(binomial(n,2*k+1), k, 0, n), simpsum;
995 sum(binomial(n,2*k), k, 0, n), simpsum;
998 sum(binomial(n,2*k), k, 1, n), simpsum;
1001 sum(binomial(n+1,k), k, 1, n), simpsum;
1004 sum(binomial(n,k), k, -1, n+1), simpsum;
1007 sum(binomial(t+i,t),i,0,k), simpsum;
1008 binomial(t+k+1,t+1);
1010 /* Because of revision 1.43 of csimp2.lisp binomial(x,x) no longer simplifies
1011 * automatically to 1. The sign must be known not be negative.
1012 * Therefore, we add a fact about the sign of t.
1016 sum(binomial(t+i,t),i,1,k), simpsum;
1017 binomial(t+k+1,t+1)-1;
1021 sum(binomial(t+i,i),i,0,k), simpsum;
1022 binomial(t+k+1,t+1);
1027 /* bug in assume database causes trouble for conditional in summation
1028 * see mailing list 2009-07-29 "Fourier Series using fourie.mac"
1031 /* If ever the assume stuff is revised, this next test can go away.
1032 * It's here to ensure the underlying problem is fixed.
1037 (kill (all), assume (xx >= 1), 0);
1043 if xx > 1 then aa else bb;
1044 if xx > 1 then aa else bb;
1046 sum (if xx > 1 then aa else bb, xx, 1, 3);
1049 foo : 'sum (if xx > 1 then aa else bb, xx, 1, 3);
1050 'sum (if xx > 1 then aa else bb, xx, 1, 3);
1055 foo : sum (if equal (xx, 1) then aa else bb, xx, 1, nn);
1056 'sum (if equal (xx, 1) then aa else bb, xx, 1, nn);
1058 ev (foo, nouns, nn=3);
1061 (reset(assume_pos),1);