
(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%
div-invN/A
*-commutativeN/A
distribute-lft-outN/A
fma-defineN/A
fma-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
metadata-eval100.0%
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ z (* x y)))) (if (<= y -1400000.0) t_0 (if (<= y 0.5) (+ z (* x 0.5)) t_0))))
double code(double x, double y, double z) {
double t_0 = z + (x * y);
double tmp;
if (y <= -1400000.0) {
tmp = t_0;
} else if (y <= 0.5) {
tmp = z + (x * 0.5);
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = z + (x * y)
if (y <= (-1400000.0d0)) then
tmp = t_0
else if (y <= 0.5d0) then
tmp = z + (x * 0.5d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z + (x * y);
double tmp;
if (y <= -1400000.0) {
tmp = t_0;
} else if (y <= 0.5) {
tmp = z + (x * 0.5);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z + (x * y) tmp = 0 if y <= -1400000.0: tmp = t_0 elif y <= 0.5: tmp = z + (x * 0.5) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z + Float64(x * y)) tmp = 0.0 if (y <= -1400000.0) tmp = t_0; elseif (y <= 0.5) tmp = Float64(z + Float64(x * 0.5)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z + (x * y); tmp = 0.0; if (y <= -1400000.0) tmp = t_0; elseif (y <= 0.5) tmp = z + (x * 0.5); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1400000.0], t$95$0, If[LessEqual[y, 0.5], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z + x \cdot y\\
\mathbf{if}\;y \leq -1400000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.4e6 or 0.5 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6499.4%
Simplified99.4%
if -1.4e6 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6498.0%
Simplified98.0%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.95e+49) (* x y) (if (<= y 2.65e+139) (+ z (* x 0.5)) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.95e+49) {
tmp = x * y;
} else if (y <= 2.65e+139) {
tmp = z + (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) :: tmp
if (y <= (-1.95d+49)) then
tmp = x * y
else if (y <= 2.65d+139) then
tmp = z + (x * 0.5d0)
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.95e+49) {
tmp = x * y;
} else if (y <= 2.65e+139) {
tmp = z + (x * 0.5);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.95e+49: tmp = x * y elif y <= 2.65e+139: tmp = z + (x * 0.5) else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.95e+49) tmp = Float64(x * y); elseif (y <= 2.65e+139) tmp = Float64(z + Float64(x * 0.5)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.95e+49) tmp = x * y; elseif (y <= 2.65e+139) tmp = z + (x * 0.5); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.95e+49], N[(x * y), $MachinePrecision], If[LessEqual[y, 2.65e+139], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+49}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{+139}:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.95e49 or 2.65000000000000025e139 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6471.9%
Simplified71.9%
if -1.95e49 < y < 2.65000000000000025e139Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6491.4%
Simplified91.4%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (<= z -52000000000000.0) z (if (<= z 1.75e+102) (* x (+ y 0.5)) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -52000000000000.0) {
tmp = z;
} else if (z <= 1.75e+102) {
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 (z <= (-52000000000000.0d0)) then
tmp = z
else if (z <= 1.75d+102) 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 (z <= -52000000000000.0) {
tmp = z;
} else if (z <= 1.75e+102) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -52000000000000.0: tmp = z elif z <= 1.75e+102: tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -52000000000000.0) tmp = z; elseif (z <= 1.75e+102) 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 (z <= -52000000000000.0) tmp = z; elseif (z <= 1.75e+102) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -52000000000000.0], z, If[LessEqual[z, 1.75e+102], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -52000000000000:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.75 \cdot 10^{+102}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -5.2e13 or 1.75000000000000005e102 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified75.1%
if -5.2e13 < z < 1.75000000000000005e102Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6479.6%
Simplified79.6%
Final simplification77.5%
(FPCore (x y z) :precision binary64 (if (<= y -6.2e+48) (* x y) (if (<= y 3.9e+136) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.2e+48) {
tmp = x * y;
} else if (y <= 3.9e+136) {
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 <= (-6.2d+48)) then
tmp = x * y
else if (y <= 3.9d+136) 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 <= -6.2e+48) {
tmp = x * y;
} else if (y <= 3.9e+136) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.2e+48: tmp = x * y elif y <= 3.9e+136: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.2e+48) tmp = Float64(x * y); elseif (y <= 3.9e+136) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.2e+48) tmp = x * y; elseif (y <= 3.9e+136) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.2e+48], N[(x * y), $MachinePrecision], If[LessEqual[y, 3.9e+136], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{+48}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 3.9 \cdot 10^{+136}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -6.20000000000000011e48 or 3.90000000000000019e136 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6471.5%
Simplified71.5%
if -6.20000000000000011e48 < y < 3.90000000000000019e136Initial program 100.0%
Taylor expanded in x around 0
Simplified56.8%
(FPCore (x y z) :precision binary64 (if (<= z -2e-114) z (if (<= z 2.1e-26) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2e-114) {
tmp = z;
} else if (z <= 2.1e-26) {
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 <= (-2d-114)) then
tmp = z
else if (z <= 2.1d-26) 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 <= -2e-114) {
tmp = z;
} else if (z <= 2.1e-26) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2e-114: tmp = z elif z <= 2.1e-26: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2e-114) tmp = z; elseif (z <= 2.1e-26) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2e-114) tmp = z; elseif (z <= 2.1e-26) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2e-114], z, If[LessEqual[z, 2.1e-26], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{-114}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-26}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -2.0000000000000001e-114 or 2.10000000000000008e-26 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified64.0%
if -2.0000000000000001e-114 < z < 2.10000000000000008e-26Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6487.9%
Simplified87.9%
Taylor expanded in y around 0
*-commutativeN/A
*-lowering-*.f6443.4%
Simplified43.4%
(FPCore (x y z) :precision binary64 (+ z (+ (/ x 2.0) (* x y))))
double code(double x, double y, double z) {
return z + ((x / 2.0) + (x * y));
}
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 / 2.0d0) + (x * y))
end function
public static double code(double x, double y, double z) {
return z + ((x / 2.0) + (x * y));
}
def code(x, y, z): return z + ((x / 2.0) + (x * y))
function code(x, y, z) return Float64(z + Float64(Float64(x / 2.0) + Float64(x * y))) end
function tmp = code(x, y, z) tmp = z + ((x / 2.0) + (x * y)); end
code[x_, y_, z_] := N[(z + N[(N[(x / 2.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(\frac{x}{2} + x \cdot y\right)
\end{array}
Initial program 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%
Taylor expanded in x around 0
Simplified46.6%
herbie shell --seed 2024161
(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))