
(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 9 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 y x (+ z (* x 0.5))))
double code(double x, double y, double z) {
return fma(y, x, (z + (x * 0.5)));
}
function code(x, y, z) return fma(y, x, Float64(z + Float64(x * 0.5))) end
code[x_, y_, z_] := N[(y * x + N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, z + x \cdot 0.5\right)
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
+-commutative100.0%
associate-+l+100.0%
*-commutative100.0%
fma-def100.0%
div-inv100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -640000000000.0)
(* y x)
(if (<= y -9.5e-111)
z
(if (<= y -1.86e-165) (* x 0.5) (if (<= y 6.2e+15) z (* y x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -640000000000.0) {
tmp = y * x;
} else if (y <= -9.5e-111) {
tmp = z;
} else if (y <= -1.86e-165) {
tmp = x * 0.5;
} else if (y <= 6.2e+15) {
tmp = z;
} else {
tmp = y * x;
}
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 <= (-640000000000.0d0)) then
tmp = y * x
else if (y <= (-9.5d-111)) then
tmp = z
else if (y <= (-1.86d-165)) then
tmp = x * 0.5d0
else if (y <= 6.2d+15) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -640000000000.0) {
tmp = y * x;
} else if (y <= -9.5e-111) {
tmp = z;
} else if (y <= -1.86e-165) {
tmp = x * 0.5;
} else if (y <= 6.2e+15) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -640000000000.0: tmp = y * x elif y <= -9.5e-111: tmp = z elif y <= -1.86e-165: tmp = x * 0.5 elif y <= 6.2e+15: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -640000000000.0) tmp = Float64(y * x); elseif (y <= -9.5e-111) tmp = z; elseif (y <= -1.86e-165) tmp = Float64(x * 0.5); elseif (y <= 6.2e+15) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -640000000000.0) tmp = y * x; elseif (y <= -9.5e-111) tmp = z; elseif (y <= -1.86e-165) tmp = x * 0.5; elseif (y <= 6.2e+15) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -640000000000.0], N[(y * x), $MachinePrecision], If[LessEqual[y, -9.5e-111], z, If[LessEqual[y, -1.86e-165], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 6.2e+15], z, N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -640000000000:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -9.5 \cdot 10^{-111}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -1.86 \cdot 10^{-165}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{+15}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -6.4e11 or 6.2e15 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 79.3%
if -6.4e11 < y < -9.4999999999999995e-111 or -1.86000000000000002e-165 < y < 6.2e15Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 61.2%
if -9.4999999999999995e-111 < y < -1.86000000000000002e-165Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 80.9%
Taylor expanded in y around 0 80.9%
Final simplification71.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.4e-134) (not (<= x 1.5e-152))) (* x (+ y 0.5)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.4e-134) || !(x <= 1.5e-152)) {
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 <= (-5.4d-134)) .or. (.not. (x <= 1.5d-152))) 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 <= -5.4e-134) || !(x <= 1.5e-152)) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.4e-134) or not (x <= 1.5e-152): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.4e-134) || !(x <= 1.5e-152)) 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 <= -5.4e-134) || ~((x <= 1.5e-152))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.4e-134], N[Not[LessEqual[x, 1.5e-152]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{-134} \lor \neg \left(x \leq 1.5 \cdot 10^{-152}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -5.3999999999999996e-134 or 1.5e-152 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 79.5%
if -5.3999999999999996e-134 < x < 1.5e-152Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 80.2%
Final simplification79.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -720000000000.0) (not (<= y 6.5e+15))) (* x (+ y 0.5)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -720000000000.0) || !(y <= 6.5e+15)) {
tmp = x * (y + 0.5);
} else {
tmp = z - (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 ((y <= (-720000000000.0d0)) .or. (.not. (y <= 6.5d+15))) then
tmp = x * (y + 0.5d0)
else
tmp = z - (x * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -720000000000.0) || !(y <= 6.5e+15)) {
tmp = x * (y + 0.5);
} else {
tmp = z - (x * -0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -720000000000.0) or not (y <= 6.5e+15): tmp = x * (y + 0.5) else: tmp = z - (x * -0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -720000000000.0) || !(y <= 6.5e+15)) tmp = Float64(x * Float64(y + 0.5)); else tmp = Float64(z - Float64(x * -0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -720000000000.0) || ~((y <= 6.5e+15))) tmp = x * (y + 0.5); else tmp = z - (x * -0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -720000000000.0], N[Not[LessEqual[y, 6.5e+15]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], N[(z - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -720000000000 \lor \neg \left(y \leq 6.5 \cdot 10^{+15}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
if y < -7.2e11 or 6.5e15 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 79.4%
if -7.2e11 < y < 6.5e15Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
distribute-frac-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 97.2%
*-commutative97.2%
Simplified97.2%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2300.0) (not (<= y 0.5))) (+ z (* y x)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2300.0) || !(y <= 0.5)) {
tmp = z + (y * x);
} else {
tmp = z - (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 ((y <= (-2300.0d0)) .or. (.not. (y <= 0.5d0))) then
tmp = z + (y * x)
else
tmp = z - (x * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2300.0) || !(y <= 0.5)) {
tmp = z + (y * x);
} else {
tmp = z - (x * -0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2300.0) or not (y <= 0.5): tmp = z + (y * x) else: tmp = z - (x * -0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2300.0) || !(y <= 0.5)) tmp = Float64(z + Float64(y * x)); else tmp = Float64(z - Float64(x * -0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2300.0) || ~((y <= 0.5))) tmp = z + (y * x); else tmp = z - (x * -0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2300.0], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(z - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2300 \lor \neg \left(y \leq 0.5\right):\\
\;\;\;\;z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
if y < -2300 or 0.5 < y Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
distribute-frac-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 99.5%
mul-1-neg99.5%
distribute-rgt-neg-out99.5%
Simplified99.5%
if -2300 < y < 0.5Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
distribute-frac-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 97.6%
*-commutative97.6%
Simplified97.6%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.28e-17) (not (<= x 2.35e+139))) (* x 0.5) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.28e-17) || !(x <= 2.35e+139)) {
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 ((x <= (-1.28d-17)) .or. (.not. (x <= 2.35d+139))) 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 ((x <= -1.28e-17) || !(x <= 2.35e+139)) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.28e-17) or not (x <= 2.35e+139): tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.28e-17) || !(x <= 2.35e+139)) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.28e-17) || ~((x <= 2.35e+139))) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.28e-17], N[Not[LessEqual[x, 2.35e+139]], $MachinePrecision]], N[(x * 0.5), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.28 \cdot 10^{-17} \lor \neg \left(x \leq 2.35 \cdot 10^{+139}\right):\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.28e-17 or 2.35e139 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 90.5%
Taylor expanded in y around 0 33.2%
if -1.28e-17 < x < 2.35e139Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 60.1%
Final simplification48.3%
(FPCore (x y z) :precision binary64 (+ z (+ (/ x 2.0) (* y x))))
double code(double x, double y, double z) {
return z + ((x / 2.0) + (y * x));
}
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) + (y * x))
end function
public static double code(double x, double y, double z) {
return z + ((x / 2.0) + (y * x));
}
def code(x, y, z): return z + ((x / 2.0) + (y * x))
function code(x, y, z) return Float64(z + Float64(Float64(x / 2.0) + Float64(y * x))) end
function tmp = code(x, y, z) tmp = z + ((x / 2.0) + (y * x)); end
code[x_, y_, z_] := N[(z + N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(\frac{x}{2} + y \cdot x\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(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%
+-commutative100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
distribute-frac-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.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 38.8%
Final simplification38.8%
herbie shell --seed 2024041
(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))