| Alternative 1 | |
|---|---|
| Error | 12.8 |
| Cost | 260 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{+58}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\]
(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z) :precision binary64 (if (<= z 6.6e-29) (- x) (if (<= z 4.05e+49) (sqrt (+ (+ (* x x) (* y y)) (* z z))) z)))
double code(double x, double y, double z) {
return sqrt((((x * x) + (y * y)) + (z * z)));
}
double code(double x, double y, double z) {
double tmp;
if (z <= 6.6e-29) {
tmp = -x;
} else if (z <= 4.05e+49) {
tmp = sqrt((((x * x) + (y * y)) + (z * z)));
} else {
tmp = z;
}
return tmp;
}
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 (z <= 6.6d-29) then
tmp = -x
else if (z <= 4.05d+49) then
tmp = sqrt((((x * x) + (y * y)) + (z * z)))
else
tmp = z
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)));
}
public static double code(double x, double y, double z) {
double tmp;
if (z <= 6.6e-29) {
tmp = -x;
} else if (z <= 4.05e+49) {
tmp = Math.sqrt((((x * x) + (y * y)) + (z * z)));
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): return math.sqrt((((x * x) + (y * y)) + (z * z)))
def code(x, y, z): tmp = 0 if z <= 6.6e-29: tmp = -x elif z <= 4.05e+49: tmp = math.sqrt((((x * x) + (y * y)) + (z * z))) else: tmp = z return tmp
function code(x, y, z) return sqrt(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z))) end
function code(x, y, z) tmp = 0.0 if (z <= 6.6e-29) tmp = Float64(-x); elseif (z <= 4.05e+49) tmp = sqrt(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z))); else tmp = z; end return tmp end
function tmp = code(x, y, z) tmp = sqrt((((x * x) + (y * y)) + (z * z))); end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 6.6e-29) tmp = -x; elseif (z <= 4.05e+49) tmp = sqrt((((x * x) + (y * y)) + (z * z))); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := N[Sqrt[N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[z, 6.6e-29], (-x), If[LessEqual[z, 4.05e+49], N[Sqrt[N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], z]]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;z \leq 6.6 \cdot 10^{-29}:\\
\;\;\;\;-x\\
\mathbf{elif}\;z \leq 4.05 \cdot 10^{+49}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
Results
| Original | 37.9 |
|---|---|
| Target | 19.5 |
| Herbie | 11.8 |
if z < 6.60000000000000055e-29Initial program 29.8
Taylor expanded in x around -inf 7.9
Simplified7.9
[Start]7.9 | \[ -1 \cdot x
\] |
|---|---|
rational.json-simplify-2 [=>]7.9 | \[ \color{blue}{x \cdot -1}
\] |
rational.json-simplify-9 [=>]7.9 | \[ \color{blue}{-x}
\] |
if 6.60000000000000055e-29 < z < 4.04999999999999989e49Initial program 18.3
if 4.04999999999999989e49 < z Initial program 48.4
Taylor expanded in z around inf 13.4
Final simplification11.8
| Alternative 1 | |
|---|---|
| Error | 12.8 |
| Cost | 260 |
| Alternative 2 | |
|---|---|
| Error | 31.5 |
| Cost | 64 |
herbie shell --seed 2023075
(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))))