factor symbolic expression
In the following code, if I add .collect(p)
to the pp*A*qq
in the before last expression, I have an error. Why ?
LE=LatexExpr
x,y,p,q=SR.var('x, y, p, q')
A=matrix(SR,2,2,[x,-x,-x,0])
B=matrix(SR,2,2,[-x,y,x,0])
show(LE(r"\boldsymbol{A} = "),A, LE(r"\,\,\,\,\,\text{et}\,\,\,\,\,"),LE(r"\boldsymbol{B} = "),B)
pp = vector(SR,[p, 1-p])
qq = vector(SR,[q, 1-q])
show(LE(r"\boldsymbol{p} = "),pp, LE(r"\,\,\,\,\,\text{et}\,\,\,\,\,"),LE(r"\boldsymbol{q} = "),qq)
EGe0 = pp*A*qq.collect(p)
show(LE(r"\mathbb{E}G_e^0 = "),EGe0)