Thanks for the help, but I'm still stuck! > create GeneratingFunction.__new__() with your own arguments and then > call Poly.__new__() from it, with any preprocessing that you need.
This is what I've got so far: ====== generating_functions.py ======== from sympy import Poly X = Symbol('X') class GeneratingFunction(Poly): def __new__(cls,*coefficients,**kwargs): normalization_factor = float(sum(coefficients)) if normalization_factor: normalized_coefficients = tuple(map (lambda c: sympify(c / normalization_factor), coefficients)) else: normalized_coefficients = coefficients monomials = tuple(map(lambda i: (i,),xrange(len(coefficients)))) gf = Poly.__new__(cls,zip (normalized_coefficients,monomials),X,**kwargs) gf.coefficients = normalized_coefficients return gf ===== end generating_functions.py ====== >>> from generating_functions import GeneratingFunction >>> gf = GeneratingFunction(10,4,4,2) >>> gf = GeneratingFunction(10,4,4,2) >>> gf(1) 1.00000000000000 >>> two_moment = gf * gf Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.5/site-packages/sympy/sympy/polys/ polynomial.py", line 952, in __mul__ self, poly = self.unify_with(other) File "/usr/local/lib/python2.5/site-packages/sympy/sympy/polys/ polynomial.py", line 1525, in unify_with other = cls(other, *symbols, **flags) File "generating_functions.py", line 34, in __new__ normalization_factor = float(sum(coefficients)) File "/usr/local/lib/python2.5/site-packages/sympy/sympy/polys/ polynomial.py", line 867, in __add__ self, poly = self.unify_with(other) File "/usr/local/lib/python2.5/site-packages/sympy/sympy/polys/ polynomial.py", line 1525, in unify_with other = cls(other, *symbols, **flags) File "generating_functions.py", line 34, in __new__ normalization_factor = float(sum(coefficients)) File "/usr/local/lib/python2.5/site-packages/sympy/sympy/core/ basic.py", line 1954, in __float__ raise ValueError("Symbolic value, can't compute") ValueError: Symbolic value, can't compute >>> It seems that GeneratingFunction.__new__ is being called internally with different arguments than I expect whenever arithmetic operations are called. > > Can I get the functionality I want by forcing > > GeneratingFunction.__new__ to perform all the same checks and magic on > > its argument that Poly.__new__ is already doing? Is there an easier > > way? It seems like the above is the only thing I can do! The Poly class can be instantiated using a few different calling schemes (lists, tuples, dictionaries, &c.) and I'm going to have to anticipate each scheme and extract the parameters I want from it, all in GeneratingFunction.__new__. Is this correct? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---