
(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 -2.5e+21)
x
(if (<= z 6.4e-208)
(/ y z)
(if (<= z 4.4e-44) (/ (- x) z) (if (<= z 9.2e+46) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.5e+21) {
tmp = x;
} else if (z <= 6.4e-208) {
tmp = y / z;
} else if (z <= 4.4e-44) {
tmp = -x / z;
} else if (z <= 9.2e+46) {
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 <= (-2.5d+21)) then
tmp = x
else if (z <= 6.4d-208) then
tmp = y / z
else if (z <= 4.4d-44) then
tmp = -x / z
else if (z <= 9.2d+46) 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 <= -2.5e+21) {
tmp = x;
} else if (z <= 6.4e-208) {
tmp = y / z;
} else if (z <= 4.4e-44) {
tmp = -x / z;
} else if (z <= 9.2e+46) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.5e+21: tmp = x elif z <= 6.4e-208: tmp = y / z elif z <= 4.4e-44: tmp = -x / z elif z <= 9.2e+46: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.5e+21) tmp = x; elseif (z <= 6.4e-208) tmp = Float64(y / z); elseif (z <= 4.4e-44) tmp = Float64(Float64(-x) / z); elseif (z <= 9.2e+46) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.5e+21) tmp = x; elseif (z <= 6.4e-208) tmp = y / z; elseif (z <= 4.4e-44) tmp = -x / z; elseif (z <= 9.2e+46) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.5e+21], x, If[LessEqual[z, 6.4e-208], N[(y / z), $MachinePrecision], If[LessEqual[z, 4.4e-44], N[((-x) / z), $MachinePrecision], If[LessEqual[z, 9.2e+46], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{+21}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6.4 \cdot 10^{-208}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 4.4 \cdot 10^{-44}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{elif}\;z \leq 9.2 \cdot 10^{+46}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.5e21 or 9.2000000000000002e46 < z Initial program 100.0%
Taylor expanded in z around inf 81.1%
if -2.5e21 < z < 6.4000000000000003e-208 or 4.40000000000000024e-44 < z < 9.2000000000000002e46Initial program 100.0%
+-commutative100.0%
div-sub98.0%
associate-+l-98.0%
Applied egg-rr98.0%
Taylor expanded in z around 0 90.3%
Taylor expanded in y around inf 61.7%
if 6.4000000000000003e-208 < z < 4.40000000000000024e-44Initial program 100.0%
+-commutative100.0%
div-sub100.0%
associate-+l-100.0%
Applied egg-rr100.0%
Taylor expanded in z around 0 100.0%
Taylor expanded in y around 0 70.6%
mul-1-neg70.6%
distribute-frac-neg70.6%
Simplified70.6%
Final simplification72.2%
(FPCore (x y z) :precision binary64 (if (or (<= z 5e-207) (not (<= z 2.05e-42))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= 5e-207) || !(z <= 2.05e-42)) {
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 <= 5d-207) .or. (.not. (z <= 2.05d-42))) 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 <= 5e-207) || !(z <= 2.05e-42)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= 5e-207) or not (z <= 2.05e-42): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= 5e-207) || !(z <= 2.05e-42)) 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 <= 5e-207) || ~((z <= 2.05e-42))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, 5e-207], N[Not[LessEqual[z, 2.05e-42]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5 \cdot 10^{-207} \lor \neg \left(z \leq 2.05 \cdot 10^{-42}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if z < 5.00000000000000014e-207 or 2.0500000000000001e-42 < z Initial program 100.0%
Taylor expanded in y around inf 85.0%
if 5.00000000000000014e-207 < z < 2.0500000000000001e-42Initial program 100.0%
+-commutative100.0%
div-sub100.0%
associate-+l-100.0%
Applied egg-rr100.0%
Taylor expanded in z around 0 100.0%
Taylor expanded in y around 0 70.6%
mul-1-neg70.6%
distribute-frac-neg70.6%
Simplified70.6%
Final simplification83.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -5e-104) (not (<= y 8.8e-98))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5e-104) || !(y <= 8.8e-98)) {
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 <= (-5d-104)) .or. (.not. (y <= 8.8d-98))) 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 <= -5e-104) || !(y <= 8.8e-98)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5e-104) or not (y <= 8.8e-98): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5e-104) || !(y <= 8.8e-98)) 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 <= -5e-104) || ~((y <= 8.8e-98))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5e-104], N[Not[LessEqual[y, 8.8e-98]], $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 -5 \cdot 10^{-104} \lor \neg \left(y \leq 8.8 \cdot 10^{-98}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -4.99999999999999979e-104 or 8.79999999999999985e-98 < y Initial program 100.0%
Taylor expanded in y around inf 89.6%
if -4.99999999999999979e-104 < y < 8.79999999999999985e-98Initial program 100.0%
Taylor expanded in y around 0 90.6%
Final simplification90.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 8.8e-11))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 8.8e-11)) {
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 <= 8.8d-11))) 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 <= 8.8e-11)) {
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 <= 8.8e-11): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 8.8e-11)) 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 <= 8.8e-11))) 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, 8.8e-11]], $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 8.8 \cdot 10^{-11}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 8.8000000000000006e-11 < z Initial program 100.0%
Taylor expanded in y around inf 98.5%
if -1 < z < 8.8000000000000006e-11Initial program 100.0%
+-commutative100.0%
div-sub98.3%
associate-+l-98.3%
Applied egg-rr98.3%
Taylor expanded in z around 0 96.6%
Taylor expanded in y around 0 96.6%
mul-1-neg96.6%
distribute-frac-neg96.6%
+-commutative96.6%
distribute-frac-neg96.6%
sub-neg96.6%
div-sub98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (<= z -1.15e+22) x (if (<= z 2.95e+47) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.15e+22) {
tmp = x;
} else if (z <= 2.95e+47) {
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.15d+22)) then
tmp = x
else if (z <= 2.95d+47) 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.15e+22) {
tmp = x;
} else if (z <= 2.95e+47) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.15e+22: tmp = x elif z <= 2.95e+47: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.15e+22) tmp = x; elseif (z <= 2.95e+47) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.15e+22) tmp = x; elseif (z <= 2.95e+47) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.15e+22], x, If[LessEqual[z, 2.95e+47], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{+22}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.95 \cdot 10^{+47}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.1500000000000001e22 or 2.95000000000000017e47 < z Initial program 100.0%
Taylor expanded in z around inf 81.1%
if -1.1500000000000001e22 < z < 2.95000000000000017e47Initial program 100.0%
+-commutative100.0%
div-sub98.5%
associate-+l-98.5%
Applied egg-rr98.5%
Taylor expanded in z around 0 92.7%
Taylor expanded in y around inf 54.0%
Final simplification67.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%
Taylor expanded in z around inf 41.9%
Final simplification41.9%
herbie shell --seed 2023274
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))