1 | initial version |

The function `coefficients`

may help you, though it is not exactly what you requested for at least three reasons:

```
sage: e = trm.expand()
sage: e.coefficients(sqrt(2))
[[2*sqrt(2)*c + 3*a + c + 4*d, 0], [3*b + d, 1]]
```

The three problems:

It is not written in the same way as you want, but you can obtain a closer expression like this:

`sage: sum([cc[0] * sqrt(2)^cc[1] for cc in c]) sqrt(2)*(3*b + d) + 2*sqrt(2)*c + 3*a + c + 4*d`

The second, more disturbing problem, is that

`coefficients`

seem not to produce what we would like in this case. In particular, we would like to have`sage: e.coefficients(sqrt(2)) [[3*a + c + 4*d, 0], [2*c + 3*b + d, 1]]`

I do not now why this is not the case. It may be a bug.

Finally, this works for only one square root as such. Maybe some modification can yield the result with several square roots.

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.