Average Error: 37.4 → 18.3
Time: 27.0s
Precision: 64
Internal precision: 128
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;y \le -1.2461039277906793 \cdot 10^{+90}:\\
\;\;\;\;\left(-y\right) \cdot \sqrt{0.3333333333333333}\\
\mathbf{if}\;y \le -3833755296400741.5:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot x\\
\mathbf{if}\;y \le 2.7533805383758474 \cdot 10^{+165}:\\
\;\;\;\;\sqrt{{y}^2 + \left({z}^2 + x \cdot x\right)} \cdot \sqrt{\frac{1}{3.0}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot y\\
\end{array}\]
Target
| Original | 37.4 |
| Comparison | 29.2 |
| Herbie | 18.3 |
\[ \begin{array}{l}
\mathbf{if}\;z \lt -6.396479394109776 \cdot 10^{+136}:\\
\;\;\;\;\frac{-z}{\sqrt{3.0}}\\
\mathbf{if}\;z \lt 7.320293694404182 \cdot 10^{+117}:\\
\;\;\;\;\frac{\sqrt{\left({z}^2 + {x}^2\right) + {y}^2}}{\sqrt{3.0}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot z\\
\end{array} \]
Derivation
- Split input into 4 regimes.
-
if y < -1.2461039277906793e+90
Initial program 51.5
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
Applied simplify 51.5
\[\leadsto \color{blue}{\sqrt{\frac{{y}^2 + \left({z}^2 + x \cdot x\right)}{3.0}}}\]
Applied taylor 0.2
\[\leadsto -1 \cdot \left(\sqrt{0.3333333333333333} \cdot y\right)\]
Taylor expanded around -inf 0.2
\[\leadsto \color{blue}{-1 \cdot \left(\sqrt{0.3333333333333333} \cdot y\right)}\]
Applied simplify 0.2
\[\leadsto \color{blue}{\left(-y\right) \cdot \sqrt{0.3333333333333333}}\]
if -1.2461039277906793e+90 < y < -3833755296400741.5
Initial program 58.2
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
Applied simplify 58.2
\[\leadsto \color{blue}{\sqrt{\frac{{y}^2 + \left({z}^2 + x \cdot x\right)}{3.0}}}\]
Applied taylor 0.2
\[\leadsto \sqrt{0.3333333333333333} \cdot x\]
Taylor expanded around 0 0.2
\[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot x}\]
if -3833755296400741.5 < y < 2.7533805383758474e+165
Initial program 27.8
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
Applied simplify 27.8
\[\leadsto \color{blue}{\sqrt{\frac{{y}^2 + \left({z}^2 + x \cdot x\right)}{3.0}}}\]
- Using strategy
rm
Applied div-inv 27.8
\[\leadsto \sqrt{\color{blue}{\left({y}^2 + \left({z}^2 + x \cdot x\right)\right) \cdot \frac{1}{3.0}}}\]
Applied sqrt-prod 27.9
\[\leadsto \color{blue}{\sqrt{{y}^2 + \left({z}^2 + x \cdot x\right)} \cdot \sqrt{\frac{1}{3.0}}}\]
if 2.7533805383758474e+165 < y
Initial program 59.6
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3.0}}\]
Applied simplify 59.6
\[\leadsto \color{blue}{\sqrt{\frac{{y}^2 + \left({z}^2 + x \cdot x\right)}{3.0}}}\]
Applied taylor 0.2
\[\leadsto \sqrt{0.3333333333333333} \cdot y\]
Taylor expanded around inf 0.2
\[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot y}\]
- Recombined 4 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie --seed '#(851321798 3617685590 4011722190 1634036316 762064292 2712077172)'
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"
:target
(if (< z -6.396479394109776e+136) (/ (- z) (sqrt 3.0)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (sqr z) (sqr x)) (sqr y))) (sqrt 3.0)) (* (sqrt 0.3333333333333333) z)))
(sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))