
(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 (+ 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*99.9%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -6.8e+37)
(* x y)
(if (<= y -3.4e-84)
z
(if (<= y 1.25e-241)
(* x 0.5)
(if (<= y 9e-194)
z
(if (<= y 1.9e-108) (* x 0.5) (if (<= y 1.9e+81) z (* x y))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e+37) {
tmp = x * y;
} else if (y <= -3.4e-84) {
tmp = z;
} else if (y <= 1.25e-241) {
tmp = x * 0.5;
} else if (y <= 9e-194) {
tmp = z;
} else if (y <= 1.9e-108) {
tmp = x * 0.5;
} else if (y <= 1.9e+81) {
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 <= (-6.8d+37)) then
tmp = x * y
else if (y <= (-3.4d-84)) then
tmp = z
else if (y <= 1.25d-241) then
tmp = x * 0.5d0
else if (y <= 9d-194) then
tmp = z
else if (y <= 1.9d-108) then
tmp = x * 0.5d0
else if (y <= 1.9d+81) 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 <= -6.8e+37) {
tmp = x * y;
} else if (y <= -3.4e-84) {
tmp = z;
} else if (y <= 1.25e-241) {
tmp = x * 0.5;
} else if (y <= 9e-194) {
tmp = z;
} else if (y <= 1.9e-108) {
tmp = x * 0.5;
} else if (y <= 1.9e+81) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.8e+37: tmp = x * y elif y <= -3.4e-84: tmp = z elif y <= 1.25e-241: tmp = x * 0.5 elif y <= 9e-194: tmp = z elif y <= 1.9e-108: tmp = x * 0.5 elif y <= 1.9e+81: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.8e+37) tmp = Float64(x * y); elseif (y <= -3.4e-84) tmp = z; elseif (y <= 1.25e-241) tmp = Float64(x * 0.5); elseif (y <= 9e-194) tmp = z; elseif (y <= 1.9e-108) tmp = Float64(x * 0.5); elseif (y <= 1.9e+81) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.8e+37) tmp = x * y; elseif (y <= -3.4e-84) tmp = z; elseif (y <= 1.25e-241) tmp = x * 0.5; elseif (y <= 9e-194) tmp = z; elseif (y <= 1.9e-108) tmp = x * 0.5; elseif (y <= 1.9e+81) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.8e+37], N[(x * y), $MachinePrecision], If[LessEqual[y, -3.4e-84], z, If[LessEqual[y, 1.25e-241], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 9e-194], z, If[LessEqual[y, 1.9e-108], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 1.9e+81], z, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+37}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -3.4 \cdot 10^{-84}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-241}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 9 \cdot 10^{-194}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{-108}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{+81}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -6.80000000000000011e37 or 1.9e81 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 77.7%
if -6.80000000000000011e37 < y < -3.40000000000000021e-84 or 1.25e-241 < y < 8.9999999999999997e-194 or 1.89999999999999987e-108 < y < 1.9e81Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 62.5%
if -3.40000000000000021e-84 < y < 1.25e-241 or 8.9999999999999997e-194 < y < 1.89999999999999987e-108Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 65.6%
Taylor expanded in y around 0 65.6%
Final simplification69.4%
(FPCore (x y z)
:precision binary64
(if (or (<= x -98000.0)
(and (not (<= x -9e-79)) (or (<= x -7.5e-141) (not (<= x 2e-58)))))
(* x (+ y 0.5))
z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -98000.0) || (!(x <= -9e-79) && ((x <= -7.5e-141) || !(x <= 2e-58)))) {
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 <= (-98000.0d0)) .or. (.not. (x <= (-9d-79))) .and. (x <= (-7.5d-141)) .or. (.not. (x <= 2d-58))) 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 <= -98000.0) || (!(x <= -9e-79) && ((x <= -7.5e-141) || !(x <= 2e-58)))) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -98000.0) or (not (x <= -9e-79) and ((x <= -7.5e-141) or not (x <= 2e-58))): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -98000.0) || (!(x <= -9e-79) && ((x <= -7.5e-141) || !(x <= 2e-58)))) 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 <= -98000.0) || (~((x <= -9e-79)) && ((x <= -7.5e-141) || ~((x <= 2e-58))))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -98000.0], And[N[Not[LessEqual[x, -9e-79]], $MachinePrecision], Or[LessEqual[x, -7.5e-141], N[Not[LessEqual[x, 2e-58]], $MachinePrecision]]]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -98000 \lor \neg \left(x \leq -9 \cdot 10^{-79}\right) \land \left(x \leq -7.5 \cdot 10^{-141} \lor \neg \left(x \leq 2 \cdot 10^{-58}\right)\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -98000 or -9.0000000000000006e-79 < x < -7.50000000000000046e-141 or 2.0000000000000001e-58 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 86.4%
if -98000 < x < -9.0000000000000006e-79 or -7.50000000000000046e-141 < x < 2.0000000000000001e-58Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 78.2%
Final simplification83.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -9e+25) (not (<= y 1.85e+81))) (* x y) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9e+25) || !(y <= 1.85e+81)) {
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 <= (-9d+25)) .or. (.not. (y <= 1.85d+81))) 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 <= -9e+25) || !(y <= 1.85e+81)) {
tmp = x * y;
} else {
tmp = z - (x * -0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9e+25) or not (y <= 1.85e+81): tmp = x * y else: tmp = z - (x * -0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9e+25) || !(y <= 1.85e+81)) 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 <= -9e+25) || ~((y <= 1.85e+81))) tmp = x * y; else tmp = z - (x * -0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9e+25], N[Not[LessEqual[y, 1.85e+81]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(z - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{+25} \lor \neg \left(y \leq 1.85 \cdot 10^{+81}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
if y < -9.0000000000000006e25 or 1.85e81 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 76.7%
if -9.0000000000000006e25 < y < 1.85e81Initial 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 94.2%
*-commutative94.2%
Simplified94.2%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -150000.0) (not (<= y 0.5))) (+ z (* x y)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -150000.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 <= (-150000.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 <= -150000.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 <= -150000.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 <= -150000.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 <= -150000.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, -150000.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 -150000 \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.5e5 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 -1.5e5 < 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 98.3%
*-commutative98.3%
Simplified98.3%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.8e+34) (not (<= x 4.2e-26))) (* x 0.5) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e+34) || !(x <= 4.2e-26)) {
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 <= (-2.8d+34)) .or. (.not. (x <= 4.2d-26))) 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 <= -2.8e+34) || !(x <= 4.2e-26)) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.8e+34) or not (x <= 4.2e-26): tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.8e+34) || !(x <= 4.2e-26)) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.8e+34) || ~((x <= 4.2e-26))) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.8e+34], N[Not[LessEqual[x, 4.2e-26]], $MachinePrecision]], N[(x * 0.5), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{+34} \lor \neg \left(x \leq 4.2 \cdot 10^{-26}\right):\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.80000000000000008e34 or 4.20000000000000016e-26 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 87.7%
Taylor expanded in y around 0 45.5%
if -2.80000000000000008e34 < x < 4.20000000000000016e-26Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 68.2%
Final simplification55.8%
(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.4%
Final simplification38.4%
herbie shell --seed 2024018
(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))