
(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 7 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 (<= z -9e+14)
x
(if (<= z -4.2e-63)
(/ y z)
(if (<= z 8e-143)
(/ (- x) z)
(if (or (<= z 1e+34) (and (not (<= z 1.5e+135)) (<= z 5.5e+184)))
(/ y z)
x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9e+14) {
tmp = x;
} else if (z <= -4.2e-63) {
tmp = y / z;
} else if (z <= 8e-143) {
tmp = -x / z;
} else if ((z <= 1e+34) || (!(z <= 1.5e+135) && (z <= 5.5e+184))) {
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 <= (-9d+14)) then
tmp = x
else if (z <= (-4.2d-63)) then
tmp = y / z
else if (z <= 8d-143) then
tmp = -x / z
else if ((z <= 1d+34) .or. (.not. (z <= 1.5d+135)) .and. (z <= 5.5d+184)) 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 <= -9e+14) {
tmp = x;
} else if (z <= -4.2e-63) {
tmp = y / z;
} else if (z <= 8e-143) {
tmp = -x / z;
} else if ((z <= 1e+34) || (!(z <= 1.5e+135) && (z <= 5.5e+184))) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9e+14: tmp = x elif z <= -4.2e-63: tmp = y / z elif z <= 8e-143: tmp = -x / z elif (z <= 1e+34) or (not (z <= 1.5e+135) and (z <= 5.5e+184)): tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9e+14) tmp = x; elseif (z <= -4.2e-63) tmp = Float64(y / z); elseif (z <= 8e-143) tmp = Float64(Float64(-x) / z); elseif ((z <= 1e+34) || (!(z <= 1.5e+135) && (z <= 5.5e+184))) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9e+14) tmp = x; elseif (z <= -4.2e-63) tmp = y / z; elseif (z <= 8e-143) tmp = -x / z; elseif ((z <= 1e+34) || (~((z <= 1.5e+135)) && (z <= 5.5e+184))) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9e+14], x, If[LessEqual[z, -4.2e-63], N[(y / z), $MachinePrecision], If[LessEqual[z, 8e-143], N[((-x) / z), $MachinePrecision], If[Or[LessEqual[z, 1e+34], And[N[Not[LessEqual[z, 1.5e+135]], $MachinePrecision], LessEqual[z, 5.5e+184]]], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{+14}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -4.2 \cdot 10^{-63}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 8 \cdot 10^{-143}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{elif}\;z \leq 10^{+34} \lor \neg \left(z \leq 1.5 \cdot 10^{+135}\right) \land z \leq 5.5 \cdot 10^{+184}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9e14 or 9.99999999999999946e33 < z < 1.5e135 or 5.5000000000000002e184 < 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 82.2%
if -9e14 < z < -4.2e-63 or 7.9999999999999996e-143 < z < 9.99999999999999946e33 or 1.5e135 < z < 5.5000000000000002e184Initial 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 71.8%
if -4.2e-63 < z < 7.9999999999999996e-143Initial program 100.0%
div-sub91.2%
sub-neg91.2%
distribute-frac-neg91.2%
+-commutative91.2%
associate-+r+91.2%
distribute-frac-neg91.2%
sub-neg91.2%
associate--r-91.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 62.4%
distribute-lft-out--62.4%
*-rgt-identity62.4%
associate-*r/62.5%
*-rgt-identity62.5%
Simplified62.5%
Taylor expanded in z around 0 62.5%
mul-1-neg62.5%
distribute-frac-neg62.5%
Simplified62.5%
Final simplification72.6%
(FPCore (x y z)
:precision binary64
(if (<= z -1.95e+15)
x
(if (or (<= z 7.8e+26) (and (not (<= z 1.6e+133)) (<= z 1.75e+184)))
(/ y z)
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.95e+15) {
tmp = x;
} else if ((z <= 7.8e+26) || (!(z <= 1.6e+133) && (z <= 1.75e+184))) {
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.95d+15)) then
tmp = x
else if ((z <= 7.8d+26) .or. (.not. (z <= 1.6d+133)) .and. (z <= 1.75d+184)) 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.95e+15) {
tmp = x;
} else if ((z <= 7.8e+26) || (!(z <= 1.6e+133) && (z <= 1.75e+184))) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.95e+15: tmp = x elif (z <= 7.8e+26) or (not (z <= 1.6e+133) and (z <= 1.75e+184)): tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.95e+15) tmp = x; elseif ((z <= 7.8e+26) || (!(z <= 1.6e+133) && (z <= 1.75e+184))) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.95e+15) tmp = x; elseif ((z <= 7.8e+26) || (~((z <= 1.6e+133)) && (z <= 1.75e+184))) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.95e+15], x, If[Or[LessEqual[z, 7.8e+26], And[N[Not[LessEqual[z, 1.6e+133]], $MachinePrecision], LessEqual[z, 1.75e+184]]], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{+15}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7.8 \cdot 10^{+26} \lor \neg \left(z \leq 1.6 \cdot 10^{+133}\right) \land z \leq 1.75 \cdot 10^{+184}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.95e15 or 7.8e26 < z < 1.59999999999999999e133 or 1.74999999999999989e184 < 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 82.2%
if -1.95e15 < z < 7.8e26 or 1.59999999999999999e133 < z < 1.74999999999999989e184Initial program 100.0%
div-sub94.8%
sub-neg94.8%
distribute-frac-neg94.8%
+-commutative94.8%
associate-+r+94.8%
distribute-frac-neg94.8%
sub-neg94.8%
associate--r-94.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 56.4%
Final simplification66.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.2e+14) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.2e+14) || !(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 <= (-6.2d+14)) .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 <= -6.2e+14) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.2e+14) 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 <= -6.2e+14) || !(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 <= -6.2e+14) || ~((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, -6.2e+14], 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 -6.2 \cdot 10^{+14} \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -6.2e14 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.6%
neg-mul-199.6%
Simplified99.6%
Taylor expanded in x around 0 99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
*-lft-identity99.6%
+-commutative99.6%
Simplified99.6%
if -6.2e14 < z < 1Initial program 100.0%
div-sub94.1%
sub-neg94.1%
distribute-frac-neg94.1%
+-commutative94.1%
associate-+r+94.1%
distribute-frac-neg94.1%
sub-neg94.1%
associate--r-94.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.4%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1e+92) (not (<= y 0.01))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1e+92) || !(y <= 0.01)) {
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 <= (-1d+92)) .or. (.not. (y <= 0.01d0))) 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 <= -1e+92) || !(y <= 0.01)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1e+92) or not (y <= 0.01): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1e+92) || !(y <= 0.01)) 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 <= -1e+92) || ~((y <= 0.01))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1e+92], N[Not[LessEqual[y, 0.01]], $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 -1 \cdot 10^{+92} \lor \neg \left(y \leq 0.01\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -1e92 or 0.0100000000000000002 < y Initial program 100.0%
div-sub95.0%
sub-neg95.0%
distribute-frac-neg95.0%
+-commutative95.0%
associate-+r+95.0%
distribute-frac-neg95.0%
sub-neg95.0%
associate--r-95.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 94.1%
neg-mul-194.1%
Simplified94.1%
Taylor expanded in x around 0 94.1%
cancel-sign-sub-inv94.1%
metadata-eval94.1%
*-lft-identity94.1%
+-commutative94.1%
Simplified94.1%
if -1e92 < y < 0.0100000000000000002Initial program 100.0%
div-sub98.5%
sub-neg98.5%
distribute-frac-neg98.5%
+-commutative98.5%
associate-+r+98.5%
distribute-frac-neg98.5%
sub-neg98.5%
associate--r-98.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 83.8%
distribute-lft-out--83.8%
*-rgt-identity83.8%
associate-*r/83.8%
*-rgt-identity83.8%
Simplified83.8%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.3e-131) (not (<= z 4.7e-150))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.3e-131) || !(z <= 4.7e-150)) {
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 ((z <= (-4.3d-131)) .or. (.not. (z <= 4.7d-150))) 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 ((z <= -4.3e-131) || !(z <= 4.7e-150)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.3e-131) or not (z <= 4.7e-150): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.3e-131) || !(z <= 4.7e-150)) 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 ((z <= -4.3e-131) || ~((z <= 4.7e-150))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.3e-131], N[Not[LessEqual[z, 4.7e-150]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.3 \cdot 10^{-131} \lor \neg \left(z \leq 4.7 \cdot 10^{-150}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if z < -4.30000000000000019e-131 or 4.6999999999999999e-150 < z 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 86.4%
neg-mul-186.4%
Simplified86.4%
Taylor expanded in x around 0 86.4%
cancel-sign-sub-inv86.4%
metadata-eval86.4%
*-lft-identity86.4%
+-commutative86.4%
Simplified86.4%
if -4.30000000000000019e-131 < z < 4.6999999999999999e-150Initial program 100.0%
div-sub90.3%
sub-neg90.3%
distribute-frac-neg90.3%
+-commutative90.3%
associate-+r+90.3%
distribute-frac-neg90.3%
sub-neg90.3%
associate--r-90.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 66.0%
distribute-lft-out--66.0%
*-rgt-identity66.0%
associate-*r/66.0%
*-rgt-identity66.0%
Simplified66.0%
Taylor expanded in z around 0 66.0%
mul-1-neg66.0%
distribute-frac-neg66.0%
Simplified66.0%
Final simplification80.7%
(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-sub96.9%
sub-neg96.9%
distribute-frac-neg96.9%
+-commutative96.9%
associate-+r+96.9%
distribute-frac-neg96.9%
sub-neg96.9%
associate--r-96.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 35.7%
herbie shell --seed 2024191
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))