
(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 8 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%
associate-/l*99.9%
associate-/r/100.0%
distribute-rgt-out--100.0%
fma-def100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -290000.0) (not (<= x 2.1e-10))) (* x (+ y 0.5)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -290000.0) || !(x <= 2.1e-10)) {
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 <= (-290000.0d0)) .or. (.not. (x <= 2.1d-10))) 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 <= -290000.0) || !(x <= 2.1e-10)) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -290000.0) or not (x <= 2.1e-10): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -290000.0) || !(x <= 2.1e-10)) 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 <= -290000.0) || ~((x <= 2.1e-10))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -290000.0], N[Not[LessEqual[x, 2.1e-10]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -290000 \lor \neg \left(x \leq 2.1 \cdot 10^{-10}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.9e5 or 2.1e-10 < x 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%
Taylor expanded in z around 0 87.5%
if -2.9e5 < x < 2.1e-10Initial 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 z around inf 72.3%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -25000000000.0) (not (<= x 2.35e+83))) (* x (+ y 0.5)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -25000000000.0) || !(x <= 2.35e+83)) {
tmp = x * (y + 0.5);
} else {
tmp = z + (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 ((x <= (-25000000000.0d0)) .or. (.not. (x <= 2.35d+83))) then
tmp = x * (y + 0.5d0)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -25000000000.0) || !(x <= 2.35e+83)) {
tmp = x * (y + 0.5);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -25000000000.0) or not (x <= 2.35e+83): tmp = x * (y + 0.5) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -25000000000.0) || !(x <= 2.35e+83)) tmp = Float64(x * Float64(y + 0.5)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -25000000000.0) || ~((x <= 2.35e+83))) tmp = x * (y + 0.5); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -25000000000.0], N[Not[LessEqual[x, 2.35e+83]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -25000000000 \lor \neg \left(x \leq 2.35 \cdot 10^{+83}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -2.5e10 or 2.3499999999999999e83 < x 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.8%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in z around 0 89.4%
if -2.5e10 < x < 2.3499999999999999e83Initial 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 91.4%
associate-*r*91.4%
neg-mul-191.4%
Simplified91.4%
cancel-sign-sub91.4%
+-commutative91.4%
Applied egg-rr91.4%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -165000.0) (not (<= y 0.00062))) (+ z (* x y)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -165000.0) || !(y <= 0.00062)) {
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 <= (-165000.0d0)) .or. (.not. (y <= 0.00062d0))) 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 <= -165000.0) || !(y <= 0.00062)) {
tmp = z + (x * y);
} else {
tmp = z - (x * -0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -165000.0) or not (y <= 0.00062): tmp = z + (x * y) else: tmp = z - (x * -0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -165000.0) || !(y <= 0.00062)) 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 <= -165000.0) || ~((y <= 0.00062))) tmp = z + (x * y); else tmp = z - (x * -0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -165000.0], N[Not[LessEqual[y, 0.00062]], $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 -165000 \lor \neg \left(y \leq 0.00062\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
if y < -165000 or 6.2e-4 < 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.9%
associate-*r*99.9%
neg-mul-199.9%
Simplified99.9%
cancel-sign-sub99.9%
+-commutative99.9%
Applied egg-rr99.9%
if -165000 < y < 6.2e-4Initial 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.6%
*-commutative98.6%
Simplified98.6%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -280000000.0) (not (<= x 5.2e+92))) (* x 0.5) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -280000000.0) || !(x <= 5.2e+92)) {
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 <= (-280000000.0d0)) .or. (.not. (x <= 5.2d+92))) 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 <= -280000000.0) || !(x <= 5.2e+92)) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -280000000.0) or not (x <= 5.2e+92): tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -280000000.0) || !(x <= 5.2e+92)) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -280000000.0) || ~((x <= 5.2e+92))) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -280000000.0], N[Not[LessEqual[x, 5.2e+92]], $MachinePrecision]], N[(x * 0.5), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -280000000 \lor \neg \left(x \leq 5.2 \cdot 10^{+92}\right):\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.8e8 or 5.1999999999999998e92 < x 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.8%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
add-cube-cbrt99.8%
fma-neg99.8%
pow299.8%
distribute-rgt-neg-in99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 52.5%
*-commutative52.5%
Simplified52.5%
Taylor expanded in z around 0 42.8%
*-commutative42.8%
Simplified42.8%
if -2.8e8 < x < 5.1999999999999998e92Initial 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 z around inf 67.5%
Final simplification57.5%
(FPCore (x y z) :precision binary64 (if (<= x -470000000.0) (* x 0.5) (if (<= x 0.013) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -470000000.0) {
tmp = x * 0.5;
} else if (x <= 0.013) {
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 (x <= (-470000000.0d0)) then
tmp = x * 0.5d0
else if (x <= 0.013d0) 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 (x <= -470000000.0) {
tmp = x * 0.5;
} else if (x <= 0.013) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -470000000.0: tmp = x * 0.5 elif x <= 0.013: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -470000000.0) tmp = Float64(x * 0.5); elseif (x <= 0.013) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -470000000.0) tmp = x * 0.5; elseif (x <= 0.013) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -470000000.0], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 0.013], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -470000000:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 0.013:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -4.7e8Initial 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.8%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
add-cube-cbrt99.7%
fma-neg99.7%
pow299.7%
distribute-rgt-neg-in99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 61.1%
*-commutative61.1%
Simplified61.1%
Taylor expanded in z around 0 49.4%
*-commutative49.4%
Simplified49.4%
if -4.7e8 < x < 0.0129999999999999994Initial 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 z around inf 71.9%
if 0.0129999999999999994 < x 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%
Taylor expanded in y around inf 67.3%
Final simplification65.1%
(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 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-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 z around inf 44.5%
Final simplification44.5%
herbie shell --seed 2024014
(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))