# Factor out roots

```
sage: var('a, b, c, d')
sage: trm = 3*(a+b*sqrt(2))+(1+2*sqrt(2))*(c + d*sqrt(2))
sage: trm.expand()
3*sqrt(2)*b + 2*sqrt(2)*c + sqrt(2)*d + 3*a + c + 4*d
```

What could I do if I wanted a result like:

```
(3*b + 2*c + *d)*sqrt(2) + 3*a + c + 4*d
```

And similar, if there were other roots like `sqrt(5)`

, `7^(1/3)`

etc.

Thank you!