
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
return x + ((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 + ((y - x) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) / z);
}
def code(x, y, z): return x + ((y - x) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) / z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
return x + ((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 + ((y - x) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) / z);
}
def code(x, y, z): return x + ((y - x) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) / z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{z}
\end{array}
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
return x + ((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 + ((y - x) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) / z);
}
def code(x, y, z): return x + ((y - x) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) / z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{z}
\end{array}
Initial program 100.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -540000000000.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -540000000000.0) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / 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 ((z <= (-540000000000.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = x + (y / z)
else
tmp = (y - x) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -540000000000.0) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -540000000000.0) or not (z <= 1.0): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -540000000000.0) || !(z <= 1.0)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(Float64(y - x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -540000000000.0) || ~((z <= 1.0))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -540000000000.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -540000000000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -5.4e11 or 1 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 99.8%
neg-mul-199.8%
Simplified99.8%
div-inv99.7%
cancel-sign-sub99.7%
*-commutative99.7%
+-commutative99.7%
associate-*l/99.8%
*-un-lft-identity99.8%
Applied egg-rr99.8%
if -5.4e11 < z < 1Initial program 100.0%
div-sub99.3%
sub-neg99.3%
distribute-frac-neg99.3%
+-commutative99.3%
associate-+r+99.3%
distribute-frac-neg99.3%
sub-neg99.3%
associate--r-99.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.1%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.4e-101) (not (<= y 3.8e-42))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.4e-101) || !(y <= 3.8e-42)) {
tmp = x + (y / z);
} else {
tmp = x - (x / 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 ((y <= (-2.4d-101)) .or. (.not. (y <= 3.8d-42))) then
tmp = x + (y / z)
else
tmp = x - (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.4e-101) || !(y <= 3.8e-42)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.4e-101) or not (y <= 3.8e-42): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.4e-101) || !(y <= 3.8e-42)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(x - Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.4e-101) || ~((y <= 3.8e-42))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.4e-101], N[Not[LessEqual[y, 3.8e-42]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{-101} \lor \neg \left(y \leq 3.8 \cdot 10^{-42}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.4e-101 or 3.80000000000000017e-42 < y Initial program 100.0%
div-sub99.4%
sub-neg99.4%
distribute-frac-neg99.4%
+-commutative99.4%
associate-+r+99.4%
distribute-frac-neg99.4%
sub-neg99.4%
associate--r-99.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 89.2%
neg-mul-189.2%
Simplified89.2%
div-inv89.0%
cancel-sign-sub89.0%
*-commutative89.0%
+-commutative89.0%
associate-*l/89.2%
*-un-lft-identity89.2%
Applied egg-rr89.2%
if -2.4e-101 < y < 3.80000000000000017e-42Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 89.3%
distribute-lft-out--89.3%
*-rgt-identity89.3%
associate-*r/89.5%
*-rgt-identity89.5%
Simplified89.5%
Final simplification89.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.8e-253) (not (<= y 2e-244))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e-253) || !(y <= 2e-244)) {
tmp = x + (y / z);
} else {
tmp = -x / 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 ((y <= (-5.8d-253)) .or. (.not. (y <= 2d-244))) then
tmp = x + (y / z)
else
tmp = -x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e-253) || !(y <= 2e-244)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.8e-253) or not (y <= 2e-244): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.8e-253) || !(y <= 2e-244)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(Float64(-x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.8e-253) || ~((y <= 2e-244))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.8e-253], N[Not[LessEqual[y, 2e-244]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-253} \lor \neg \left(y \leq 2 \cdot 10^{-244}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if y < -5.7999999999999996e-253 or 1.9999999999999999e-244 < y Initial program 100.0%
div-sub99.5%
sub-neg99.5%
distribute-frac-neg99.5%
+-commutative99.5%
associate-+r+99.5%
distribute-frac-neg99.5%
sub-neg99.5%
associate--r-99.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 84.5%
neg-mul-184.5%
Simplified84.5%
div-inv84.4%
cancel-sign-sub84.4%
*-commutative84.4%
+-commutative84.4%
associate-*l/84.5%
*-un-lft-identity84.5%
Applied egg-rr84.5%
if -5.7999999999999996e-253 < y < 1.9999999999999999e-244Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 99.7%
distribute-lft-out--99.7%
*-rgt-identity99.7%
associate-*r/100.0%
*-rgt-identity100.0%
Simplified100.0%
Taylor expanded in z around 0 75.3%
associate-*r/75.3%
neg-mul-175.3%
Simplified75.3%
Final simplification83.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.2e+16) x (if (<= z 5.8e+97) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.2e+16) {
tmp = x;
} else if (z <= 5.8e+97) {
tmp = y / z;
} else {
tmp = x;
}
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 (z <= (-1.2d+16)) then
tmp = x
else if (z <= 5.8d+97) then
tmp = y / z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.2e+16) {
tmp = x;
} else if (z <= 5.8e+97) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.2e+16: tmp = x elif z <= 5.8e+97: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.2e+16) tmp = x; elseif (z <= 5.8e+97) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.2e+16) tmp = x; elseif (z <= 5.8e+97) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.2e+16], x, If[LessEqual[z, 5.8e+97], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{+16}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.8 \cdot 10^{+97}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.2e16 or 5.79999999999999974e97 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 78.2%
if -1.2e16 < z < 5.79999999999999974e97Initial program 100.0%
div-sub99.4%
sub-neg99.4%
distribute-frac-neg99.4%
+-commutative99.4%
associate-+r+99.4%
distribute-frac-neg99.4%
sub-neg99.4%
associate--r-99.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 61.2%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
div-sub99.6%
sub-neg99.6%
distribute-frac-neg99.6%
+-commutative99.6%
associate-+r+99.6%
distribute-frac-neg99.6%
sub-neg99.6%
associate--r-99.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 34.2%
herbie shell --seed 2024165
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))