Hello,

Looking back at a previous thread (http://groups.google.com/group/sympy/browse_thread/thread/a406176eeb28eb04), an interesting procedure was discussed to place p[i,j,n+1] terms on the LHS of the expression. (Thanks again, Aaron!) As shown in another sample code below, the procedure uses as_independent() with filter and lambda.

I am testing this example code with the main branch of sympy, and I receive the following error:

Traceback (most recent call last):
  File "test-collect-final.py", line 33, in <module>
    main()
  File "test-collect-final.py", line 29, in main
    generate_fdtd(expr,n+1)
  File "test-collect-final.py", line 21, in generate_fdtd
expr3 = expr2.as_independent(*filter(lambda t: t.args[-1] == Idx(n), expr2.atoms(IndexedBase) ) ) File "/usr/local/lib/python2.6/dist-packages/sympy/core/expr.py", line 323, in as_independent
    if term.has(*deps):
File "/usr/local/lib/python2.6/dist-packages/sympy/core/basic.py", line 919, in has
    raise TypeError("has() requires at least 1 argument (got none)")
TypeError: has() requires at least 1 argument (got none)

I understand that IndexedBase is now used instead of IndexedElement in the main branch, and I am wondering if something has changed (or if I am missing something again). What would I have to change to make this code work with the main branch of sympy?

Nicholas


#begin sample code
from sympy import *
from sympy.tensor import Indexed, Idx, IndexedBase
from sympy.matrices import *

p = IndexedBase('p')
var('deltax deltay delta deltat A B')
i,j,n = symbols('i j n', integer = True)


#
# function to generate the FDTD scheme
#
# All p[i,j,n+1] indices should be collected and on the LHS of the expression
def generate_fdtd(expr, nsolve):
    expr0 = expr.lhs - expr.rhs
    expr1 = expr0.expand()
    w1 = Wild('w1',integer=True)
    w2 = Wild('w2',integer=True)
    expr2 = collect(expr1, p[w1, w2, nsolve])
expr3 = expr2.as_independent(*filter(lambda t: t.args[-1] == Idx(n), expr2.atoms(IndexedBase) ) ) # error here
    right = -1 * expr3[0]
    left = expr3[1]
    return Eq(left, right.expand())


def main():
expr = Eq( A*p[1,1,n+1] - B*p[1,1,n], B*p[1,1,n+1] + A*p[1,2,n] + B*p[1,2,n+1] + A*p[1,2,n+1])
    generate_fdtd(expr,n+1)


if __name__ == "__main__":
    main()
# end sample code

--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to