Average Error: 29.7 → 0.3
Time: 2.8s
Precision: binary64
Cost: 39105
\[\sqrt{x \cdot x + x \cdot x}\]
↓
\[\begin{array}{l}
\mathbf{if}\;x \leq -1.52521227020015 \cdot 10^{-310}:\\
\;\;\;\;-x \cdot \sqrt{2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\sqrt{\sqrt{2}}} \cdot \left(x \cdot {\left(\sqrt{\sqrt{2}}\right)}^{1.5}\right)\\
\end{array}\]
\sqrt{x \cdot x + x \cdot x}↓
\begin{array}{l}
\mathbf{if}\;x \leq -1.52521227020015 \cdot 10^{-310}:\\
\;\;\;\;-x \cdot \sqrt{2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\sqrt{\sqrt{2}}} \cdot \left(x \cdot {\left(\sqrt{\sqrt{2}}\right)}^{1.5}\right)\\
\end{array}(FPCore (x) :precision binary64 (sqrt (+ (* x x) (* x x))))
↓
(FPCore (x)
:precision binary64
(if (<= x -1.52521227020015e-310)
(- (* x (sqrt 2.0)))
(* (sqrt (sqrt (sqrt 2.0))) (* x (pow (sqrt (sqrt 2.0)) 1.5)))))
double code(double x) {
return sqrt((x * x) + (x * x));
}
↓
double code(double x) {
double tmp;
if (x <= -1.52521227020015e-310) {
tmp = -(x * sqrt(2.0));
} else {
tmp = sqrt(sqrt(sqrt(2.0))) * (x * pow(sqrt(sqrt(2.0)), 1.5));
}
return tmp;
}
Try it out
Enter valid numbers for all inputs
Alternatives
| Alternative 1 |
|---|
| Error | 30.5 |
|---|
| Cost | 51648 |
|---|
\[\left(\left(x \cdot \sqrt{\sqrt{2}}\right) \cdot \left|\sqrt[3]{\sqrt{2}}\right|\right) \cdot \sqrt{\sqrt[3]{\sqrt{2}}}\]
| Alternative 2 |
|---|
| Error | 30.3 |
|---|
| Cost | 39488 |
|---|
\[\sqrt[3]{\sqrt{x \cdot \left(x + x\right)}} \cdot \left(\sqrt[3]{\sqrt{x \cdot \left(x + x\right)}} \cdot \sqrt[3]{\sqrt{x \cdot \left(x + x\right)}}\right)\]
| Alternative 3 |
|---|
| Error | 31.0 |
|---|
| Cost | 39104 |
|---|
\[\sqrt[3]{x \cdot \sqrt{2}} \cdot \left(\sqrt[3]{x \cdot \sqrt{2}} \cdot \sqrt[3]{x \cdot \sqrt{2}}\right)\]
| Alternative 4 |
|---|
| Error | 30.5 |
|---|
| Cost | 38848 |
|---|
\[\sqrt[3]{\sqrt{2}} \cdot \left(x \cdot \left(\sqrt[3]{\sqrt{2}} \cdot \sqrt[3]{\sqrt{2}}\right)\right)\]
| Alternative 5 |
|---|
| Error | 31.4 |
|---|
| Cost | 38848 |
|---|
\[\left(\sqrt{\sqrt{2}} \cdot \sqrt{x}\right) \cdot \left(\sqrt{\sqrt{2}} \cdot \sqrt{x}\right)\]
| Alternative 6 |
|---|
| Error | 30.4 |
|---|
| Cost | 38784 |
|---|
\[\sqrt{\sqrt{\sqrt{2}}} \cdot \left(x \cdot {\left(\sqrt{\sqrt{2}}\right)}^{1.5}\right)\]
| Alternative 7 |
|---|
| Error | 30.4 |
|---|
| Cost | 32512 |
|---|
\[\left(x \cdot {\left(2 \cdot \sqrt{2}\right)}^{0.25}\right) \cdot \sqrt{\sqrt{\sqrt{2}}}\]
| Alternative 8 |
|---|
| Error | 31.3 |
|---|
| Cost | 26048 |
|---|
\[\sqrt{x \cdot \sqrt{2}} \cdot \sqrt{x \cdot \sqrt{2}}\]
| Alternative 9 |
|---|
| Error | 30.5 |
|---|
| Cost | 25920 |
|---|
\[\sqrt{\sqrt{2}} \cdot \left(x \cdot \sqrt{\sqrt{2}}\right)\]
| Alternative 10 |
|---|
| Error | 45.9 |
|---|
| Cost | 19584 |
|---|
\[\frac{\sqrt{2 \cdot {x}^{4}}}{\left|x\right|}\]
| Alternative 11 |
|---|
| Error | 40.4 |
|---|
| Cost | 19584 |
|---|
\[\sqrt[3]{{\left(\sqrt{x \cdot \left(x + x\right)}\right)}^{3}}\]
| Alternative 12 |
|---|
| Error | 32.1 |
|---|
| Cost | 19520 |
|---|
\[e^{\log \left(\sqrt{x \cdot \left(x + x\right)}\right)}\]
| Alternative 13 |
|---|
| Error | 31.3 |
|---|
| Cost | 19520 |
|---|
\[\sqrt{x} \cdot \left(\sqrt{2} \cdot \sqrt{x}\right)\]
| Alternative 14 |
|---|
| Error | 51.2 |
|---|
| Cost | 19456 |
|---|
\[\sqrt[3]{{\left(x \cdot \sqrt{2}\right)}^{3}}\]
| Alternative 15 |
|---|
| Error | 31.2 |
|---|
| Cost | 13120 |
|---|
\[\sqrt{x} \cdot \sqrt{x + x}\]
| Alternative 16 |
|---|
| Error | 29.7 |
|---|
| Cost | 6848 |
|---|
\[\sqrt{x \cdot x + x \cdot x}\]
| Alternative 17 |
|---|
| Error | 29.7 |
|---|
| Cost | 6720 |
|---|
\[\sqrt{x \cdot \left(x + x\right)}\]
| Alternative 18 |
|---|
| Error | 32.5 |
|---|
| Cost | 6656 |
|---|
\[-x \cdot \sqrt{2}\]
| Alternative 19 |
|---|
| Error | 30.5 |
|---|
| Cost | 6592 |
|---|
\[x \cdot \sqrt{2}\]
| Alternative 20 |
|---|
| Error | 60.5 |
|---|
| Cost | 64 |
|---|
\[1\]
| Alternative 21 |
|---|
| Error | 61.6 |
|---|
| Cost | 64 |
|---|
\[0\]
| Alternative 22 |
|---|
| Error | 62.9 |
|---|
| Cost | 64 |
|---|
\[-1\]
Error

Derivation
- Split input into 2 regimes
if x < -1.525212270200155e-310
Initial program 29.2
\[\sqrt{x \cdot x + x \cdot x}\]
Simplified29.2
\[\leadsto \color{blue}{\sqrt{x \cdot \left(x + x\right)}}\]
Taylor expanded around -inf 0.4
\[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{2}\right)}\]
Simplified0.4
\[\leadsto \color{blue}{-x \cdot \sqrt{2}}\]
Simplified0.4
\[\leadsto \color{blue}{-x \cdot \sqrt{2}}\]
if -1.525212270200155e-310 < x
Initial program 30.2
\[\sqrt{x \cdot x + x \cdot x}\]
Simplified30.2
\[\leadsto \color{blue}{\sqrt{x \cdot \left(x + x\right)}}\]
Taylor expanded around 0 0.4
\[\leadsto \color{blue}{x \cdot \sqrt{2}}\]
- Using strategy
rm Applied add-sqr-sqrt_binary64_930.6
\[\leadsto x \cdot \color{blue}{\left(\sqrt{\sqrt{2}} \cdot \sqrt{\sqrt{2}}\right)}\]
Applied associate-*r*_binary64_110.5
\[\leadsto \color{blue}{\left(x \cdot \sqrt{\sqrt{2}}\right) \cdot \sqrt{\sqrt{2}}}\]
- Using strategy
rm Applied add-sqr-sqrt_binary64_930.5
\[\leadsto \left(x \cdot \sqrt{\sqrt{2}}\right) \cdot \color{blue}{\left(\sqrt{\sqrt{\sqrt{2}}} \cdot \sqrt{\sqrt{\sqrt{2}}}\right)}\]
Applied associate-*r*_binary64_110.4
\[\leadsto \color{blue}{\left(\left(x \cdot \sqrt{\sqrt{2}}\right) \cdot \sqrt{\sqrt{\sqrt{2}}}\right) \cdot \sqrt{\sqrt{\sqrt{2}}}}\]
Simplified0.3
\[\leadsto \color{blue}{\left(x \cdot {\left(\sqrt{\sqrt{2}}\right)}^{1.5}\right)} \cdot \sqrt{\sqrt{\sqrt{2}}}\]
Simplified0.3
\[\leadsto \color{blue}{\sqrt{\sqrt{\sqrt{2}}} \cdot \left(x \cdot {\left(\sqrt{\sqrt{2}}\right)}^{1.5}\right)}\]
- Recombined 2 regimes into one program.
Final simplification0.3
\[\leadsto \begin{array}{l}
\mathbf{if}\;x \leq -1.52521227020015 \cdot 10^{-310}:\\
\;\;\;\;-x \cdot \sqrt{2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\sqrt{\sqrt{2}}} \cdot \left(x \cdot {\left(\sqrt{\sqrt{2}}\right)}^{1.5}\right)\\
\end{array}\]
Reproduce
herbie shell --seed 2021042
(FPCore (x)
:name "sqrt A"
:precision binary64
(sqrt (+ (* x x) (* x x))))