
(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%
*-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%
(FPCore (x y z)
:precision binary64
(if (<= y -5.7e+79)
(* x y)
(if (<= y -1.65e-149)
z
(if (<= y 4.6e-271) (* x 0.5) (if (<= y 1.1e+30) z (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.7e+79) {
tmp = x * y;
} else if (y <= -1.65e-149) {
tmp = z;
} else if (y <= 4.6e-271) {
tmp = x * 0.5;
} else if (y <= 1.1e+30) {
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 <= (-5.7d+79)) then
tmp = x * y
else if (y <= (-1.65d-149)) then
tmp = z
else if (y <= 4.6d-271) then
tmp = x * 0.5d0
else if (y <= 1.1d+30) 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 <= -5.7e+79) {
tmp = x * y;
} else if (y <= -1.65e-149) {
tmp = z;
} else if (y <= 4.6e-271) {
tmp = x * 0.5;
} else if (y <= 1.1e+30) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.7e+79: tmp = x * y elif y <= -1.65e-149: tmp = z elif y <= 4.6e-271: tmp = x * 0.5 elif y <= 1.1e+30: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.7e+79) tmp = Float64(x * y); elseif (y <= -1.65e-149) tmp = z; elseif (y <= 4.6e-271) tmp = Float64(x * 0.5); elseif (y <= 1.1e+30) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.7e+79) tmp = x * y; elseif (y <= -1.65e-149) tmp = z; elseif (y <= 4.6e-271) tmp = x * 0.5; elseif (y <= 1.1e+30) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.7e+79], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.65e-149], z, If[LessEqual[y, 4.6e-271], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 1.1e+30], z, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.7 \cdot 10^{+79}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.65 \cdot 10^{-149}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 4.6 \cdot 10^{-271}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+30}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -5.6999999999999997e79 or 1.1e30 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 69.7%
if -5.6999999999999997e79 < y < -1.65000000000000009e-149 or 4.60000000000000017e-271 < y < 1.1e30Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 61.9%
if -1.65000000000000009e-149 < y < 4.60000000000000017e-271Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 64.4%
Taylor expanded in y around 0 64.4%
*-commutative64.4%
Simplified64.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.5) (not (<= y 1.2e-9))) (+ z (* x y)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 1.2e-9)) {
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 <= (-0.5d0)) .or. (.not. (y <= 1.2d-9))) 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 <= -0.5) || !(y <= 1.2e-9)) {
tmp = z + (x * y);
} else {
tmp = z - (x * -0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.5) or not (y <= 1.2e-9): tmp = z + (x * y) else: tmp = z - (x * -0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.5) || !(y <= 1.2e-9)) 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 <= -0.5) || ~((y <= 1.2e-9))) tmp = z + (x * y); else tmp = z - (x * -0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.5], N[Not[LessEqual[y, 1.2e-9]], $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 -0.5 \lor \neg \left(y \leq 1.2 \cdot 10^{-9}\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
if y < -0.5 or 1.2e-9 < 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%
+-commutative100.0%
+-commutative100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 99.3%
mul-1-neg99.3%
*-commutative99.3%
distribute-rgt-neg-in99.3%
Simplified99.3%
*-commutative99.3%
cancel-sign-sub99.3%
+-commutative99.3%
Applied egg-rr99.3%
if -0.5 < y < 1.2e-9Initial 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%
+-commutative100.0%
+-commutative100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 98.8%
*-commutative98.8%
Simplified98.8%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.15e+96) (not (<= x 1.24e+92))) (* x (+ y 0.5)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.15e+96) || !(x <= 1.24e+92)) {
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 <= (-1.15d+96)) .or. (.not. (x <= 1.24d+92))) 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 <= -1.15e+96) || !(x <= 1.24e+92)) {
tmp = x * (y + 0.5);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.15e+96) or not (x <= 1.24e+92): tmp = x * (y + 0.5) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.15e+96) || !(x <= 1.24e+92)) 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 <= -1.15e+96) || ~((x <= 1.24e+92))) tmp = x * (y + 0.5); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.15e+96], N[Not[LessEqual[x, 1.24e+92]], $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 -1.15 \cdot 10^{+96} \lor \neg \left(x \leq 1.24 \cdot 10^{+92}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -1.15000000000000008e96 or 1.23999999999999999e92 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 90.5%
if -1.15000000000000008e96 < x < 1.23999999999999999e92Initial 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%
+-commutative100.0%
+-commutative100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 87.1%
mul-1-neg87.1%
*-commutative87.1%
distribute-rgt-neg-in87.1%
Simplified87.1%
*-commutative87.1%
cancel-sign-sub87.1%
+-commutative87.1%
Applied egg-rr87.1%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.0017) (not (<= x 3.9e-42))) (* x (+ y 0.5)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.0017) || !(x <= 3.9e-42)) {
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 <= (-0.0017d0)) .or. (.not. (x <= 3.9d-42))) 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 <= -0.0017) || !(x <= 3.9e-42)) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.0017) or not (x <= 3.9e-42): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.0017) || !(x <= 3.9e-42)) 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 <= -0.0017) || ~((x <= 3.9e-42))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.0017], N[Not[LessEqual[x, 3.9e-42]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0017 \lor \neg \left(x \leq 3.9 \cdot 10^{-42}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -0.00169999999999999991 or 3.9000000000000002e-42 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 83.0%
if -0.00169999999999999991 < x < 3.9000000000000002e-42Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 72.9%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.4e+97) (not (<= x 4.6e+114))) (* x 0.5) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.4e+97) || !(x <= 4.6e+114)) {
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 <= (-6.4d+97)) .or. (.not. (x <= 4.6d+114))) 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 <= -6.4e+97) || !(x <= 4.6e+114)) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.4e+97) or not (x <= 4.6e+114): tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.4e+97) || !(x <= 4.6e+114)) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.4e+97) || ~((x <= 4.6e+114))) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.4e+97], N[Not[LessEqual[x, 4.6e+114]], $MachinePrecision]], N[(x * 0.5), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.4 \cdot 10^{+97} \lor \neg \left(x \leq 4.6 \cdot 10^{+114}\right):\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -6.40000000000000032e97 or 4.6000000000000001e114 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 91.2%
Taylor expanded in y around 0 41.8%
*-commutative41.8%
Simplified41.8%
if -6.40000000000000032e97 < x < 4.6000000000000001e114Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 61.2%
Final simplification55.5%
(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%
+-commutative100.0%
+-commutative100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
distribute-lft-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 45.8%
herbie shell --seed 2024157
(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))