\[ \begin{array}{c}[x, y, z] = \mathsf{sort}([x, y, z])\\ \end{array} \]
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\]
↓
\[\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-58}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-38}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \cdot x \leq 6 \cdot 10^{+63}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+91}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+104}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\]
(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
↓
(FPCore (x y z)
:precision binary64
(if (<= (* x x) 5e-58)
z
(if (<= (* x x) 2e-38)
(- x)
(if (<= (* x x) 6e+63)
z
(if (<= (* x x) 5e+91)
(sqrt (+ (+ (* x x) (* y y)) (* z z)))
(if (<= (* x x) 5e+104) z (- x)))))))
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = sqrt((((x * x) + (y * y)) + (z * z)))
end function
↓
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x * x) <= 5d-58) then
tmp = z
else if ((x * x) <= 2d-38) then
tmp = -x
else if ((x * x) <= 6d+63) then
tmp = z
else if ((x * x) <= 5d+91) then
tmp = sqrt((((x * x) + (y * y)) + (z * z)))
else if ((x * x) <= 5d+104) then
tmp = z
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return Math.sqrt((((x * x) + (y * y)) + (z * z)));
}
if (*.f64 x x) < 4.99999999999999977e-58 or 1.9999999999999999e-38 < (*.f64 x x) < 5.99999999999999998e63 or 5.0000000000000002e91 < (*.f64 x x) < 4.9999999999999997e104
Initial program 27.1
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\]
Taylor expanded in z around inf 11.7
\[\leadsto \color{blue}{z}
\]
if 4.99999999999999977e-58 < (*.f64 x x) < 1.9999999999999999e-38 or 4.9999999999999997e104 < (*.f64 x x)
Initial program 48.5
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\]
Taylor expanded in x around -inf 14.1
\[\leadsto \color{blue}{-1 \cdot x}
\]
Simplified14.1
\[\leadsto \color{blue}{-x}
\]
Proof
[Start]14.1
\[ -1 \cdot x
\]
rational_best-simplify-2 [=>]14.1
\[ \color{blue}{x \cdot -1}
\]
rational_best-simplify-12 [=>]14.1
\[ \color{blue}{-x}
\]
if 5.99999999999999998e63 < (*.f64 x x) < 5.0000000000000002e91
Initial program 18.7
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\]
Recombined 3 regimes into one program.
Final simplification13.1
\[\leadsto \begin{array}{l}
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-58}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-38}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \cdot x \leq 6 \cdot 10^{+63}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+91}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\
\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+104}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\]
herbie shell --seed 2023092
(FPCore (x y z)
:name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
:precision binary64
:herbie-target
(if (< z -6.396479394109776e+136) (- z) (if (< z 7.320293694404182e+117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))
(sqrt (+ (+ (* x x) (* y y)) (* z z))))