
(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 -2e+246)
(* x y)
(if (<= t_0 -4e+121)
(* x 0.5)
(if (<= t_0 1e+132) z (if (<= t_0 2e+247) (* 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 <= -2e+246) {
tmp = x * y;
} else if (t_0 <= -4e+121) {
tmp = x * 0.5;
} else if (t_0 <= 1e+132) {
tmp = z;
} else if (t_0 <= 2e+247) {
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 <= (-2d+246)) then
tmp = x * y
else if (t_0 <= (-4d+121)) then
tmp = x * 0.5d0
else if (t_0 <= 1d+132) then
tmp = z
else if (t_0 <= 2d+247) 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 <= -2e+246) {
tmp = x * y;
} else if (t_0 <= -4e+121) {
tmp = x * 0.5;
} else if (t_0 <= 1e+132) {
tmp = z;
} else if (t_0 <= 2e+247) {
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 <= -2e+246: tmp = x * y elif t_0 <= -4e+121: tmp = x * 0.5 elif t_0 <= 1e+132: tmp = z elif t_0 <= 2e+247: 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 <= -2e+246) tmp = Float64(x * y); elseif (t_0 <= -4e+121) tmp = Float64(x * 0.5); elseif (t_0 <= 1e+132) tmp = z; elseif (t_0 <= 2e+247) 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 <= -2e+246) tmp = x * y; elseif (t_0 <= -4e+121) tmp = x * 0.5; elseif (t_0 <= 1e+132) tmp = z; elseif (t_0 <= 2e+247) 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, -2e+246], N[(x * y), $MachinePrecision], If[LessEqual[t$95$0, -4e+121], N[(x * 0.5), $MachinePrecision], If[LessEqual[t$95$0, 1e+132], z, If[LessEqual[t$95$0, 2e+247], 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 -2 \cdot 10^{+246}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;t\_0 \leq -4 \cdot 10^{+121}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;t\_0 \leq 10^{+132}:\\
\;\;\;\;z\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+247}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -2.00000000000000014e246 or 1.9999999999999999e247 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6488.6
Simplified88.6%
if -2.00000000000000014e246 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -4.00000000000000015e121 or 9.99999999999999991e131 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 1.9999999999999999e247Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6479.3
Simplified79.3%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6455.4
Simplified55.4%
if -4.00000000000000015e121 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 9.99999999999999991e131Initial program 100.0%
Taylor expanded in x around 0
Simplified61.8%
Final simplification66.9%
(FPCore (x y z) :precision binary64 (if (<= y -52000000.0) (fma y x z) (if (<= y 1.3e-16) (fma x 0.5 z) (fma y x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -52000000.0) {
tmp = fma(y, x, z);
} else if (y <= 1.3e-16) {
tmp = fma(x, 0.5, z);
} else {
tmp = fma(y, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -52000000.0) tmp = fma(y, x, z); elseif (y <= 1.3e-16) tmp = fma(x, 0.5, z); else tmp = fma(y, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -52000000.0], N[(y * x + z), $MachinePrecision], If[LessEqual[y, 1.3e-16], N[(x * 0.5 + z), $MachinePrecision], N[(y * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -52000000:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\end{array}
\end{array}
if y < -5.2e7 or 1.2999999999999999e-16 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6499.4
Simplified99.4%
*-commutativeN/A
accelerator-lowering-fma.f6499.4
Applied egg-rr99.4%
if -5.2e7 < y < 1.2999999999999999e-16Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64100.0
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= y -23000000000000.0) (* x y) (if (<= y 4e+77) (fma x 0.5 z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -23000000000000.0) {
tmp = x * y;
} else if (y <= 4e+77) {
tmp = fma(x, 0.5, z);
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -23000000000000.0) tmp = Float64(x * y); elseif (y <= 4e+77) tmp = fma(x, 0.5, z); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -23000000000000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 4e+77], N[(x * 0.5 + z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -23000000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+77}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -2.3e13 or 3.99999999999999993e77 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6473.7
Simplified73.7%
if -2.3e13 < y < 3.99999999999999993e77Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6495.5
Simplified95.5%
(FPCore (x y z) :precision binary64 (if (<= z -5e-70) z (if (<= z 1.35e-93) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5e-70) {
tmp = z;
} else if (z <= 1.35e-93) {
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 <= (-5d-70)) then
tmp = z
else if (z <= 1.35d-93) 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 <= -5e-70) {
tmp = z;
} else if (z <= 1.35e-93) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5e-70: tmp = z elif z <= 1.35e-93: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5e-70) tmp = z; elseif (z <= 1.35e-93) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5e-70) tmp = z; elseif (z <= 1.35e-93) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5e-70], z, If[LessEqual[z, 1.35e-93], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{-70}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{-93}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -4.9999999999999998e-70 or 1.3500000000000001e-93 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified58.3%
if -4.9999999999999998e-70 < z < 1.3500000000000001e-93Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6451.4
Simplified51.4%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6442.5
Simplified42.5%
(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.1%
herbie shell --seed 2024198
(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))