
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.95e+78)
(not (or (<= y -8.2e+40) (and (not (<= y -3.7e-70)) (<= y 2.7e+56)))))
(/ y z)
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.95e+78) || !((y <= -8.2e+40) || (!(y <= -3.7e-70) && (y <= 2.7e+56)))) {
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 ((y <= (-1.95d+78)) .or. (.not. (y <= (-8.2d+40)) .or. (.not. (y <= (-3.7d-70))) .and. (y <= 2.7d+56))) 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 ((y <= -1.95e+78) || !((y <= -8.2e+40) || (!(y <= -3.7e-70) && (y <= 2.7e+56)))) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.95e+78) or not ((y <= -8.2e+40) or (not (y <= -3.7e-70) and (y <= 2.7e+56))): tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.95e+78) || !((y <= -8.2e+40) || (!(y <= -3.7e-70) && (y <= 2.7e+56)))) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.95e+78) || ~(((y <= -8.2e+40) || (~((y <= -3.7e-70)) && (y <= 2.7e+56))))) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.95e+78], N[Not[Or[LessEqual[y, -8.2e+40], And[N[Not[LessEqual[y, -3.7e-70]], $MachinePrecision], LessEqual[y, 2.7e+56]]]], $MachinePrecision]], N[(y / z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+78} \lor \neg \left(y \leq -8.2 \cdot 10^{+40} \lor \neg \left(y \leq -3.7 \cdot 10^{-70}\right) \land y \leq 2.7 \cdot 10^{+56}\right):\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.9500000000000002e78 or -8.2000000000000003e40 < y < -3.7e-70 or 2.7000000000000001e56 < y Initial program 100.0%
div-sub96.5%
sub-neg96.5%
distribute-frac-neg96.5%
+-commutative96.5%
associate-+r+96.5%
distribute-frac-neg96.5%
sub-neg96.5%
associate--r-96.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 74.5%
if -1.9500000000000002e78 < y < -8.2000000000000003e40 or -3.7e-70 < y < 2.7000000000000001e56Initial 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 55.6%
Final simplification64.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.2e-46) (not (<= y 1.1e-60))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.2e-46) || !(y <= 1.1e-60)) {
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 <= (-9.2d-46)) .or. (.not. (y <= 1.1d-60))) 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 <= -9.2e-46) || !(y <= 1.1e-60)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.2e-46) or not (y <= 1.1e-60): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.2e-46) || !(y <= 1.1e-60)) 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 <= -9.2e-46) || ~((y <= 1.1e-60))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.2e-46], N[Not[LessEqual[y, 1.1e-60]], $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 -9.2 \cdot 10^{-46} \lor \neg \left(y \leq 1.1 \cdot 10^{-60}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -9.1999999999999997e-46 or 1.0999999999999999e-60 < y Initial program 100.0%
div-sub97.3%
sub-neg97.3%
distribute-frac-neg97.3%
+-commutative97.3%
associate-+r+97.3%
distribute-frac-neg97.3%
sub-neg97.3%
associate--r-97.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 90.7%
neg-mul-190.7%
distribute-neg-frac290.7%
Simplified90.7%
Taylor expanded in x around 0 90.7%
+-commutative90.7%
Simplified90.7%
if -9.1999999999999997e-46 < y < 1.0999999999999999e-60Initial 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 91.3%
sub-neg91.3%
distribute-rgt-out91.3%
*-lft-identity91.3%
distribute-frac-neg291.3%
associate-*l/91.4%
*-lft-identity91.4%
distribute-frac-neg291.4%
sub-neg91.4%
Simplified91.4%
Final simplification91.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -880000.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -880000.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 <= (-880000.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 <= -880000.0) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -880000.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 <= -880000.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 <= -880000.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, -880000.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 -880000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -8.8e5 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 97.8%
neg-mul-197.8%
distribute-neg-frac297.8%
Simplified97.8%
Taylor expanded in x around 0 97.8%
+-commutative97.8%
Simplified97.8%
if -8.8e5 < z < 1Initial program 100.0%
div-sub96.6%
sub-neg96.6%
distribute-frac-neg96.6%
+-commutative96.6%
associate-+r+96.6%
distribute-frac-neg96.6%
sub-neg96.6%
associate--r-96.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.7%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= x -3.1e+242) (/ x (- z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.1e+242) {
tmp = x / -z;
} else {
tmp = x + (y / 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.1d+242)) then
tmp = x / -z
else
tmp = x + (y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.1e+242) {
tmp = x / -z;
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.1e+242: tmp = x / -z else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.1e+242) tmp = Float64(x / Float64(-z)); else tmp = Float64(x + Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.1e+242) tmp = x / -z; else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.1e+242], N[(x / (-z)), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{+242}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -3.1000000000000001e242Initial 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 100.0%
sub-neg100.0%
distribute-rgt-out100.0%
*-lft-identity100.0%
distribute-frac-neg2100.0%
associate-*l/100.0%
*-lft-identity100.0%
distribute-frac-neg2100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in z around 0 66.5%
associate-*r/66.5%
neg-mul-166.5%
Simplified66.5%
if -3.1000000000000001e242 < x Initial program 100.0%
div-sub98.3%
sub-neg98.3%
distribute-frac-neg98.3%
+-commutative98.3%
associate-+r+98.3%
distribute-frac-neg98.3%
sub-neg98.3%
associate--r-98.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 80.7%
neg-mul-180.7%
distribute-neg-frac280.7%
Simplified80.7%
Taylor expanded in x around 0 80.7%
+-commutative80.7%
Simplified80.7%
Final simplification80.0%
(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-sub98.4%
sub-neg98.4%
distribute-frac-neg98.4%
+-commutative98.4%
associate-+r+98.4%
distribute-frac-neg98.4%
sub-neg98.4%
associate--r-98.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 39.1%
Final simplification39.1%
herbie shell --seed 2024048
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))