
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (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 = ((x / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z): return ((x / 2.0) + (y * x)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (y * x)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (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 = ((x / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z): return ((x / 2.0) + (y * x)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (y * x)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ 0.5 y) x z))
double code(double x, double y, double z) {
return fma((0.5 + y), x, z);
}
function code(x, y, z) return fma(Float64(0.5 + y), x, z) end
code[x_, y_, z_] := N[(N[(0.5 + y), $MachinePrecision] * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.5 + y, x, z\right)
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -2600.0)
(* y x)
(if (<= y -1.75e-168)
z
(if (<= y 9.8e-285)
(* 0.5 x)
(if (<= y 3.6e-230)
z
(if (<= y 5e-73)
(* 0.5 x)
(if (<= y 3.4e-48)
z
(if (<= y 8.2e-13)
(* 0.5 x)
(if (<= y 1.85e+64) z (* y x))))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2600.0) {
tmp = y * x;
} else if (y <= -1.75e-168) {
tmp = z;
} else if (y <= 9.8e-285) {
tmp = 0.5 * x;
} else if (y <= 3.6e-230) {
tmp = z;
} else if (y <= 5e-73) {
tmp = 0.5 * x;
} else if (y <= 3.4e-48) {
tmp = z;
} else if (y <= 8.2e-13) {
tmp = 0.5 * x;
} else if (y <= 1.85e+64) {
tmp = z;
} else {
tmp = y * x;
}
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 <= (-2600.0d0)) then
tmp = y * x
else if (y <= (-1.75d-168)) then
tmp = z
else if (y <= 9.8d-285) then
tmp = 0.5d0 * x
else if (y <= 3.6d-230) then
tmp = z
else if (y <= 5d-73) then
tmp = 0.5d0 * x
else if (y <= 3.4d-48) then
tmp = z
else if (y <= 8.2d-13) then
tmp = 0.5d0 * x
else if (y <= 1.85d+64) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2600.0) {
tmp = y * x;
} else if (y <= -1.75e-168) {
tmp = z;
} else if (y <= 9.8e-285) {
tmp = 0.5 * x;
} else if (y <= 3.6e-230) {
tmp = z;
} else if (y <= 5e-73) {
tmp = 0.5 * x;
} else if (y <= 3.4e-48) {
tmp = z;
} else if (y <= 8.2e-13) {
tmp = 0.5 * x;
} else if (y <= 1.85e+64) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2600.0: tmp = y * x elif y <= -1.75e-168: tmp = z elif y <= 9.8e-285: tmp = 0.5 * x elif y <= 3.6e-230: tmp = z elif y <= 5e-73: tmp = 0.5 * x elif y <= 3.4e-48: tmp = z elif y <= 8.2e-13: tmp = 0.5 * x elif y <= 1.85e+64: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2600.0) tmp = Float64(y * x); elseif (y <= -1.75e-168) tmp = z; elseif (y <= 9.8e-285) tmp = Float64(0.5 * x); elseif (y <= 3.6e-230) tmp = z; elseif (y <= 5e-73) tmp = Float64(0.5 * x); elseif (y <= 3.4e-48) tmp = z; elseif (y <= 8.2e-13) tmp = Float64(0.5 * x); elseif (y <= 1.85e+64) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2600.0) tmp = y * x; elseif (y <= -1.75e-168) tmp = z; elseif (y <= 9.8e-285) tmp = 0.5 * x; elseif (y <= 3.6e-230) tmp = z; elseif (y <= 5e-73) tmp = 0.5 * x; elseif (y <= 3.4e-48) tmp = z; elseif (y <= 8.2e-13) tmp = 0.5 * x; elseif (y <= 1.85e+64) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2600.0], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.75e-168], z, If[LessEqual[y, 9.8e-285], N[(0.5 * x), $MachinePrecision], If[LessEqual[y, 3.6e-230], z, If[LessEqual[y, 5e-73], N[(0.5 * x), $MachinePrecision], If[LessEqual[y, 3.4e-48], z, If[LessEqual[y, 8.2e-13], N[(0.5 * x), $MachinePrecision], If[LessEqual[y, 1.85e+64], z, N[(y * x), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2600:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.75 \cdot 10^{-168}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 9.8 \cdot 10^{-285}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-230}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-73}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{-48}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{-13}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{+64}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2600 or 1.84999999999999992e64 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 73.4%
if -2600 < y < -1.74999999999999991e-168 or 9.79999999999999949e-285 < y < 3.5999999999999998e-230 or 4.9999999999999998e-73 < y < 3.40000000000000028e-48 or 8.2000000000000004e-13 < y < 1.84999999999999992e64Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 61.7%
if -1.74999999999999991e-168 < y < 9.79999999999999949e-285 or 3.5999999999999998e-230 < y < 4.9999999999999998e-73 or 3.40000000000000028e-48 < y < 8.2000000000000004e-13Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 67.9%
Taylor expanded in y around 0 67.6%
Final simplification68.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.65e-155) (not (<= z 1.9e-6))) (+ z (* y x)) (* (+ 0.5 y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.65e-155) || !(z <= 1.9e-6)) {
tmp = z + (y * x);
} else {
tmp = (0.5 + y) * x;
}
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.65d-155)) .or. (.not. (z <= 1.9d-6))) then
tmp = z + (y * x)
else
tmp = (0.5d0 + y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.65e-155) || !(z <= 1.9e-6)) {
tmp = z + (y * x);
} else {
tmp = (0.5 + y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.65e-155) or not (z <= 1.9e-6): tmp = z + (y * x) else: tmp = (0.5 + y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.65e-155) || !(z <= 1.9e-6)) tmp = Float64(z + Float64(y * x)); else tmp = Float64(Float64(0.5 + y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.65e-155) || ~((z <= 1.9e-6))) tmp = z + (y * x); else tmp = (0.5 + y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.65e-155], N[Not[LessEqual[z, 1.9e-6]], $MachinePrecision]], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.65 \cdot 10^{-155} \lor \neg \left(z \leq 1.9 \cdot 10^{-6}\right):\\
\;\;\;\;z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 + y\right) \cdot x\\
\end{array}
\end{array}
if z < -2.6499999999999999e-155 or 1.9e-6 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
flip-+87.0%
associate-*r/85.2%
metadata-eval85.2%
Applied egg-rr85.2%
*-commutative85.2%
associate-/l*86.5%
Simplified86.5%
Taylor expanded in y around inf 82.5%
if -2.6499999999999999e-155 < z < 1.9e-6Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 89.5%
Final simplification85.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.5) (not (<= y 2.85e-8))) (+ z (* y x)) (+ z (* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 2.85e-8)) {
tmp = z + (y * x);
} else {
tmp = z + (0.5 * x);
}
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 <= (-0.5d0)) .or. (.not. (y <= 2.85d-8))) then
tmp = z + (y * x)
else
tmp = z + (0.5d0 * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 2.85e-8)) {
tmp = z + (y * x);
} else {
tmp = z + (0.5 * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.5) or not (y <= 2.85e-8): tmp = z + (y * x) else: tmp = z + (0.5 * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.5) || !(y <= 2.85e-8)) tmp = Float64(z + Float64(y * x)); else tmp = Float64(z + Float64(0.5 * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.5) || ~((y <= 2.85e-8))) tmp = z + (y * x); else tmp = z + (0.5 * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.5], N[Not[LessEqual[y, 2.85e-8]], $MachinePrecision]], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(z + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5 \lor \neg \left(y \leq 2.85 \cdot 10^{-8}\right):\\
\;\;\;\;z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + 0.5 \cdot x\\
\end{array}
\end{array}
if y < -0.5 or 2.85000000000000004e-8 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
flip-+71.5%
associate-*r/65.0%
metadata-eval65.0%
Applied egg-rr65.0%
*-commutative65.0%
associate-/l*70.7%
Simplified70.7%
Taylor expanded in y around inf 97.9%
if -0.5 < y < 2.85000000000000004e-8Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 99.6%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.3e+71) z (if (<= z 2.3e+125) (* (+ 0.5 y) x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.3e+71) {
tmp = z;
} else if (z <= 2.3e+125) {
tmp = (0.5 + y) * x;
} 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 <= (-1.3d+71)) then
tmp = z
else if (z <= 2.3d+125) then
tmp = (0.5d0 + y) * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.3e+71) {
tmp = z;
} else if (z <= 2.3e+125) {
tmp = (0.5 + y) * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.3e+71: tmp = z elif z <= 2.3e+125: tmp = (0.5 + y) * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.3e+71) tmp = z; elseif (z <= 2.3e+125) tmp = Float64(Float64(0.5 + y) * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.3e+71) tmp = z; elseif (z <= 2.3e+125) tmp = (0.5 + y) * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.3e+71], z, If[LessEqual[z, 2.3e+125], N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.3 \cdot 10^{+71}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{+125}:\\
\;\;\;\;\left(0.5 + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.29999999999999996e71 or 2.30000000000000013e125 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 78.4%
if -1.29999999999999996e71 < z < 2.30000000000000013e125Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 79.8%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (<= z -2.2e-159) z (if (<= z 22500000.0) (* 0.5 x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e-159) {
tmp = z;
} else if (z <= 22500000.0) {
tmp = 0.5 * x;
} 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.2d-159)) then
tmp = z
else if (z <= 22500000.0d0) then
tmp = 0.5d0 * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e-159) {
tmp = z;
} else if (z <= 22500000.0) {
tmp = 0.5 * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2e-159: tmp = z elif z <= 22500000.0: tmp = 0.5 * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2e-159) tmp = z; elseif (z <= 22500000.0) tmp = Float64(0.5 * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.2e-159) tmp = z; elseif (z <= 22500000.0) tmp = 0.5 * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2e-159], z, If[LessEqual[z, 22500000.0], N[(0.5 * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{-159}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 22500000:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -2.2e-159 or 2.25e7 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 57.6%
if -2.2e-159 < z < 2.25e7Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 89.5%
Taylor expanded in y around 0 49.6%
Final simplification54.4%
(FPCore (x y z) :precision binary64 (+ z (* (+ 0.5 y) x)))
double code(double x, double y, double z) {
return z + ((0.5 + y) * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + ((0.5d0 + y) * x)
end function
public static double code(double x, double y, double z) {
return z + ((0.5 + y) * x);
}
def code(x, y, z): return z + ((0.5 + y) * x)
function code(x, y, z) return Float64(z + Float64(Float64(0.5 + y) * x)) end
function tmp = code(x, y, z) tmp = z + ((0.5 + y) * x); end
code[x_, y_, z_] := N[(z + N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(0.5 + y\right) \cdot x
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(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}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 39.7%
Final simplification39.7%
herbie shell --seed 2023228
(FPCore (x y z)
:name "Data.Histogram.Bin.BinF:$cfromIndex from histogram-fill-0.8.4.1"
:precision binary64
(+ (+ (/ x 2.0) (* y x)) z))