Advertisement
robert_dodier

sum_kron_delta.mac -- kron_delta summation for Maxima

Jul 7th, 2016
4,087
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* sum_kron_delta.mac -- simplify 'sum(f(i)*kron_delta(i, j), i, ...)
  2.  * copyright 2013 by Robert Dodier
  3.  * I release this work under terms of the GNU General Public License
  4.  */
  5.  
  6. put ('sum_kron_delta, true, 'present);
  7.  
  8. matchdeclare (kk, kron_delta_p);
  9. kron_delta_p (e) := not atom(e) and op(e) = 'kron_delta;
  10. matchdeclare (xx, lambda ([e], not kron_delta_p (e)));
  11. matchdeclare (ii, symbolp);
  12. matchdeclare ([ii1, iin], all);
  13.  
  14. simp : false;
  15. tellsimpafter ('sum (kk, ii, ii1, iin), FOO (kk, 1, ii, ii1, iin));
  16. tellsimpafter ('sum (kk * xx, ii, ii1, iin), FOO (kk, xx, ii, ii1, iin));
  17. simp:true;
  18.  
  19. FOO (kk, xx, ii, ii1, iin) := block ([ii_args],
  20.   kk : kron_delta_product (kk),
  21.   ii_args : sublist (args (kk), lambda ([e], not freeof (ii, e))),
  22.   /* just take the first kron_delta variable other than ii -- this is not unique when there are 3 or more variables!! */
  23.   block ([a],
  24.     a : first (delete_all (ii_args, args (kk))),
  25.     /* oops -- what if ii_args has more (or less) than 1 element?? */
  26.     eq : solve (first (ii_args) = a, ii),
  27.     /* oops -- what if eq has more (or less) than 1 element?? */
  28.     buildq
  29.     ([eq,
  30.       S : index_set (ii1, iin),
  31.       kk_xx : subst (eq, kk * xx),
  32.       rhs_eq : rhs (first (eq))],
  33.       if %elementp (rhs_eq, S) then kk_xx else 0)));
  34.  
  35. kron_delta_product (k) := if op(k) = "*" then apply (append, args (k)) else k;
  36. delete_all (L1, L2) := (for x in L1 do L2 : delete (x, L2), L2);
  37. index_set (i, j) := %intersection (%range (i, j), 'integers);
  38.  
  39. matchdeclare (xx, all);
  40. matchdeclare (%ii, lambda ([e], not atom(e) and op(e) = '%intersection));
  41. tellsimp (%elementp (xx, %ii), apply ("and", map (lambda ([S], %elementp (xx, S)), args (%ii))));
  42.  
  43. matchdeclare (ii, lambda ([e], integerp (e) or featurep (e, 'integer)));
  44. tellsimp (%elementp (ii, 'integers), true);
  45. matchdeclare ([aa, bb], all);
  46. tellsimp (%elementp (xx, %range (aa, bb)), aa <= xx and xx <= bb);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement