Ask Your Question

Revision history [back]

click to hide/show revision 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:

  1. 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
  2. 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.

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