I'm writing a Python library that deals with symbolic computations of square roots (since approximated ones cause a lot of problems and at least for now correctness is more valuable than performance).
As a part of this I need to be able to simplify square root of sums of square roots, i.e. find if sum of square roots is representable as an another sum of square roots squared: $$ \exists y_j\in \mathbb{Q}_{\gt 0}:\quad\sum_{i=0}^m \sqrt{x_i} = \left( \sum_{j=0}^n \sqrt{y_j} \right)^2 $$ where $x_i \in \mathbb{Q}_{\gt 0}$ are known.
For example: $$ \sqrt{8} + \sqrt{9} = 2\sqrt{2} + 3 = \left(1 + \sqrt{2}\right)^2 = \left(\sqrt{1} + \sqrt{2}\right)^2 $$
After expanding right-hand side $$ \left( \sum_{j=0}^n \sqrt{y_j} \right)^2 = \sum_{j=0}^n y_j + 2 \sum_{j=0}^{n - 1} \sum_{k=j + 1}^{n} \sqrt{y_j} \sqrt{y_k} $$ we can see that it is required for the left-hand side to have one term which is a square root of a perfect square, i.e. a rational number.
I've managed to implement algorithm for two terms, but can't find any general approach, so my question is: does it exist?