
(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 0.5) (* x y)) z))
double code(double x, double y, double z) {
return ((x * 0.5) + (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 * 0.5d0) + (x * y)) + z
end function
public static double code(double x, double y, double z) {
return ((x * 0.5) + (x * y)) + z;
}
def code(x, y, z): return ((x * 0.5) + (x * y)) + z
function code(x, y, z) return Float64(Float64(Float64(x * 0.5) + Float64(x * y)) + z) end
function tmp = code(x, y, z) tmp = ((x * 0.5) + (x * y)) + z; end
code[x_, y_, z_] := N[(N[(N[(x * 0.5), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 0.5 + x \cdot y\right) + z
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64100.0
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -0.5) (fma x y z) (if (<= y 2.35e-12) (fma x 0.5 z) (fma x y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = fma(x, y, z);
} else if (y <= 2.35e-12) {
tmp = fma(x, 0.5, z);
} else {
tmp = fma(x, y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -0.5) tmp = fma(x, y, z); elseif (y <= 2.35e-12) tmp = fma(x, 0.5, z); else tmp = fma(x, y, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -0.5], N[(x * y + z), $MachinePrecision], If[LessEqual[y, 2.35e-12], N[(x * 0.5 + z), $MachinePrecision], N[(x * y + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;\mathsf{fma}\left(x, y, z\right)\\
\mathbf{elif}\;y \leq 2.35 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, z\right)\\
\end{array}
\end{array}
if y < -0.5 or 2.34999999999999988e-12 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6498.1
Simplified98.1%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6498.1
Simplified98.1%
if -0.5 < y < 2.34999999999999988e-12Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6498.6
Simplified98.6%
(FPCore (x y z) :precision binary64 (if (<= y -72000000.0) (* x y) (if (<= y 250000000000.0) (fma x 0.5 z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -72000000.0) {
tmp = x * y;
} else if (y <= 250000000000.0) {
tmp = fma(x, 0.5, z);
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -72000000.0) tmp = Float64(x * y); elseif (y <= 250000000000.0) tmp = fma(x, 0.5, z); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -72000000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 250000000000.0], N[(x * 0.5 + z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -72000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 250000000000:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -7.2e7 or 2.5e11 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6471.6
Simplified71.6%
if -7.2e7 < y < 2.5e11Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6496.6
Simplified96.6%
(FPCore (x y z) :precision binary64 (if (<= y -0.5) (* x y) (if (<= y 0.5) (* x 0.5) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = x * y;
} else if (y <= 0.5) {
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) :: tmp
if (y <= (-0.5d0)) then
tmp = x * y
else if (y <= 0.5d0) 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 tmp;
if (y <= -0.5) {
tmp = x * y;
} else if (y <= 0.5) {
tmp = x * 0.5;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.5: tmp = x * y elif y <= 0.5: tmp = x * 0.5 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.5) tmp = Float64(x * y); elseif (y <= 0.5) tmp = 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 <= -0.5) tmp = x * y; elseif (y <= 0.5) tmp = x * 0.5; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.5], N[(x * y), $MachinePrecision], If[LessEqual[y, 0.5], N[(x * 0.5), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -0.5 or 0.5 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6468.9
Simplified68.9%
if -0.5 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6498.6
Simplified98.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6454.6
Simplified54.6%
(FPCore (x y z) :precision binary64 (fma x (+ 0.5 y) z))
double code(double x, double y, double z) {
return fma(x, (0.5 + y), z);
}
function code(x, y, z) return fma(x, Float64(0.5 + y), z) end
code[x_, y_, z_] := N[(x * N[(0.5 + y), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 0.5 + y, z\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-+.f64100.0
Simplified100.0%
(FPCore (x y z) :precision binary64 (* x 0.5))
double code(double x, double y, double z) {
return x * 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 = x * 0.5d0
end function
public static double code(double x, double y, double z) {
return x * 0.5;
}
def code(x, y, z): return x * 0.5
function code(x, y, z) return Float64(x * 0.5) end
function tmp = code(x, y, z) tmp = x * 0.5; end
code[x_, y_, z_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6466.7
Simplified66.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6430.3
Simplified30.3%
herbie shell --seed 2024215
(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))