
(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 x (+ y 0.5) z))
double code(double x, double y, double z) {
return fma(x, (y + 0.5), z);
}
function code(x, y, z) return fma(x, Float64(y + 0.5), z) end
code[x_, y_, z_] := N[(x * N[(y + 0.5), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + 0.5, 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%
*-commutative100.0%
fma-udef100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -8e+97)
(* x y)
(if (<= y -3.9e-53)
z
(if (<= y -4.6e-220)
(* x 0.5)
(if (<= y 4.5e-116)
z
(if (<= y 0.00365) (* x 0.5) (if (<= y 6.5e+122) z (* x y))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8e+97) {
tmp = x * y;
} else if (y <= -3.9e-53) {
tmp = z;
} else if (y <= -4.6e-220) {
tmp = x * 0.5;
} else if (y <= 4.5e-116) {
tmp = z;
} else if (y <= 0.00365) {
tmp = x * 0.5;
} else if (y <= 6.5e+122) {
tmp = z;
} else {
tmp = x * y;
}
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 <= (-8d+97)) then
tmp = x * y
else if (y <= (-3.9d-53)) then
tmp = z
else if (y <= (-4.6d-220)) then
tmp = x * 0.5d0
else if (y <= 4.5d-116) then
tmp = z
else if (y <= 0.00365d0) then
tmp = x * 0.5d0
else if (y <= 6.5d+122) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8e+97) {
tmp = x * y;
} else if (y <= -3.9e-53) {
tmp = z;
} else if (y <= -4.6e-220) {
tmp = x * 0.5;
} else if (y <= 4.5e-116) {
tmp = z;
} else if (y <= 0.00365) {
tmp = x * 0.5;
} else if (y <= 6.5e+122) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8e+97: tmp = x * y elif y <= -3.9e-53: tmp = z elif y <= -4.6e-220: tmp = x * 0.5 elif y <= 4.5e-116: tmp = z elif y <= 0.00365: tmp = x * 0.5 elif y <= 6.5e+122: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8e+97) tmp = Float64(x * y); elseif (y <= -3.9e-53) tmp = z; elseif (y <= -4.6e-220) tmp = Float64(x * 0.5); elseif (y <= 4.5e-116) tmp = z; elseif (y <= 0.00365) tmp = Float64(x * 0.5); elseif (y <= 6.5e+122) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8e+97) tmp = x * y; elseif (y <= -3.9e-53) tmp = z; elseif (y <= -4.6e-220) tmp = x * 0.5; elseif (y <= 4.5e-116) tmp = z; elseif (y <= 0.00365) tmp = x * 0.5; elseif (y <= 6.5e+122) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8e+97], N[(x * y), $MachinePrecision], If[LessEqual[y, -3.9e-53], z, If[LessEqual[y, -4.6e-220], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 4.5e-116], z, If[LessEqual[y, 0.00365], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 6.5e+122], z, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+97}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -3.9 \cdot 10^{-53}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -4.6 \cdot 10^{-220}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{-116}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 0.00365:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{+122}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -8.0000000000000006e97 or 6.49999999999999963e122 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
*-commutative100.0%
fma-udef100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 84.3%
if -8.0000000000000006e97 < y < -3.9000000000000002e-53 or -4.59999999999999961e-220 < y < 4.50000000000000012e-116 or 0.00365000000000000003 < y < 6.49999999999999963e122Initial program 99.9%
associate-+l+99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
*-commutative100.0%
fma-udef100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 59.3%
if -3.9000000000000002e-53 < y < -4.59999999999999961e-220 or 4.50000000000000012e-116 < y < 0.00365000000000000003Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 67.1%
Taylor expanded in y around 0 63.8%
Final simplification67.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -15.0) (not (<= x 2.45e-76))) (* x (+ y 0.5)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -15.0) || !(x <= 2.45e-76)) {
tmp = x * (y + 0.5);
} 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 ((x <= (-15.0d0)) .or. (.not. (x <= 2.45d-76))) then
tmp = x * (y + 0.5d0)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -15.0) || !(x <= 2.45e-76)) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -15.0) or not (x <= 2.45e-76): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -15.0) || !(x <= 2.45e-76)) tmp = Float64(x * Float64(y + 0.5)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -15.0) || ~((x <= 2.45e-76))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -15.0], N[Not[LessEqual[x, 2.45e-76]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -15 \lor \neg \left(x \leq 2.45 \cdot 10^{-76}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -15 or 2.44999999999999986e-76 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 83.8%
if -15 < x < 2.44999999999999986e-76Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
*-commutative100.0%
fma-udef100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 69.1%
Final simplification77.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -34000.0) (not (<= x 1.65e+109))) (* x (+ y 0.5)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -34000.0) || !(x <= 1.65e+109)) {
tmp = x * (y + 0.5);
} else {
tmp = z + (x * y);
}
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 <= (-34000.0d0)) .or. (.not. (x <= 1.65d+109))) then
tmp = x * (y + 0.5d0)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -34000.0) || !(x <= 1.65e+109)) {
tmp = x * (y + 0.5);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -34000.0) or not (x <= 1.65e+109): tmp = x * (y + 0.5) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -34000.0) || !(x <= 1.65e+109)) tmp = Float64(x * Float64(y + 0.5)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -34000.0) || ~((x <= 1.65e+109))) tmp = x * (y + 0.5); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -34000.0], N[Not[LessEqual[x, 1.65e+109]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -34000 \lor \neg \left(x \leq 1.65 \cdot 10^{+109}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -34000 or 1.6499999999999999e109 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 92.6%
if -34000 < x < 1.6499999999999999e109Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
flip-+81.1%
associate-*l/79.9%
metadata-eval79.9%
Applied egg-rr79.9%
Taylor expanded in y around inf 83.0%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -6600.0) (not (<= y 0.5))) (+ z (* x y)) (+ z (/ x 2.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6600.0) || !(y <= 0.5)) {
tmp = z + (x * y);
} else {
tmp = z + (x / 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 <= (-6600.0d0)) .or. (.not. (y <= 0.5d0))) then
tmp = z + (x * y)
else
tmp = z + (x / 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6600.0) || !(y <= 0.5)) {
tmp = z + (x * y);
} else {
tmp = z + (x / 2.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6600.0) or not (y <= 0.5): tmp = z + (x * y) else: tmp = z + (x / 2.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6600.0) || !(y <= 0.5)) tmp = Float64(z + Float64(x * y)); else tmp = Float64(z + Float64(x / 2.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6600.0) || ~((y <= 0.5))) tmp = z + (x * y); else tmp = z + (x / 2.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6600.0], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z + N[(x / 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6600 \lor \neg \left(y \leq 0.5\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z + \frac{x}{2}\\
\end{array}
\end{array}
if y < -6600 or 0.5 < y Initial program 99.9%
associate-+l+99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in x around 0 100.0%
flip-+70.0%
associate-*l/62.4%
metadata-eval62.4%
Applied egg-rr62.4%
Taylor expanded in y around inf 99.8%
if -6600 < y < 0.5Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 97.8%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= x -42000.0) (* x 0.5) (if (<= x 1.4e+65) z (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if (x <= -42000.0) {
tmp = x * 0.5;
} else if (x <= 1.4e+65) {
tmp = z;
} else {
tmp = x * 0.5;
}
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 <= (-42000.0d0)) then
tmp = x * 0.5d0
else if (x <= 1.4d+65) then
tmp = z
else
tmp = x * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -42000.0) {
tmp = x * 0.5;
} else if (x <= 1.4e+65) {
tmp = z;
} else {
tmp = x * 0.5;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -42000.0: tmp = x * 0.5 elif x <= 1.4e+65: tmp = z else: tmp = x * 0.5 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -42000.0) tmp = Float64(x * 0.5); elseif (x <= 1.4e+65) tmp = z; else tmp = Float64(x * 0.5); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -42000.0) tmp = x * 0.5; elseif (x <= 1.4e+65) tmp = z; else tmp = x * 0.5; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -42000.0], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 1.4e+65], z, N[(x * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -42000:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{+65}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5\\
\end{array}
\end{array}
if x < -42000 or 1.3999999999999999e65 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 91.3%
Taylor expanded in y around 0 52.3%
if -42000 < x < 1.3999999999999999e65Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
*-commutative100.0%
fma-udef100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 62.9%
Final simplification58.5%
(FPCore (x y z) :precision binary64 (+ z (* x (+ y 0.5))))
double code(double x, double y, double z) {
return z + (x * (y + 0.5));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (x * (y + 0.5d0))
end function
public static double code(double x, double y, double z) {
return z + (x * (y + 0.5));
}
def code(x, y, z): return z + (x * (y + 0.5))
function code(x, y, z) return Float64(z + Float64(x * Float64(y + 0.5))) end
function tmp = code(x, y, z) tmp = z + (x * (y + 0.5)); end
code[x_, y_, z_] := N[(z + N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot \left(y + 0.5\right)
\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 100.0%
+-commutative100.0%
*-commutative100.0%
fma-udef100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 40.5%
Final simplification40.5%
herbie shell --seed 2023171
(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))