1

Let's consider the following function I've already mentioned in my previous question:

   rot[i](f) := sum(sum(sum(sum(
      G[r,i]*G[q,j]*W[i,j,k]*('diff(f[k], y[q]) + sum(K[k,q,m]*f[m], m, 1, N)),
          r, 1, N),
          j, 1, N),
          k, 1, N),
          q, 1, N) $

It kind of works in general, but what if original expression f already contains symbols r, j, and so on? In this case it doesn't do the right thing. The only solution I've found so far is to use some unique prefix for these symbols or at least start their names with underscores: r__r, j__j. But I hope there should be a more idiomatic solution. Is there anything?

Community
  • 1
  • 1
firegurafiku
  • 3,017
  • 1
  • 28
  • 37

1 Answers1

1

Unfortunately, in Maxima all symbols are effectively global -- the x in some expression is the same symbol as the x in f(x) := .... So there is no general way to ensure that function arguments are distinguished from other symbols of the same name. Some functions attempt to make their arguments local, e.g., sum treats the index variable specially, but integrate does not.

I made an attempt to make a lexical block construct which would make it possible to distinguish symbols of the same name. It is called blex and I think a web search should find it, if not, let me know and I'll post a link.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
  • That's sad. I think I'll stick to prefixes or underscores for now. – firegurafiku Aug 01 '15 at 18:28
  • Yes, I think for now that choosing unusual names to avoid name collisions is a workable solution. The good news is that I think that implementing lexical symbols might be not too much work, actually, and I'm pretty sure that very few programs actually require dynamic scope to work correctly, so changing to lexical scope might be not too hard to put into practice. – Robert Dodier Aug 03 '15 at 21:20