Algorithm for dividing sums of square roots: $\tfrac{\sum_{i=1}^m \sqrt{x_i}}{\sum_{j=1}^n \sqrt{y_j}}$

163 Views Asked by At

As a part of a project for supporting symbolic computation of square roots (since using any sort of approximated calculation ends up accumulating errors after several iterations) I'm trying to implement an algorithm for division of sums of square roots, i.e. expression like $$ \frac{\sum_{i=1}^m \sqrt{x_i}}{\sum_{j=1}^n \sqrt{y_j}} $$ where $x_i, y_j \in \mathbb{Q}$.
We can assume that $n > 2$ since $n = 1$ is trivial and $n = 2$ can be solved by multiplying both numerator & denominator by $\sqrt{y_1} - \sqrt{y_2}$.

For example if we have expression $$ \mathrm{expr} := \sqrt{2} + \sqrt{3} + \sqrt{5} $$ when we square it $$ \mathrm{expr}^2 = 2\sqrt{15} + 2\sqrt{10} + 2\sqrt{6} + 10 $$ and divide by the original one we should have it as a result of the division so $$ \frac{2\sqrt{15} + 2\sqrt{10} + 2\sqrt{6} + 10}{\sqrt{2} + \sqrt{3} + \sqrt{5}} = \sqrt{2} + \sqrt{3} + \sqrt{5} $$

I think there is an algorithm for this particular task (since WolframAlpha is capable of doing so), but I couldn't find it online, so any help would be appreciated.

Edit

If I understood correctly the approach described by @Empy2 we can iteratively multiply by $\sum_{j=1}^{n-1} \sqrt{y_j} - \sqrt{y_n}$, but this won't work for 4 terms, because after multiplication total number of terms will be $\tfrac{(n - 1)(n - 2)}{2} + 1$ which increases for $n > 3$. For $n = 4$ we can multiply both numerator & denominator by $(\sqrt{y_1} + \sqrt{y_2}) - (\sqrt{y_3} + \sqrt{y_4})$ leading us to the case with $n = 3$, but that's it, for $n > 4$ I'm not aware of any working algorithm.

1

There are 1 best solutions below

3
On

$$f=\sqrt2+\sqrt3+\sqrt5+\sqrt7+\sqrt{11}\\ g=(\sqrt2+\sqrt3+\sqrt5+\sqrt7)^2-(\sqrt{11})^2\\ =6+2(\sqrt6+\sqrt{10}+\sqrt{14}+\sqrt{15}+\sqrt{21}+\sqrt{35})\\ =2(3+\sqrt6+\sqrt{10}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