
(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 -85.0) x (if (<= z 5.7e-83) (/ (- x) z) (if (<= z 1.15e+41) (/ y z) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -85.0) {
tmp = x;
} else if (z <= 5.7e-83) {
tmp = -x / z;
} else if (z <= 1.15e+41) {
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 <= (-85.0d0)) then
tmp = x
else if (z <= 5.7d-83) then
tmp = -x / z
else if (z <= 1.15d+41) 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 <= -85.0) {
tmp = x;
} else if (z <= 5.7e-83) {
tmp = -x / z;
} else if (z <= 1.15e+41) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -85.0: tmp = x elif z <= 5.7e-83: tmp = -x / z elif z <= 1.15e+41: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -85.0) tmp = x; elseif (z <= 5.7e-83) tmp = Float64(Float64(-x) / z); elseif (z <= 1.15e+41) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -85.0) tmp = x; elseif (z <= 5.7e-83) tmp = -x / z; elseif (z <= 1.15e+41) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -85.0], x, If[LessEqual[z, 5.7e-83], N[((-x) / z), $MachinePrecision], If[LessEqual[z, 1.15e+41], N[(y / z), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -85:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.7 \cdot 10^{-83}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+41}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -85 or 1.1499999999999999e41 < z Initial program 100.0%
Taylor expanded in z around inf 72.7%
if -85 < z < 5.7e-83Initial program 100.0%
Taylor expanded in y around 0 65.1%
Taylor expanded in z around 0 65.0%
mul-1-neg65.0%
distribute-frac-neg65.0%
Simplified65.0%
if 5.7e-83 < z < 1.1499999999999999e41Initial program 99.9%
+-commutative99.9%
clear-num99.6%
associate-/r/99.5%
fma-def99.5%
Applied egg-rr99.5%
Taylor expanded in y around inf 59.9%
Final simplification67.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.2e-14) (not (<= z 5.8e-80))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.2e-14) || !(z <= 5.8e-80)) {
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 <= (-7.2d-14)) .or. (.not. (z <= 5.8d-80))) 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 <= -7.2e-14) || !(z <= 5.8e-80)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.2e-14) or not (z <= 5.8e-80): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.2e-14) || !(z <= 5.8e-80)) 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 <= -7.2e-14) || ~((z <= 5.8e-80))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.2e-14], N[Not[LessEqual[z, 5.8e-80]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{-14} \lor \neg \left(z \leq 5.8 \cdot 10^{-80}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if z < -7.1999999999999996e-14 or 5.79999999999999996e-80 < z Initial program 100.0%
Taylor expanded in y around inf 93.4%
if -7.1999999999999996e-14 < z < 5.79999999999999996e-80Initial program 100.0%
Taylor expanded in y around 0 65.8%
Taylor expanded in z around 0 65.7%
mul-1-neg65.7%
distribute-frac-neg65.7%
Simplified65.7%
Final simplification80.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.45e-60) (not (<= y 4.9e+58))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.45e-60) || !(y <= 4.9e+58)) {
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 <= (-1.45d-60)) .or. (.not. (y <= 4.9d+58))) 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 <= -1.45e-60) || !(y <= 4.9e+58)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.45e-60) or not (y <= 4.9e+58): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.45e-60) || !(y <= 4.9e+58)) 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 <= -1.45e-60) || ~((y <= 4.9e+58))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.45e-60], N[Not[LessEqual[y, 4.9e+58]], $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.45 \cdot 10^{-60} \lor \neg \left(y \leq 4.9 \cdot 10^{+58}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.45e-60 or 4.90000000000000018e58 < y Initial program 100.0%
Taylor expanded in y around inf 88.2%
if -1.45e-60 < y < 4.90000000000000018e58Initial program 100.0%
Taylor expanded in y around 0 89.1%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -85.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -85.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 <= (-85.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 <= -85.0) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -85.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 <= -85.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 <= -85.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, -85.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 -85 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -85 or 1 < z Initial program 100.0%
Taylor expanded in y around inf 99.3%
if -85 < z < 1Initial program 100.0%
+-commutative100.0%
clear-num99.8%
associate-/r/99.7%
fma-def99.7%
Applied egg-rr99.7%
Taylor expanded in z around 0 99.3%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (<= z -6000000000.0) x (if (<= z 6.8e+43) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6000000000.0) {
tmp = x;
} else if (z <= 6.8e+43) {
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 <= (-6000000000.0d0)) then
tmp = x
else if (z <= 6.8d+43) 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 <= -6000000000.0) {
tmp = x;
} else if (z <= 6.8e+43) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6000000000.0: tmp = x elif z <= 6.8e+43: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6000000000.0) tmp = x; elseif (z <= 6.8e+43) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6000000000.0) tmp = x; elseif (z <= 6.8e+43) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6000000000.0], x, If[LessEqual[z, 6.8e+43], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6.8 \cdot 10^{+43}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6e9 or 6.80000000000000024e43 < z Initial program 100.0%
Taylor expanded in z around inf 73.7%
if -6e9 < z < 6.80000000000000024e43Initial program 100.0%
+-commutative100.0%
clear-num99.8%
associate-/r/99.7%
fma-def99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 44.6%
Final simplification57.1%
(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.3%
Final simplification34.3%
herbie shell --seed 2023200
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))