On Fri, Nov 23, 2012 at 7:53 AM, dibus2 <[email protected]> wrote:
> Hi ,
> I am working with the tensor module of sympy (0.7.2) python (2.7.1) and I
> am having troubles to replace correctly the tensor objects :
>
> For instance if I have a tensor L :
>
> L = IndexedBase('L')
>
> and two indicies a,b:
>
> a,b = map(Idx,['a','b'])
>
You can just do map(Idx, 'ab'), or, better, symbols('a b', cls=Idx)
>
> Now I construc the following expression :
>
> exp = 2*L[a,b]
>
> If I want to replace L[a,b] in my expression in a general way using
> matching pattern ( I assuming there other terms ), I can do :
> p,q = map(Wild,['p','q']
> exp = exp.replace(L[p,q],p)
>
> I got >> 2*a
>
> The problem arise when I have one of the indices that has a definite
> value, 1 for instance. Let's assume I now have
> exp = 2*L[1,0] and I still want to replace it
>
> exp.replace(L[p,q],p)
>
> would rise an error :
> >>AttributeError: 'int' object has no attribute 'args'
>
Whenever you get an error that is not NotImplementedError, especially if
it's a builtin exception, that is a good sign that you have come across a
bug. In this case, the bug is that IndexedBase doesn't sympify it's
arguments. The workaround is to manually wrap your numbers with sympify().
You can use the shortcut S():
In [9]: exp = 2*L[S(1),S(0)]
In [10]: exp.replace(L[p,q],p)
Out[10]: 2
I opened https://code.google.com/p/sympy/issues/detail?id=3531 for the
issue. It should be very easy to fix.
Aaron Meurer
> In principle if I know what are the values (1 and 0) I can use subs
> exp = exp.subs(L[1,0],1)
> >>2
> But I want to be able to use the matching and therefore subs does not
> work.
> Does anyone knows how I could go around this ?
>
> Thanks
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/Won4heE3S2MJ.
> 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.
>
--
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.