
(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
(let* ((t_0 (/ (- x) z)))
(if (<= z -4.45e+46)
x
(if (<= z -1.8e-100)
(/ y z)
(if (<= z -1.1e-213)
t_0
(if (<= z 1.02e-209) (/ y z) (if (<= z 1.0) t_0 x)))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -4.45e+46) {
tmp = x;
} else if (z <= -1.8e-100) {
tmp = y / z;
} else if (z <= -1.1e-213) {
tmp = t_0;
} else if (z <= 1.02e-209) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = -x / z
if (z <= (-4.45d+46)) then
tmp = x
else if (z <= (-1.8d-100)) then
tmp = y / z
else if (z <= (-1.1d-213)) then
tmp = t_0
else if (z <= 1.02d-209) then
tmp = y / z
else if (z <= 1.0d0) then
tmp = t_0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -4.45e+46) {
tmp = x;
} else if (z <= -1.8e-100) {
tmp = y / z;
} else if (z <= -1.1e-213) {
tmp = t_0;
} else if (z <= 1.02e-209) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -4.45e+46: tmp = x elif z <= -1.8e-100: tmp = y / z elif z <= -1.1e-213: tmp = t_0 elif z <= 1.02e-209: tmp = y / z elif z <= 1.0: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -4.45e+46) tmp = x; elseif (z <= -1.8e-100) tmp = Float64(y / z); elseif (z <= -1.1e-213) tmp = t_0; elseif (z <= 1.02e-209) tmp = Float64(y / z); elseif (z <= 1.0) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x / z; tmp = 0.0; if (z <= -4.45e+46) tmp = x; elseif (z <= -1.8e-100) tmp = y / z; elseif (z <= -1.1e-213) tmp = t_0; elseif (z <= 1.02e-209) tmp = y / z; elseif (z <= 1.0) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -4.45e+46], x, If[LessEqual[z, -1.8e-100], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.1e-213], t$95$0, If[LessEqual[z, 1.02e-209], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.0], t$95$0, x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -4.45 \cdot 10^{+46}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.8 \cdot 10^{-100}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -1.1 \cdot 10^{-213}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.02 \cdot 10^{-209}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.4499999999999998e46 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 z around inf 75.8%
if -4.4499999999999998e46 < z < -1.7999999999999999e-100 or -1.10000000000000005e-213 < z < 1.01999999999999999e-209Initial 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 66.7%
if -1.7999999999999999e-100 < z < -1.10000000000000005e-213 or 1.01999999999999999e-209 < z < 1Initial program 100.0%
div-sub95.1%
sub-neg95.1%
distribute-frac-neg95.1%
+-commutative95.1%
associate-+r+95.1%
distribute-frac-neg95.1%
sub-neg95.1%
associate--r-95.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 71.2%
distribute-lft-out--71.2%
*-rgt-identity71.2%
associate-*r/71.4%
*-rgt-identity71.4%
Simplified71.4%
Taylor expanded in z around 0 70.6%
associate-*r/70.6%
neg-mul-170.6%
Simplified70.6%
(FPCore (x y z)
:precision binary64
(if (or (<= z -4.2e-95)
(and (not (<= z -1.6e-212))
(or (<= z 2.9e-213) (not (<= z 1.65e-70)))))
(+ x (/ y z))
(/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.2e-95) || (!(z <= -1.6e-212) && ((z <= 2.9e-213) || !(z <= 1.65e-70)))) {
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.2d-95)) .or. (.not. (z <= (-1.6d-212))) .and. (z <= 2.9d-213) .or. (.not. (z <= 1.65d-70))) 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.2e-95) || (!(z <= -1.6e-212) && ((z <= 2.9e-213) || !(z <= 1.65e-70)))) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.2e-95) or (not (z <= -1.6e-212) and ((z <= 2.9e-213) or not (z <= 1.65e-70))): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.2e-95) || (!(z <= -1.6e-212) && ((z <= 2.9e-213) || !(z <= 1.65e-70)))) 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.2e-95) || (~((z <= -1.6e-212)) && ((z <= 2.9e-213) || ~((z <= 1.65e-70))))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.2e-95], And[N[Not[LessEqual[z, -1.6e-212]], $MachinePrecision], Or[LessEqual[z, 2.9e-213], N[Not[LessEqual[z, 1.65e-70]], $MachinePrecision]]]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{-95} \lor \neg \left(z \leq -1.6 \cdot 10^{-212}\right) \land \left(z \leq 2.9 \cdot 10^{-213} \lor \neg \left(z \leq 1.65 \cdot 10^{-70}\right)\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if z < -4.2e-95 or -1.5999999999999999e-212 < z < 2.8999999999999999e-213 or 1.65000000000000008e-70 < z 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 89.6%
neg-mul-189.6%
Simplified89.6%
Taylor expanded in x around 0 89.6%
cancel-sign-sub-inv89.6%
metadata-eval89.6%
*-lft-identity89.6%
+-commutative89.6%
Simplified89.6%
if -4.2e-95 < z < -1.5999999999999999e-212 or 2.8999999999999999e-213 < z < 1.65000000000000008e-70Initial program 100.0%
div-sub94.2%
sub-neg94.2%
distribute-frac-neg94.2%
+-commutative94.2%
associate-+r+94.2%
distribute-frac-neg94.2%
sub-neg94.2%
associate--r-94.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 75.5%
distribute-lft-out--75.5%
*-rgt-identity75.5%
associate-*r/75.8%
*-rgt-identity75.8%
Simplified75.8%
Taylor expanded in z around 0 75.8%
associate-*r/75.8%
neg-mul-175.8%
Simplified75.8%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -28.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -28.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 <= (-28.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 <= -28.0) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -28.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 <= -28.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 <= -28.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, -28.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 -28 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -28 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.4%
neg-mul-199.4%
Simplified99.4%
Taylor expanded in x around 0 99.4%
cancel-sign-sub-inv99.4%
metadata-eval99.4%
*-lft-identity99.4%
+-commutative99.4%
Simplified99.4%
if -28 < z < 1Initial program 100.0%
div-sub96.4%
sub-neg96.4%
distribute-frac-neg96.4%
+-commutative96.4%
associate-+r+96.4%
distribute-frac-neg96.4%
sub-neg96.4%
associate--r-96.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.9%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.4e-73) (not (<= y 2.05e-36))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e-73) || !(y <= 2.05e-36)) {
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 <= (-3.4d-73)) .or. (.not. (y <= 2.05d-36))) 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 <= -3.4e-73) || !(y <= 2.05e-36)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.4e-73) or not (y <= 2.05e-36): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.4e-73) || !(y <= 2.05e-36)) 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 <= -3.4e-73) || ~((y <= 2.05e-36))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.4e-73], N[Not[LessEqual[y, 2.05e-36]], $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 -3.4 \cdot 10^{-73} \lor \neg \left(y \leq 2.05 \cdot 10^{-36}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -3.40000000000000021e-73 or 2.05000000000000006e-36 < 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.9%
neg-mul-190.9%
Simplified90.9%
Taylor expanded in x around 0 90.9%
cancel-sign-sub-inv90.9%
metadata-eval90.9%
*-lft-identity90.9%
+-commutative90.9%
Simplified90.9%
if -3.40000000000000021e-73 < y < 2.05000000000000006e-36Initial 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.8%
distribute-lft-out--89.8%
*-rgt-identity89.8%
associate-*r/89.9%
*-rgt-identity89.9%
Simplified89.9%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.4e+47) x (if (<= z 5.9e+38) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.4e+47) {
tmp = x;
} else if (z <= 5.9e+38) {
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.4d+47)) then
tmp = x
else if (z <= 5.9d+38) 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.4e+47) {
tmp = x;
} else if (z <= 5.9e+38) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.4e+47: tmp = x elif z <= 5.9e+38: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.4e+47) tmp = x; elseif (z <= 5.9e+38) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.4e+47) tmp = x; elseif (z <= 5.9e+38) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.4e+47], x, If[LessEqual[z, 5.9e+38], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{+47}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.9 \cdot 10^{+38}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.39999999999999994e47 or 5.89999999999999981e38 < 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 79.2%
if -1.39999999999999994e47 < z < 5.89999999999999981e38Initial program 100.0%
div-sub97.0%
sub-neg97.0%
distribute-frac-neg97.0%
+-commutative97.0%
associate-+r+97.0%
distribute-frac-neg97.0%
sub-neg97.0%
associate--r-97.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 50.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 42.6%
herbie shell --seed 2024180
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))