1 | initial version |

A few solutions (there may well be others, which I'm too (lazy|dumb) to think of) :

```
p1, p2 = var("p1, p2")
A1 = matrix(QQ, [[1, -1], [-1, 1]])
# Use a vector rather than a 2x1 matrix (cleaner...)
P1 = vector(SR, [p1, p2])
# Using a constraint
with assuming(P1.norm()==1): res = (P2*A1*P2).simplify_full()
# Better ?
with assuming(P1.norm()==1): resf = (P2*A1*P2).factor()
# One can also "brute force" an explicit substitution
# First solution : substitute before computing
P2 = vector(map(lambda u:u.subs(solve(p1 + p2 == 1, p2)[0]), P1))
res1 = (P2*A1*P2).simplify_full()
res1f = res1.factor()
# Second solution : substitute after computing
res2 = (P1*A1*P1).subs((p1 + p2==1).solve(p2)[0]).simplify_full()
res2f = res2.factor()
```

Checks :

```
sage: res, resf, res1, res1f, res2, res2f
(4*p1^2 - 4*p1 + 1,
(2*p1 - 1)^2,
4*p1^2 - 4*p1 + 1,
(2*p1 - 1)^2,
4*p1^2 - 4*p1 + 1,
(2*p1 - 1)^2)
```

HTH,

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.