
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -4.1e+133)
x
(if (<= z -6.5e+88)
(/ y z)
(if (<= z -3.6e+54)
x
(if (<= z -1.32e-55)
(/ y z)
(if (<= z 2.1e-70) (/ (- x) z) (if (<= z 3.5e+21) (/ y z) x)))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.1e+133) {
tmp = x;
} else if (z <= -6.5e+88) {
tmp = y / z;
} else if (z <= -3.6e+54) {
tmp = x;
} else if (z <= -1.32e-55) {
tmp = y / z;
} else if (z <= 2.1e-70) {
tmp = -x / z;
} else if (z <= 3.5e+21) {
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 <= (-4.1d+133)) then
tmp = x
else if (z <= (-6.5d+88)) then
tmp = y / z
else if (z <= (-3.6d+54)) then
tmp = x
else if (z <= (-1.32d-55)) then
tmp = y / z
else if (z <= 2.1d-70) then
tmp = -x / z
else if (z <= 3.5d+21) 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 <= -4.1e+133) {
tmp = x;
} else if (z <= -6.5e+88) {
tmp = y / z;
} else if (z <= -3.6e+54) {
tmp = x;
} else if (z <= -1.32e-55) {
tmp = y / z;
} else if (z <= 2.1e-70) {
tmp = -x / z;
} else if (z <= 3.5e+21) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.1e+133: tmp = x elif z <= -6.5e+88: tmp = y / z elif z <= -3.6e+54: tmp = x elif z <= -1.32e-55: tmp = y / z elif z <= 2.1e-70: tmp = -x / z elif z <= 3.5e+21: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.1e+133) tmp = x; elseif (z <= -6.5e+88) tmp = Float64(y / z); elseif (z <= -3.6e+54) tmp = x; elseif (z <= -1.32e-55) tmp = Float64(y / z); elseif (z <= 2.1e-70) tmp = Float64(Float64(-x) / z); elseif (z <= 3.5e+21) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.1e+133) tmp = x; elseif (z <= -6.5e+88) tmp = y / z; elseif (z <= -3.6e+54) tmp = x; elseif (z <= -1.32e-55) tmp = y / z; elseif (z <= 2.1e-70) tmp = -x / z; elseif (z <= 3.5e+21) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.1e+133], x, If[LessEqual[z, -6.5e+88], N[(y / z), $MachinePrecision], If[LessEqual[z, -3.6e+54], x, If[LessEqual[z, -1.32e-55], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.1e-70], N[((-x) / z), $MachinePrecision], If[LessEqual[z, 3.5e+21], N[(y / z), $MachinePrecision], x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.1 \cdot 10^{+133}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -6.5 \cdot 10^{+88}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -3.6 \cdot 10^{+54}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.32 \cdot 10^{-55}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-70}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+21}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.10000000000000004e133 or -6.5000000000000002e88 < z < -3.6000000000000001e54 or 3.5e21 < z Initial program 100.0%
Taylor expanded in z around inf 74.3%
if -4.10000000000000004e133 < z < -6.5000000000000002e88 or -3.6000000000000001e54 < z < -1.31999999999999993e-55 or 2.1000000000000001e-70 < z < 3.5e21Initial program 100.0%
+-commutative100.0%
div-sub100.0%
associate-+l-100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 67.0%
if -1.31999999999999993e-55 < z < 2.1000000000000001e-70Initial program 99.9%
Taylor expanded in x around inf 65.3%
Taylor expanded in z around 0 65.5%
neg-mul-165.5%
distribute-neg-frac65.5%
Simplified65.5%
Final simplification69.4%
(FPCore (x y z)
:precision binary64
(if (<= z -4.1e+133)
x
(if (<= z -7e+88)
(/ y z)
(if (<= z -3.7e+53) x (if (<= z 1.15e+21) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.1e+133) {
tmp = x;
} else if (z <= -7e+88) {
tmp = y / z;
} else if (z <= -3.7e+53) {
tmp = x;
} else if (z <= 1.15e+21) {
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 <= (-4.1d+133)) then
tmp = x
else if (z <= (-7d+88)) then
tmp = y / z
else if (z <= (-3.7d+53)) then
tmp = x
else if (z <= 1.15d+21) 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 <= -4.1e+133) {
tmp = x;
} else if (z <= -7e+88) {
tmp = y / z;
} else if (z <= -3.7e+53) {
tmp = x;
} else if (z <= 1.15e+21) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.1e+133: tmp = x elif z <= -7e+88: tmp = y / z elif z <= -3.7e+53: tmp = x elif z <= 1.15e+21: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.1e+133) tmp = x; elseif (z <= -7e+88) tmp = Float64(y / z); elseif (z <= -3.7e+53) tmp = x; elseif (z <= 1.15e+21) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.1e+133) tmp = x; elseif (z <= -7e+88) tmp = y / z; elseif (z <= -3.7e+53) tmp = x; elseif (z <= 1.15e+21) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.1e+133], x, If[LessEqual[z, -7e+88], N[(y / z), $MachinePrecision], If[LessEqual[z, -3.7e+53], x, If[LessEqual[z, 1.15e+21], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.1 \cdot 10^{+133}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -7 \cdot 10^{+88}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -3.7 \cdot 10^{+53}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+21}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.10000000000000004e133 or -6.9999999999999995e88 < z < -3.7e53 or 1.15e21 < z Initial program 100.0%
Taylor expanded in z around inf 74.3%
if -4.10000000000000004e133 < z < -6.9999999999999995e88 or -3.7e53 < z < 1.15e21Initial program 99.9%
+-commutative99.9%
div-sub98.0%
associate-+l-98.0%
Applied egg-rr98.0%
Taylor expanded in y around inf 50.7%
Final simplification60.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.5e-50) (not (<= z 8.8e-71))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.5e-50) || !(z <= 8.8e-71)) {
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 <= (-1.5d-50)) .or. (.not. (z <= 8.8d-71))) 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 <= -1.5e-50) || !(z <= 8.8e-71)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.5e-50) or not (z <= 8.8e-71): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.5e-50) || !(z <= 8.8e-71)) 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 <= -1.5e-50) || ~((z <= 8.8e-71))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.5e-50], N[Not[LessEqual[z, 8.8e-71]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{-50} \lor \neg \left(z \leq 8.8 \cdot 10^{-71}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if z < -1.49999999999999995e-50 or 8.7999999999999999e-71 < z Initial program 100.0%
Taylor expanded in y around inf 91.3%
if -1.49999999999999995e-50 < z < 8.7999999999999999e-71Initial program 99.9%
Taylor expanded in x around inf 65.3%
Taylor expanded in z around 0 65.5%
neg-mul-165.5%
distribute-neg-frac65.5%
Simplified65.5%
Final simplification82.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.8e-113) (not (<= y 2.4e-108))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.8e-113) || !(y <= 2.4e-108)) {
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 <= (-7.8d-113)) .or. (.not. (y <= 2.4d-108))) 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 <= -7.8e-113) || !(y <= 2.4e-108)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.8e-113) or not (y <= 2.4e-108): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.8e-113) || !(y <= 2.4e-108)) 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 <= -7.8e-113) || ~((y <= 2.4e-108))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.8e-113], N[Not[LessEqual[y, 2.4e-108]], $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 -7.8 \cdot 10^{-113} \lor \neg \left(y \leq 2.4 \cdot 10^{-108}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -7.7999999999999997e-113 or 2.40000000000000017e-108 < y Initial program 100.0%
Taylor expanded in y around inf 83.4%
if -7.7999999999999997e-113 < y < 2.40000000000000017e-108Initial program 100.0%
Taylor expanded in y around 0 94.6%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.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 <= (-1.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 <= -1.0) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.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 <= -1.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 <= -1.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, -1.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 -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in y around inf 98.9%
if -1 < z < 1Initial program 100.0%
+-commutative100.0%
div-sub97.7%
associate-+l-97.7%
Applied egg-rr97.7%
Taylor expanded in z around 0 97.4%
Final simplification98.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%
Taylor expanded in z around inf 34.0%
Final simplification34.0%
herbie shell --seed 2023275
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))