Average Error: 37.3 → 18.1
Time: 22.9s
Precision: 64
Internal precision: 128
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;y \le -1.2461039277906793 \cdot 10^{+90}:\\
\;\;\;\;-y\\
\mathbf{if}\;y \le -3833755296400741.5:\\
\;\;\;\;x\\
\mathbf{if}\;y \le 2.7533805383758474 \cdot 10^{+165}:\\
\;\;\;\;\sqrt{{y}^2 + \left({z}^2 + x \cdot x\right)}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}\]
Target
| Original | 37.3 |
| Comparison | 29.0 |
| Herbie | 18.1 |
\[ \begin{array}{l}
\mathbf{if}\;z \lt -6.396479394109776 \cdot 10^{+136}:\\
\;\;\;\;-z\\
\mathbf{if}\;z \lt 7.320293694404182 \cdot 10^{+117}:\\
\;\;\;\;\sqrt{\left({z}^2 + {x}^2\right) + {y}^2}\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array} \]
Derivation
- Split input into 4 regimes.
-
if y < -1.2461039277906793e+90
Initial program 51.4
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
Applied simplify 51.4
\[\leadsto \color{blue}{\sqrt{{y}^2 + \left({z}^2 + x \cdot x\right)}}\]
Applied taylor 0
\[\leadsto -1 \cdot y\]
Taylor expanded around -inf 0
\[\leadsto \color{blue}{-1 \cdot y}\]
Applied simplify 0
\[\leadsto \color{blue}{-y}\]
if -1.2461039277906793e+90 < y < -3833755296400741.5
Initial program 58.2
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
Applied simplify 58.2
\[\leadsto \color{blue}{\sqrt{{y}^2 + \left({z}^2 + x \cdot x\right)}}\]
Applied taylor 0
\[\leadsto x\]
Taylor expanded around 0 0
\[\leadsto \color{blue}{x}\]
if -3833755296400741.5 < y < 2.7533805383758474e+165
Initial program 27.7
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
Applied simplify 27.7
\[\leadsto \color{blue}{\sqrt{{y}^2 + \left({z}^2 + x \cdot x\right)}}\]
if 2.7533805383758474e+165 < y
Initial program 59.5
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
Applied simplify 59.5
\[\leadsto \color{blue}{\sqrt{{y}^2 + \left({z}^2 + x \cdot x\right)}}\]
Applied taylor 0
\[\leadsto y\]
Taylor expanded around inf 0
\[\leadsto \color{blue}{y}\]
- Recombined 4 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie --seed '#(1911028787 4173371268 2724411631 1922811693 3973967741 3489382408)'
(FPCore (x y z)
:name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
:target
(if (< z -6.396479394109776e+136) (- z) (if (< z 7.320293694404182e+117) (sqrt (+ (+ (sqr z) (sqr x)) (sqr y))) z))
(sqrt (+ (+ (* x x) (* y y)) (* z z))))