
(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 7 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%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
fma-define100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.55e+15)
(* x y)
(if (<= y -1.06e-99)
z
(if (<= y -3.2e-225)
(* x 0.5)
(if (<= y 5.9e-179)
z
(if (<= y 5.6e-111) (* x 0.5) (if (<= y 26000000.0) z (* x y))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.55e+15) {
tmp = x * y;
} else if (y <= -1.06e-99) {
tmp = z;
} else if (y <= -3.2e-225) {
tmp = x * 0.5;
} else if (y <= 5.9e-179) {
tmp = z;
} else if (y <= 5.6e-111) {
tmp = x * 0.5;
} else if (y <= 26000000.0) {
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 <= (-1.55d+15)) then
tmp = x * y
else if (y <= (-1.06d-99)) then
tmp = z
else if (y <= (-3.2d-225)) then
tmp = x * 0.5d0
else if (y <= 5.9d-179) then
tmp = z
else if (y <= 5.6d-111) then
tmp = x * 0.5d0
else if (y <= 26000000.0d0) 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 <= -1.55e+15) {
tmp = x * y;
} else if (y <= -1.06e-99) {
tmp = z;
} else if (y <= -3.2e-225) {
tmp = x * 0.5;
} else if (y <= 5.9e-179) {
tmp = z;
} else if (y <= 5.6e-111) {
tmp = x * 0.5;
} else if (y <= 26000000.0) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.55e+15: tmp = x * y elif y <= -1.06e-99: tmp = z elif y <= -3.2e-225: tmp = x * 0.5 elif y <= 5.9e-179: tmp = z elif y <= 5.6e-111: tmp = x * 0.5 elif y <= 26000000.0: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.55e+15) tmp = Float64(x * y); elseif (y <= -1.06e-99) tmp = z; elseif (y <= -3.2e-225) tmp = Float64(x * 0.5); elseif (y <= 5.9e-179) tmp = z; elseif (y <= 5.6e-111) tmp = Float64(x * 0.5); elseif (y <= 26000000.0) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.55e+15) tmp = x * y; elseif (y <= -1.06e-99) tmp = z; elseif (y <= -3.2e-225) tmp = x * 0.5; elseif (y <= 5.9e-179) tmp = z; elseif (y <= 5.6e-111) tmp = x * 0.5; elseif (y <= 26000000.0) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.55e+15], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.06e-99], z, If[LessEqual[y, -3.2e-225], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 5.9e-179], z, If[LessEqual[y, 5.6e-111], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 26000000.0], z, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{+15}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.06 \cdot 10^{-99}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -3.2 \cdot 10^{-225}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 5.9 \cdot 10^{-179}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 5.6 \cdot 10^{-111}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 26000000:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.55e15 or 2.6e7 < y Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 76.3%
if -1.55e15 < y < -1.0599999999999999e-99 or -3.19999999999999975e-225 < y < 5.90000000000000029e-179 or 5.5999999999999999e-111 < y < 2.6e7Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 64.5%
if -1.0599999999999999e-99 < y < -3.19999999999999975e-225 or 5.90000000000000029e-179 < y < 5.5999999999999999e-111Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 71.0%
Taylor expanded in y around 0 71.0%
*-commutative71.0%
Simplified71.0%
Final simplification71.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -235.0) (not (<= x 2.8e-30))) (* x (+ y 0.5)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -235.0) || !(x <= 2.8e-30)) {
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 <= (-235.0d0)) .or. (.not. (x <= 2.8d-30))) 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 <= -235.0) || !(x <= 2.8e-30)) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -235.0) or not (x <= 2.8e-30): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -235.0) || !(x <= 2.8e-30)) 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 <= -235.0) || ~((x <= 2.8e-30))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -235.0], N[Not[LessEqual[x, 2.8e-30]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -235 \lor \neg \left(x \leq 2.8 \cdot 10^{-30}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -235 or 2.79999999999999988e-30 < x Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 83.6%
if -235 < x < 2.79999999999999988e-30Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 68.4%
Final simplification77.3%
(FPCore (x y z) :precision binary64 (if (<= y -4.4e+19) (* x y) (if (<= y 29000000.0) (+ z (* x 0.5)) (* x (+ y 0.5)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.4e+19) {
tmp = x * y;
} else if (y <= 29000000.0) {
tmp = z + (x * 0.5);
} else {
tmp = x * (y + 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 <= (-4.4d+19)) then
tmp = x * y
else if (y <= 29000000.0d0) then
tmp = z + (x * 0.5d0)
else
tmp = x * (y + 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.4e+19) {
tmp = x * y;
} else if (y <= 29000000.0) {
tmp = z + (x * 0.5);
} else {
tmp = x * (y + 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.4e+19: tmp = x * y elif y <= 29000000.0: tmp = z + (x * 0.5) else: tmp = x * (y + 0.5) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.4e+19) tmp = Float64(x * y); elseif (y <= 29000000.0) tmp = Float64(z + Float64(x * 0.5)); else tmp = Float64(x * Float64(y + 0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.4e+19) tmp = x * y; elseif (y <= 29000000.0) tmp = z + (x * 0.5); else tmp = x * (y + 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.4e+19], N[(x * y), $MachinePrecision], If[LessEqual[y, 29000000.0], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{+19}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 29000000:\\
\;\;\;\;z + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\end{array}
\end{array}
if y < -4.4e19Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 83.6%
if -4.4e19 < y < 2.9e7Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 98.0%
*-commutative98.0%
Simplified98.0%
if 2.9e7 < y Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 69.9%
Final simplification87.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.02e+129) (not (<= x 1.36e+60))) (* x 0.5) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.02e+129) || !(x <= 1.36e+60)) {
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.02d+129)) .or. (.not. (x <= 1.36d+60))) 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.02e+129) || !(x <= 1.36e+60)) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.02e+129) or not (x <= 1.36e+60): tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.02e+129) || !(x <= 1.36e+60)) 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.02e+129) || ~((x <= 1.36e+60))) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.02e+129], N[Not[LessEqual[x, 1.36e+60]], $MachinePrecision]], N[(x * 0.5), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.02 \cdot 10^{+129} \lor \neg \left(x \leq 1.36 \cdot 10^{+60}\right):\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.01999999999999996e129 or 1.36000000000000002e60 < x Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 88.8%
Taylor expanded in y around 0 40.5%
*-commutative40.5%
Simplified40.5%
if -1.01999999999999996e129 < x < 1.36000000000000002e60Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 55.5%
Final simplification49.6%
(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-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.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%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 38.8%
Final simplification38.8%
herbie shell --seed 2024071
(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))