
(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
double code(double x, double y, double z) {
return ((((x + y) + y) + x) + 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 = ((((x + y) + y) + x) + z) + x
end function
public static double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
def code(x, y, z): return ((((x + y) + y) + x) + z) + x
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x) end
function tmp = code(x, y, z) tmp = ((((x + y) + y) + x) + z) + x; end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
double code(double x, double y, double z) {
return ((((x + y) + y) + x) + 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 = ((((x + y) + y) + x) + z) + x
end function
public static double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
def code(x, y, z): return ((((x + y) + y) + x) + z) + x
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x) end
function tmp = code(x, y, z) tmp = ((((x + y) + y) + x) + z) + x; end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\end{array}
(FPCore (x y z) :precision binary64 (+ (* 2.0 (+ x y)) (+ x z)))
double code(double x, double y, double z) {
return (2.0 * (x + y)) + (x + z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (2.0d0 * (x + y)) + (x + z)
end function
public static double code(double x, double y, double z) {
return (2.0 * (x + y)) + (x + z);
}
def code(x, y, z): return (2.0 * (x + y)) + (x + z)
function code(x, y, z) return Float64(Float64(2.0 * Float64(x + y)) + Float64(x + z)) end
function tmp = code(x, y, z) tmp = (2.0 * (x + y)) + (x + z); end
code[x_, y_, z_] := N[(N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision] + N[(x + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(x + y\right) + \left(x + z\right)
\end{array}
(FPCore (x y z)
:precision binary64
(if (<= x -2.1e+16)
(* x 3.0)
(if (<= x -2.7e-32)
z
(if (<= x -3.3e-283)
(* 2.0 y)
(if (<= x 4.5e-273)
z
(if (<= x 6.2e-228)
(* 2.0 y)
(if (<= x 6.6e-158) z (if (<= x 9e+88) (* 2.0 y) (* x 3.0)))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.1e+16) {
tmp = x * 3.0;
} else if (x <= -2.7e-32) {
tmp = z;
} else if (x <= -3.3e-283) {
tmp = 2.0 * y;
} else if (x <= 4.5e-273) {
tmp = z;
} else if (x <= 6.2e-228) {
tmp = 2.0 * y;
} else if (x <= 6.6e-158) {
tmp = z;
} else if (x <= 9e+88) {
tmp = 2.0 * y;
} else {
tmp = x * 3.0;
}
return tmp;
}
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 <= (-2.1d+16)) then
tmp = x * 3.0d0
else if (x <= (-2.7d-32)) then
tmp = z
else if (x <= (-3.3d-283)) then
tmp = 2.0d0 * y
else if (x <= 4.5d-273) then
tmp = z
else if (x <= 6.2d-228) then
tmp = 2.0d0 * y
else if (x <= 6.6d-158) then
tmp = z
else if (x <= 9d+88) then
tmp = 2.0d0 * y
else
tmp = x * 3.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.1e+16) {
tmp = x * 3.0;
} else if (x <= -2.7e-32) {
tmp = z;
} else if (x <= -3.3e-283) {
tmp = 2.0 * y;
} else if (x <= 4.5e-273) {
tmp = z;
} else if (x <= 6.2e-228) {
tmp = 2.0 * y;
} else if (x <= 6.6e-158) {
tmp = z;
} else if (x <= 9e+88) {
tmp = 2.0 * y;
} else {
tmp = x * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.1e+16: tmp = x * 3.0 elif x <= -2.7e-32: tmp = z elif x <= -3.3e-283: tmp = 2.0 * y elif x <= 4.5e-273: tmp = z elif x <= 6.2e-228: tmp = 2.0 * y elif x <= 6.6e-158: tmp = z elif x <= 9e+88: tmp = 2.0 * y else: tmp = x * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.1e+16) tmp = Float64(x * 3.0); elseif (x <= -2.7e-32) tmp = z; elseif (x <= -3.3e-283) tmp = Float64(2.0 * y); elseif (x <= 4.5e-273) tmp = z; elseif (x <= 6.2e-228) tmp = Float64(2.0 * y); elseif (x <= 6.6e-158) tmp = z; elseif (x <= 9e+88) tmp = Float64(2.0 * y); else tmp = Float64(x * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.1e+16) tmp = x * 3.0; elseif (x <= -2.7e-32) tmp = z; elseif (x <= -3.3e-283) tmp = 2.0 * y; elseif (x <= 4.5e-273) tmp = z; elseif (x <= 6.2e-228) tmp = 2.0 * y; elseif (x <= 6.6e-158) tmp = z; elseif (x <= 9e+88) tmp = 2.0 * y; else tmp = x * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.1e+16], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, -2.7e-32], z, If[LessEqual[x, -3.3e-283], N[(2.0 * y), $MachinePrecision], If[LessEqual[x, 4.5e-273], z, If[LessEqual[x, 6.2e-228], N[(2.0 * y), $MachinePrecision], If[LessEqual[x, 6.6e-158], z, If[LessEqual[x, 9e+88], N[(2.0 * y), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{+16}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;x \leq -2.7 \cdot 10^{-32}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq -3.3 \cdot 10^{-283}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{-273}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{-228}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;x \leq 6.6 \cdot 10^{-158}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 9 \cdot 10^{+88}:\\
\;\;\;\;2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot 3\\
\end{array}
\end{array}
(FPCore (x y z)
:precision binary64
(if (or (<= y -2.6e+117)
(and (not (<= y 1.06e+49))
(or (<= y 1.06e+126) (not (<= y 4.3e+198)))))
(* 2.0 y)
(- z (* x -3.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.6e+117) || (!(y <= 1.06e+49) && ((y <= 1.06e+126) || !(y <= 4.3e+198)))) {
tmp = 2.0 * y;
} else {
tmp = z - (x * -3.0);
}
return tmp;
}
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 ((y <= (-2.6d+117)) .or. (.not. (y <= 1.06d+49)) .and. (y <= 1.06d+126) .or. (.not. (y <= 4.3d+198))) then
tmp = 2.0d0 * y
else
tmp = z - (x * (-3.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.6e+117) || (!(y <= 1.06e+49) && ((y <= 1.06e+126) || !(y <= 4.3e+198)))) {
tmp = 2.0 * y;
} else {
tmp = z - (x * -3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.6e+117) or (not (y <= 1.06e+49) and ((y <= 1.06e+126) or not (y <= 4.3e+198))): tmp = 2.0 * y else: tmp = z - (x * -3.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.6e+117) || (!(y <= 1.06e+49) && ((y <= 1.06e+126) || !(y <= 4.3e+198)))) tmp = Float64(2.0 * y); else tmp = Float64(z - Float64(x * -3.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.6e+117) || (~((y <= 1.06e+49)) && ((y <= 1.06e+126) || ~((y <= 4.3e+198))))) tmp = 2.0 * y; else tmp = z - (x * -3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.6e+117], And[N[Not[LessEqual[y, 1.06e+49]], $MachinePrecision], Or[LessEqual[y, 1.06e+126], N[Not[LessEqual[y, 4.3e+198]], $MachinePrecision]]]], N[(2.0 * y), $MachinePrecision], N[(z - N[(x * -3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+117} \lor \neg \left(y \leq 1.06 \cdot 10^{+49}\right) \land \left(y \leq 1.06 \cdot 10^{+126} \lor \neg \left(y \leq 4.3 \cdot 10^{+198}\right)\right):\\
\;\;\;\;2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -3\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -2.65e+38) (not (<= x 1.1e+87))) (- z (* x -3.0)) (- z (* y -2.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.65e+38) || !(x <= 1.1e+87)) {
tmp = z - (x * -3.0);
} else {
tmp = z - (y * -2.0);
}
return tmp;
}
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 <= (-2.65d+38)) .or. (.not. (x <= 1.1d+87))) then
tmp = z - (x * (-3.0d0))
else
tmp = z - (y * (-2.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.65e+38) || !(x <= 1.1e+87)) {
tmp = z - (x * -3.0);
} else {
tmp = z - (y * -2.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.65e+38) or not (x <= 1.1e+87): tmp = z - (x * -3.0) else: tmp = z - (y * -2.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.65e+38) || !(x <= 1.1e+87)) tmp = Float64(z - Float64(x * -3.0)); else tmp = Float64(z - Float64(y * -2.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.65e+38) || ~((x <= 1.1e+87))) tmp = z - (x * -3.0); else tmp = z - (y * -2.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.65e+38], N[Not[LessEqual[x, 1.1e+87]], $MachinePrecision]], N[(z - N[(x * -3.0), $MachinePrecision]), $MachinePrecision], N[(z - N[(y * -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.65 \cdot 10^{+38} \lor \neg \left(x \leq 1.1 \cdot 10^{+87}\right):\\
\;\;\;\;z - x \cdot -3\\
\mathbf{else}:\\
\;\;\;\;z - y \cdot -2\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= x -2.1e+16) (+ x (* 2.0 (+ x y))) (if (<= x 4.6e+86) (- z (* y -2.0)) (- z (* x -3.0)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.1e+16) {
tmp = x + (2.0 * (x + y));
} else if (x <= 4.6e+86) {
tmp = z - (y * -2.0);
} else {
tmp = z - (x * -3.0);
}
return tmp;
}
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 <= (-2.1d+16)) then
tmp = x + (2.0d0 * (x + y))
else if (x <= 4.6d+86) then
tmp = z - (y * (-2.0d0))
else
tmp = z - (x * (-3.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.1e+16) {
tmp = x + (2.0 * (x + y));
} else if (x <= 4.6e+86) {
tmp = z - (y * -2.0);
} else {
tmp = z - (x * -3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.1e+16: tmp = x + (2.0 * (x + y)) elif x <= 4.6e+86: tmp = z - (y * -2.0) else: tmp = z - (x * -3.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.1e+16) tmp = Float64(x + Float64(2.0 * Float64(x + y))); elseif (x <= 4.6e+86) tmp = Float64(z - Float64(y * -2.0)); else tmp = Float64(z - Float64(x * -3.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.1e+16) tmp = x + (2.0 * (x + y)); elseif (x <= 4.6e+86) tmp = z - (y * -2.0); else tmp = z - (x * -3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.1e+16], N[(x + N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.6e+86], N[(z - N[(y * -2.0), $MachinePrecision]), $MachinePrecision], N[(z - N[(x * -3.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{+16}:\\
\;\;\;\;x + 2 \cdot \left(x + y\right)\\
\mathbf{elif}\;x \leq 4.6 \cdot 10^{+86}:\\
\;\;\;\;z - y \cdot -2\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -3\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= z -5200000000.0) z (if (<= z 1.7e+67) (* 2.0 y) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5200000000.0) {
tmp = z;
} else if (z <= 1.7e+67) {
tmp = 2.0 * y;
} 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
real(8) :: tmp
if (z <= (-5200000000.0d0)) then
tmp = z
else if (z <= 1.7d+67) then
tmp = 2.0d0 * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -5200000000.0) {
tmp = z;
} else if (z <= 1.7e+67) {
tmp = 2.0 * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5200000000.0: tmp = z elif z <= 1.7e+67: tmp = 2.0 * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5200000000.0) tmp = z; elseif (z <= 1.7e+67) tmp = Float64(2.0 * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5200000000.0) tmp = z; elseif (z <= 1.7e+67) tmp = 2.0 * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5200000000.0], z, If[LessEqual[z, 1.7e+67], N[(2.0 * y), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5200000000:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.7 \cdot 10^{+67}:\\
\;\;\;\;2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
herbie shell --seed 2023350
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4"
:precision binary64
(+ (+ (+ (+ (+ x y) y) x) z) x))