On Sun, Dec 2, 2012 at 9:46 AM, Chris Smith <smi...@gmail.com> wrote: > I don't follow you...if the function or Indexed has a different name then > it's different from others, and if the argument(s) of any function or > Indexed are different they represent different objects. > >>>> eqs=Tuple(f(1,2)+f(i)-3,f(1,2)-f(i)-4) >>>> solve(eqs, eqs.atoms(Function)) > {f(i): -1/2, f(1, 2): 7/2}
But as I said in my previous mail, I would expect a subscripted symbol (which IndexedBase intends to be) to be treated as a first-classs symbolic object equal to i,j etc without resorting to any additional effort like atoms, dummies, zip etc. On Sun, Dec 2, 2012 at 4:14 PM, Chris Smith <smi...@gmail.com> wrote: > What about this? > class Syms(object): > def __new__(cls, name): > obj = object.__new__(cls) > obj.name = name > return obj > def __getitem__(self, *i): > return Indexed(self.name, *i) > def __call__(self, *i): > return Indexed(self.name, *i) > >>>> eqs=Tuple(a[i]+a[j]-3,a[i]-a[j]+4) >>>> idx=eqs.atoms(Indexed) >>>> dum=[Dummy() for ii in idx] # don't use i as loop variable >>>> Dict(solve(eqs.subs(zip(idx, dum)), dum)).subs(zip(dum,idx)) > {a[i]: -1/2, a[j]: 7/2} >>>> Sum(a[i],(i,1,4)) > Sum(a[i], (i, 1, 4)) >>>> _.doit() > a[1] + a[2] + a[3] + a[4] But the above still needs all that atoms and dummies and subs and zip stuff stuff! :-( Too complicated for what should be elementary usage. And I did myself try your suggeested implementation, but observe my comments inlined: from sympy import Indexed class SymList ( object ) : def __new__ ( cls, name ) : obj = object . __new__ ( cls ) obj . name = name return obj def __getitem__ ( self, * i ) : return Indexed ( self . name, * i ) def __call__ ( self, * i ) : return Indexed ( self . name, * i ) Sorry if I am mistaken but the above seems little more than a thin wrapper around Indexed. What does it provide that Indexed does not? a=SymList('a') a[1] Out[4]: a[1] a(1) Out[5]: a[1] So far so good, but see: from sympy import symbols i,j=symbols('i,j') a[i,j] Out[8]: a[(i, j)] a(i,j) Out[9]: a[i, j] This discrepancy is an infecility: if for single items you provide [] and () as equal (which is not necessary and IMHO [] would be enough) then the same must be true for tuples, but a[i,j] reads *args as a tuple of a tuple (of i and j), whereas a(i,j) reads *args as a tuple of i and j. from sympy import solve solve([a[i]+a[j]-3,a[i]-a[j]+4]) Out[12]: [] :-( So still my desired behaviour doesn't happen... Sorry for being persistent, but really I'd very much like to use some like (hopefully IndexedBase) in this manner without resorting to "tricks" like atoms, dummies etc etc. I hope it would not be a serious problem to provide that in SymPy. Since subscripted (i.e. indexed) variables (and in some case even super+sub-scripted or i.o.w. multi-index variables) are widely used in mathematics I hope I would not be the only person to be benefited. -- Shriramana Sharma -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.