On Wed, 17 Mar 2021 14:57:57 +0100, Vitaly Magerya <vmagerya@gmail.com> said:
VM> Hi, all. In section 5.7.2 of the docs (Expanding and collecting) VM> there is this example of ginsh usage: >> a=expand((sin(x)+sin(y))*(1+p+q)*(1+d)); collect(a,{p,q}); VM> The docs say I should get this: VM> d*sin(x)+(d*sin(x)+sin(y)+d*sin(y)+sin(x))*p VM> ... but actually: VM> cannot modify multiply referenced object VM> This is with GiNaC V1.7.6, V1.7.8, and the latest commit of VM> V1.8.0. VM> How do I make this work? Running the code from cginac import * x=realsymbol("x") y=realsymbol("y") p=realsymbol("p") q=realsymbol("q") d=realsymbol("d") a=expand((sin(x)+sin(y))*(1+p+q)*(1+d)) print(a.collect([p,q])) with in PyGiNaC [1] with GiNaC 1.8.0 produces: sin(x)+d*sin(x)+q*(sin(x)+d*sin(x)+sin(y)+d*sin(y))+sin(y)+p*(sin(x)+d*sin(x)+sin(y)+d*sin(y))+d*sin(y) Thus, the issue can be with ginsh itself. Do not treat this is an advert of PyGiNaC, but if you are looking for more ginsh-ish behaviour, the previous code can be replaced by: from cginac import * reader=parser() a=reader("(sin(x)+sin(y))*(1+p+q)*(1+d)").expand() print(a.collect([reader("p"),reader("q")])) 1. V.V. Kisil, What is PyGiNaC, anyway?, http://moebinv.sourceforge.net/pyGiNaC.html -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Maps https://doi.org/10.1142/p835 Soft: Geometry of cycles http://moebinv.sourceforge.net/ Jupyter notebooks: https://github.com/vvkisil/MoebInv-notebooks