
(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 8 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 (- z (fma x -3.0 (* y -2.0))))
double code(double x, double y, double z) {
return z - fma(x, -3.0, (y * -2.0));
}
function code(x, y, z) return Float64(z - fma(x, -3.0, Float64(y * -2.0))) end
code[x_, y_, z_] := N[(z - N[(x * -3.0 + N[(y * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - \mathsf{fma}\left(x, -3, y \cdot -2\right)
\end{array}
(FPCore (x y z)
:precision binary64
(if (<= z -8e+120)
z
(if (<= z -1e-66)
(* x 3.0)
(if (<= z -1.26e-83)
(* y 2.0)
(if (<= z -1.2e-236)
(* x 3.0)
(if (<= z -1.55e-260)
(* y 2.0)
(if (<= z 7.8e-189)
(* x 3.0)
(if (<= z 1.25e-94)
(* y 2.0)
(if (<= z 0.00043) (* x 3.0) z)))))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -8e+120) {
tmp = z;
} else if (z <= -1e-66) {
tmp = x * 3.0;
} else if (z <= -1.26e-83) {
tmp = y * 2.0;
} else if (z <= -1.2e-236) {
tmp = x * 3.0;
} else if (z <= -1.55e-260) {
tmp = y * 2.0;
} else if (z <= 7.8e-189) {
tmp = x * 3.0;
} else if (z <= 1.25e-94) {
tmp = y * 2.0;
} else if (z <= 0.00043) {
tmp = x * 3.0;
} 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 <= (-8d+120)) then
tmp = z
else if (z <= (-1d-66)) then
tmp = x * 3.0d0
else if (z <= (-1.26d-83)) then
tmp = y * 2.0d0
else if (z <= (-1.2d-236)) then
tmp = x * 3.0d0
else if (z <= (-1.55d-260)) then
tmp = y * 2.0d0
else if (z <= 7.8d-189) then
tmp = x * 3.0d0
else if (z <= 1.25d-94) then
tmp = y * 2.0d0
else if (z <= 0.00043d0) then
tmp = x * 3.0d0
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -8e+120) {
tmp = z;
} else if (z <= -1e-66) {
tmp = x * 3.0;
} else if (z <= -1.26e-83) {
tmp = y * 2.0;
} else if (z <= -1.2e-236) {
tmp = x * 3.0;
} else if (z <= -1.55e-260) {
tmp = y * 2.0;
} else if (z <= 7.8e-189) {
tmp = x * 3.0;
} else if (z <= 1.25e-94) {
tmp = y * 2.0;
} else if (z <= 0.00043) {
tmp = x * 3.0;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8e+120: tmp = z elif z <= -1e-66: tmp = x * 3.0 elif z <= -1.26e-83: tmp = y * 2.0 elif z <= -1.2e-236: tmp = x * 3.0 elif z <= -1.55e-260: tmp = y * 2.0 elif z <= 7.8e-189: tmp = x * 3.0 elif z <= 1.25e-94: tmp = y * 2.0 elif z <= 0.00043: tmp = x * 3.0 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8e+120) tmp = z; elseif (z <= -1e-66) tmp = Float64(x * 3.0); elseif (z <= -1.26e-83) tmp = Float64(y * 2.0); elseif (z <= -1.2e-236) tmp = Float64(x * 3.0); elseif (z <= -1.55e-260) tmp = Float64(y * 2.0); elseif (z <= 7.8e-189) tmp = Float64(x * 3.0); elseif (z <= 1.25e-94) tmp = Float64(y * 2.0); elseif (z <= 0.00043) tmp = Float64(x * 3.0); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8e+120) tmp = z; elseif (z <= -1e-66) tmp = x * 3.0; elseif (z <= -1.26e-83) tmp = y * 2.0; elseif (z <= -1.2e-236) tmp = x * 3.0; elseif (z <= -1.55e-260) tmp = y * 2.0; elseif (z <= 7.8e-189) tmp = x * 3.0; elseif (z <= 1.25e-94) tmp = y * 2.0; elseif (z <= 0.00043) tmp = x * 3.0; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8e+120], z, If[LessEqual[z, -1e-66], N[(x * 3.0), $MachinePrecision], If[LessEqual[z, -1.26e-83], N[(y * 2.0), $MachinePrecision], If[LessEqual[z, -1.2e-236], N[(x * 3.0), $MachinePrecision], If[LessEqual[z, -1.55e-260], N[(y * 2.0), $MachinePrecision], If[LessEqual[z, 7.8e-189], N[(x * 3.0), $MachinePrecision], If[LessEqual[z, 1.25e-94], N[(y * 2.0), $MachinePrecision], If[LessEqual[z, 0.00043], N[(x * 3.0), $MachinePrecision], z]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{+120}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq -1 \cdot 10^{-66}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;z \leq -1.26 \cdot 10^{-83}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;z \leq -1.2 \cdot 10^{-236}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;z \leq -1.55 \cdot 10^{-260}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;z \leq 7.8 \cdot 10^{-189}:\\
\;\;\;\;x \cdot 3\\
\mathbf{elif}\;z \leq 1.25 \cdot 10^{-94}:\\
\;\;\;\;y \cdot 2\\
\mathbf{elif}\;z \leq 0.00043:\\
\;\;\;\;x \cdot 3\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -5.4e+184) (not (<= y 1.05e+155))) (* y 2.0) (- z (* x -3.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.4e+184) || !(y <= 1.05e+155)) {
tmp = 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 ((y <= (-5.4d+184)) .or. (.not. (y <= 1.05d+155))) then
tmp = 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 ((y <= -5.4e+184) || !(y <= 1.05e+155)) {
tmp = y * 2.0;
} else {
tmp = z - (x * -3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.4e+184) or not (y <= 1.05e+155): tmp = y * 2.0 else: tmp = z - (x * -3.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.4e+184) || !(y <= 1.05e+155)) tmp = 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 ((y <= -5.4e+184) || ~((y <= 1.05e+155))) tmp = y * 2.0; else tmp = z - (x * -3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.4e+184], N[Not[LessEqual[y, 1.05e+155]], $MachinePrecision]], N[(y * 2.0), $MachinePrecision], N[(z - N[(x * -3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{+184} \lor \neg \left(y \leq 1.05 \cdot 10^{+155}\right):\\
\;\;\;\;y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -3\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -8.3e+183) (not (<= y 6e+54))) (- z (* y -2.0)) (- z (* x -3.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.3e+183) || !(y <= 6e+54)) {
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 ((y <= (-8.3d+183)) .or. (.not. (y <= 6d+54))) 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 ((y <= -8.3e+183) || !(y <= 6e+54)) {
tmp = z - (y * -2.0);
} else {
tmp = z - (x * -3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.3e+183) or not (y <= 6e+54): tmp = z - (y * -2.0) else: tmp = z - (x * -3.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.3e+183) || !(y <= 6e+54)) 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 ((y <= -8.3e+183) || ~((y <= 6e+54))) tmp = z - (y * -2.0); else tmp = z - (x * -3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.3e+183], N[Not[LessEqual[y, 6e+54]], $MachinePrecision]], N[(z - N[(y * -2.0), $MachinePrecision]), $MachinePrecision], N[(z - N[(x * -3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.3 \cdot 10^{+183} \lor \neg \left(y \leq 6 \cdot 10^{+54}\right):\\
\;\;\;\;z - y \cdot -2\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -3\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= y -1.45e+175) (+ x (* 2.0 (+ x y))) (if (<= y 3.6e+54) (- z (* x -3.0)) (- z (* y -2.0)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.45e+175) {
tmp = x + (2.0 * (x + y));
} else if (y <= 3.6e+54) {
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 (y <= (-1.45d+175)) then
tmp = x + (2.0d0 * (x + y))
else if (y <= 3.6d+54) 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 (y <= -1.45e+175) {
tmp = x + (2.0 * (x + y));
} else if (y <= 3.6e+54) {
tmp = z - (x * -3.0);
} else {
tmp = z - (y * -2.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.45e+175: tmp = x + (2.0 * (x + y)) elif y <= 3.6e+54: tmp = z - (x * -3.0) else: tmp = z - (y * -2.0) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.45e+175) tmp = Float64(x + Float64(2.0 * Float64(x + y))); elseif (y <= 3.6e+54) 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 (y <= -1.45e+175) tmp = x + (2.0 * (x + y)); elseif (y <= 3.6e+54) tmp = z - (x * -3.0); else tmp = z - (y * -2.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.45e+175], N[(x + N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.6e+54], N[(z - N[(x * -3.0), $MachinePrecision]), $MachinePrecision], N[(z - N[(y * -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+175}:\\
\;\;\;\;x + 2 \cdot \left(x + y\right)\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{+54}:\\
\;\;\;\;z - x \cdot -3\\
\mathbf{else}:\\
\;\;\;\;z - y \cdot -2\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (+ (* 2.0 (+ x y)) (+ z x)))
double code(double x, double y, double z) {
return (2.0 * (x + y)) + (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 = (2.0d0 * (x + y)) + (z + x)
end function
public static double code(double x, double y, double z) {
return (2.0 * (x + y)) + (z + x);
}
def code(x, y, z): return (2.0 * (x + y)) + (z + x)
function code(x, y, z) return Float64(Float64(2.0 * Float64(x + y)) + Float64(z + x)) end
function tmp = code(x, y, z) tmp = (2.0 * (x + y)) + (z + x); end
code[x_, y_, z_] := N[(N[(2.0 * N[(x + y), $MachinePrecision]), $MachinePrecision] + N[(z + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(x + y\right) + \left(z + x\right)
\end{array}
(FPCore (x y z) :precision binary64 (if (<= z -2.4e+85) z (if (<= z 1.5) (* y 2.0) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e+85) {
tmp = z;
} else if (z <= 1.5) {
tmp = y * 2.0;
} 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 <= (-2.4d+85)) then
tmp = z
else if (z <= 1.5d0) then
tmp = y * 2.0d0
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e+85) {
tmp = z;
} else if (z <= 1.5) {
tmp = y * 2.0;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.4e+85: tmp = z elif z <= 1.5: tmp = y * 2.0 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.4e+85) tmp = z; elseif (z <= 1.5) tmp = Float64(y * 2.0); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.4e+85) tmp = z; elseif (z <= 1.5) tmp = y * 2.0; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.4e+85], z, If[LessEqual[z, 1.5], N[(y * 2.0), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+85}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.5:\\
\;\;\;\;y \cdot 2\\
\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 2024008
(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))