
(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 (+ (* x (- y -0.5)) z))
double code(double x, double y, double z) {
return (x * (y - -0.5)) + 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 * (y - (-0.5d0))) + z
end function
public static double code(double x, double y, double z) {
return (x * (y - -0.5)) + z;
}
def code(x, y, z): return (x * (y - -0.5)) + z
function code(x, y, z) return Float64(Float64(x * Float64(y - -0.5)) + z) end
function tmp = code(x, y, z) tmp = (x * (y - -0.5)) + z; end
code[x_, y_, z_] := N[(N[(x * N[(y - -0.5), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y - -0.5\right) + 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%
(FPCore (x y z)
:precision binary64
(if (<= y -1.42e+25)
(* x y)
(if (<= y 1.2e-196)
z
(if (<= y 5e-133) (* x 0.5) (if (<= y 1.65e+50) z (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.42e+25) {
tmp = x * y;
} else if (y <= 1.2e-196) {
tmp = z;
} else if (y <= 5e-133) {
tmp = x * 0.5;
} else if (y <= 1.65e+50) {
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.42d+25)) then
tmp = x * y
else if (y <= 1.2d-196) then
tmp = z
else if (y <= 5d-133) then
tmp = x * 0.5d0
else if (y <= 1.65d+50) 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.42e+25) {
tmp = x * y;
} else if (y <= 1.2e-196) {
tmp = z;
} else if (y <= 5e-133) {
tmp = x * 0.5;
} else if (y <= 1.65e+50) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.42e+25: tmp = x * y elif y <= 1.2e-196: tmp = z elif y <= 5e-133: tmp = x * 0.5 elif y <= 1.65e+50: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.42e+25) tmp = Float64(x * y); elseif (y <= 1.2e-196) tmp = z; elseif (y <= 5e-133) tmp = Float64(x * 0.5); elseif (y <= 1.65e+50) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.42e+25) tmp = x * y; elseif (y <= 1.2e-196) tmp = z; elseif (y <= 5e-133) tmp = x * 0.5; elseif (y <= 1.65e+50) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.42e+25], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.2e-196], z, If[LessEqual[y, 5e-133], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 1.65e+50], z, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.42 \cdot 10^{+25}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{-196}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-133}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{+50}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.4199999999999999e25 or 1.65e50 < 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 z around inf 89.7%
associate-/l*81.8%
Simplified81.8%
Taylor expanded in y around inf 68.9%
if -1.4199999999999999e25 < y < 1.2000000000000001e-196 or 4.9999999999999999e-133 < y < 1.65e50Initial 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 57.6%
if 1.2000000000000001e-196 < y < 4.9999999999999999e-133Initial 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 z around inf 82.7%
associate-/l*82.5%
Simplified82.5%
Taylor expanded in z around 0 75.7%
Taylor expanded in y around 0 75.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1800000.0) (not (<= y 0.5))) (+ z (* x y)) (+ z (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1800000.0) || !(y <= 0.5)) {
tmp = z + (x * y);
} 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 <= (-1800000.0d0)) .or. (.not. (y <= 0.5d0))) then
tmp = z + (x * y)
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 <= -1800000.0) || !(y <= 0.5)) {
tmp = z + (x * y);
} else {
tmp = z + (x * 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1800000.0) or not (y <= 0.5): tmp = z + (x * y) else: tmp = z + (x * 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1800000.0) || !(y <= 0.5)) tmp = Float64(z + Float64(x * y)); else tmp = Float64(z + Float64(x * 0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1800000.0) || ~((y <= 0.5))) tmp = z + (x * y); else tmp = z + (x * 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1800000.0], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1800000 \lor \neg \left(y \leq 0.5\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 0.5\\
\end{array}
\end{array}
if y < -1.8e6 or 0.5 < 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 99.0%
if -1.8e6 < y < 0.5Initial 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.9%
*-commutative98.9%
Simplified98.9%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.2e+24) (not (<= y 8.5e+177))) (* x y) (+ z (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.2e+24) || !(y <= 8.5e+177)) {
tmp = x * y;
} 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 <= (-8.2d+24)) .or. (.not. (y <= 8.5d+177))) then
tmp = x * y
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 <= -8.2e+24) || !(y <= 8.5e+177)) {
tmp = x * y;
} else {
tmp = z + (x * 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.2e+24) or not (y <= 8.5e+177): tmp = x * y else: tmp = z + (x * 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.2e+24) || !(y <= 8.5e+177)) tmp = Float64(x * y); else tmp = Float64(z + Float64(x * 0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -8.2e+24) || ~((y <= 8.5e+177))) tmp = x * y; else tmp = z + (x * 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.2e+24], N[Not[LessEqual[y, 8.5e+177]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.2 \cdot 10^{+24} \lor \neg \left(y \leq 8.5 \cdot 10^{+177}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 0.5\\
\end{array}
\end{array}
if y < -8.2000000000000002e24 or 8.5000000000000006e177 < 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 z around inf 88.7%
associate-/l*80.3%
Simplified80.3%
Taylor expanded in y around inf 72.2%
if -8.2000000000000002e24 < y < 8.5000000000000006e177Initial 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 90.3%
*-commutative90.3%
Simplified90.3%
Final simplification83.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.6e-29) (not (<= x 6.7e-40))) (* x (+ y 0.5)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.6e-29) || !(x <= 6.7e-40)) {
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.6d-29)) .or. (.not. (x <= 6.7d-40))) 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.6e-29) || !(x <= 6.7e-40)) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.6e-29) or not (x <= 6.7e-40): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.6e-29) || !(x <= 6.7e-40)) 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.6e-29) || ~((x <= 6.7e-40))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.6e-29], N[Not[LessEqual[x, 6.7e-40]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.6 \cdot 10^{-29} \lor \neg \left(x \leq 6.7 \cdot 10^{-40}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -5.6000000000000005e-29 or 6.6999999999999998e-40 < 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 z around inf 87.6%
associate-/l*87.4%
Simplified87.4%
Taylor expanded in z around 0 78.9%
if -5.6000000000000005e-29 < x < 6.6999999999999998e-40Initial 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 72.2%
Final simplification75.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.9e+107) (not (<= x 7.8e-40))) (* x 0.5) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.9e+107) || !(x <= 7.8e-40)) {
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 <= (-3.9d+107)) .or. (.not. (x <= 7.8d-40))) 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 <= -3.9e+107) || !(x <= 7.8e-40)) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.9e+107) or not (x <= 7.8e-40): tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.9e+107) || !(x <= 7.8e-40)) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.9e+107) || ~((x <= 7.8e-40))) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.9e+107], N[Not[LessEqual[x, 7.8e-40]], $MachinePrecision]], N[(x * 0.5), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{+107} \lor \neg \left(x \leq 7.8 \cdot 10^{-40}\right):\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -3.8999999999999998e107 or 7.79999999999999961e-40 < 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 z around inf 85.3%
associate-/l*85.2%
Simplified85.2%
Taylor expanded in z around 0 85.0%
Taylor expanded in y around 0 43.2%
if -3.8999999999999998e107 < x < 7.79999999999999961e-40Initial 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 67.5%
Final simplification57.2%
(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 44.8%
herbie shell --seed 2024132
(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))