Ask Your Question

factor symbolic expression

asked 2021-04-25 16:47:57 +0200

Cyrille gravatar image

In the following code, if I add .collect(p) to the pp*A*qq in the before last expression, I have an error. Why ?

x,y,p,q=SR.var('x, y, p, q')
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)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-04-25 17:33:02 +0200

Max Alekseyev gravatar image

Adding parentheses does the job:

EGe0 = (pp*A*qq).collect(p)

edit flag offensive delete link more


Thanks but I have an other problem y is not recognized as a variable. I don't undersand since itis decalred. I have tried without comas. But nothing work so I can't see the effect of the parenthesis.

Cyrille gravatar imageCyrille ( 2021-04-25 17:58:13 +0200 )edit

I'm not sure what problem you are talking about as your code runs without an issue at Sagecell:

Max Alekseyev gravatar imageMax Alekseyev ( 2021-04-25 18:30:58 +0200 )edit

Thanks it works

Cyrille gravatar imageCyrille ( 2021-04-25 22:28:27 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-04-25 16:47:57 +0200

Seen: 33 times

Last updated: Apr 25