
(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 6 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 (+ (+ (/ x 2.0) (* x y)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (x * y)) + 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) + (x * y)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (x * y)) + z;
}
def code(x, y, z): return ((x / 2.0) + (x * y)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(x * y)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (x * y)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + x \cdot y\right) + z
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (/ x 2.0) (* x y))))
(if (<= t_0 -1e+213)
(* x y)
(if (<= t_0 1e+108) z (if (<= t_0 1e+307) (* x 0.5) (* x y))))))
double code(double x, double y, double z) {
double t_0 = (x / 2.0) + (x * y);
double tmp;
if (t_0 <= -1e+213) {
tmp = x * y;
} else if (t_0 <= 1e+108) {
tmp = z;
} else if (t_0 <= 1e+307) {
tmp = x * 0.5;
} 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) :: t_0
real(8) :: tmp
t_0 = (x / 2.0d0) + (x * y)
if (t_0 <= (-1d+213)) then
tmp = x * y
else if (t_0 <= 1d+108) then
tmp = z
else if (t_0 <= 1d+307) then
tmp = x * 0.5d0
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x / 2.0) + (x * y);
double tmp;
if (t_0 <= -1e+213) {
tmp = x * y;
} else if (t_0 <= 1e+108) {
tmp = z;
} else if (t_0 <= 1e+307) {
tmp = x * 0.5;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): t_0 = (x / 2.0) + (x * y) tmp = 0 if t_0 <= -1e+213: tmp = x * y elif t_0 <= 1e+108: tmp = z elif t_0 <= 1e+307: tmp = x * 0.5 else: tmp = x * y return tmp
function code(x, y, z) t_0 = Float64(Float64(x / 2.0) + Float64(x * y)) tmp = 0.0 if (t_0 <= -1e+213) tmp = Float64(x * y); elseif (t_0 <= 1e+108) tmp = z; elseif (t_0 <= 1e+307) tmp = Float64(x * 0.5); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x / 2.0) + (x * y); tmp = 0.0; if (t_0 <= -1e+213) tmp = x * y; elseif (t_0 <= 1e+108) tmp = z; elseif (t_0 <= 1e+307) tmp = x * 0.5; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x / 2.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+213], N[(x * y), $MachinePrecision], If[LessEqual[t$95$0, 1e+108], z, If[LessEqual[t$95$0, 1e+307], N[(x * 0.5), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{2} + x \cdot y\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+213}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;t\_0 \leq 10^{+108}:\\
\;\;\;\;z\\
\mathbf{elif}\;t\_0 \leq 10^{+307}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -9.99999999999999984e212 or 9.99999999999999986e306 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6491.4
Simplified91.4%
if -9.99999999999999984e212 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 1e108Initial program 100.0%
Taylor expanded in x around 0
Simplified64.6%
if 1e108 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 9.99999999999999986e306Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6472.2
Simplified72.2%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6458.3
Simplified58.3%
Final simplification70.2%
(FPCore (x y z) :precision binary64 (if (<= y -76000.0) (fma y x z) (if (<= y 8.6e-10) (fma x 0.5 z) (fma y x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -76000.0) {
tmp = fma(y, x, z);
} else if (y <= 8.6e-10) {
tmp = fma(x, 0.5, z);
} else {
tmp = fma(y, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -76000.0) tmp = fma(y, x, z); elseif (y <= 8.6e-10) tmp = fma(x, 0.5, z); else tmp = fma(y, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -76000.0], N[(y * x + z), $MachinePrecision], If[LessEqual[y, 8.6e-10], N[(x * 0.5 + z), $MachinePrecision], N[(y * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -76000:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\mathbf{elif}\;y \leq 8.6 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\end{array}
\end{array}
if y < -76000 or 8.60000000000000029e-10 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6498.6
Simplified98.6%
*-commutativeN/A
accelerator-lowering-fma.f6498.6
Applied egg-rr98.6%
if -76000 < y < 8.60000000000000029e-10Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6499.6
Simplified99.6%
(FPCore (x y z) :precision binary64 (if (<= y -8.6e+40) (* x y) (if (<= y 3400000.0) (fma x 0.5 z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.6e+40) {
tmp = x * y;
} else if (y <= 3400000.0) {
tmp = fma(x, 0.5, z);
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -8.6e+40) tmp = Float64(x * y); elseif (y <= 3400000.0) tmp = fma(x, 0.5, z); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -8.6e+40], N[(x * y), $MachinePrecision], If[LessEqual[y, 3400000.0], N[(x * 0.5 + z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.6 \cdot 10^{+40}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 3400000:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -8.6000000000000005e40 or 3.4e6 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6477.3
Simplified77.3%
if -8.6000000000000005e40 < y < 3.4e6Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6497.7
Simplified97.7%
(FPCore (x y z) :precision binary64 (if (<= z -1e-94) z (if (<= z 1.2e-53) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1e-94) {
tmp = z;
} else if (z <= 1.2e-53) {
tmp = x * 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 (z <= (-1d-94)) then
tmp = z
else if (z <= 1.2d-53) then
tmp = x * 0.5d0
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1e-94) {
tmp = z;
} else if (z <= 1.2e-53) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1e-94: tmp = z elif z <= 1.2e-53: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1e-94) tmp = z; elseif (z <= 1.2e-53) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1e-94) tmp = z; elseif (z <= 1.2e-53) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1e-94], z, If[LessEqual[z, 1.2e-53], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{-94}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{-53}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -9.9999999999999996e-95 or 1.20000000000000004e-53 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified59.7%
if -9.9999999999999996e-95 < z < 1.20000000000000004e-53Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6457.9
Simplified57.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6445.2
Simplified45.2%
(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%
Taylor expanded in x around 0
Simplified41.6%
herbie shell --seed 2024199
(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))