On Fri, 25 Apr 2025 at 02:31, Matthew Samuel <matthemat...@gmail.com> wrote: > > I'm reaching out because I'm running into issues that should be pretty > elementary if I were doing it right. For example, the best representation of > linear combinations of Schubert polynomials is as a dict of coefficients of > basis elements, but there are some times when they need to be left > uncombined, but then you should be able to add to the uncombined terms and > combine with the cominable ones. sympy does automatically do that, for > example, > > >>> DSx([3,4,1,2]) + DSx([4,1,3,2],"z") > DSx((3, 4, 1, 2), y) + DSx((4, 1, 3, 2), z) > > This is sympy.Add, not a DoubleSchubertAlgebraElement, because the sets of > coefficient variables, y and z, are different. This is what I want. When we > do this, however, > > >>> DSx([3,4,1,2]) + DSx([4,1,3,2],"z") + DSx([3,4,1,2]) > 2*DSx((3, 4, 1, 2), y) + DSx((4, 1, 3, 2), z) > > This looks correct, however that 2*DSx((3, 4, 1, 2), y) is a sympy.Mul > object, when what I want is for it to be internally represented as > {(3,4,1,2): 2}, which it is not. > > I feel like this is similar to the Poly class being a subclass of Basic > instead of Expr, but I don't know if I want to be that rigid. And combining > terms as Expr alone is inefficient. These can have hundreds or thousands of > terms after multiplying, and the hashmap of keys is the most efficient way to > combine coefficients.
My first thought is that you should probably use something more like Poly rather than Expr here. Combining as Expr alone will be inefficient. Does a typical calculation here use a closed finite set of DSx elements? If so you could use e.g. a sparse matrix to represent the linear combination. > I guess this is a question? What's the most elegant way to get that 2 into > that dict? If you are working with Expr then you probably just want to use something like Expr.replace. -- Oscar -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/sympy/CAHVvXxSYsJ_YNEn1O38DcJbFx4g7ojtmg%3D_xp6qHGhCbWyeGPQ%40mail.gmail.com.