
(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
(let* ((t_0 (/ (- x) z)))
(if (<= z -7.4e+22)
x
(if (<= z -1.7e-137)
(/ y z)
(if (<= z -2.5e-185)
t_0
(if (<= z -4.4e-266)
(/ y z)
(if (<= z -5e-306)
t_0
(if (<= z 5e-294)
(/ y z)
(if (<= z 2.5e-228)
t_0
(if (<= z 4.5e-83) (/ 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 <= -7.4e+22) {
tmp = x;
} else if (z <= -1.7e-137) {
tmp = y / z;
} else if (z <= -2.5e-185) {
tmp = t_0;
} else if (z <= -4.4e-266) {
tmp = y / z;
} else if (z <= -5e-306) {
tmp = t_0;
} else if (z <= 5e-294) {
tmp = y / z;
} else if (z <= 2.5e-228) {
tmp = t_0;
} else if (z <= 4.5e-83) {
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 <= (-7.4d+22)) then
tmp = x
else if (z <= (-1.7d-137)) then
tmp = y / z
else if (z <= (-2.5d-185)) then
tmp = t_0
else if (z <= (-4.4d-266)) then
tmp = y / z
else if (z <= (-5d-306)) then
tmp = t_0
else if (z <= 5d-294) then
tmp = y / z
else if (z <= 2.5d-228) then
tmp = t_0
else if (z <= 4.5d-83) 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 <= -7.4e+22) {
tmp = x;
} else if (z <= -1.7e-137) {
tmp = y / z;
} else if (z <= -2.5e-185) {
tmp = t_0;
} else if (z <= -4.4e-266) {
tmp = y / z;
} else if (z <= -5e-306) {
tmp = t_0;
} else if (z <= 5e-294) {
tmp = y / z;
} else if (z <= 2.5e-228) {
tmp = t_0;
} else if (z <= 4.5e-83) {
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 <= -7.4e+22: tmp = x elif z <= -1.7e-137: tmp = y / z elif z <= -2.5e-185: tmp = t_0 elif z <= -4.4e-266: tmp = y / z elif z <= -5e-306: tmp = t_0 elif z <= 5e-294: tmp = y / z elif z <= 2.5e-228: tmp = t_0 elif z <= 4.5e-83: 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 <= -7.4e+22) tmp = x; elseif (z <= -1.7e-137) tmp = Float64(y / z); elseif (z <= -2.5e-185) tmp = t_0; elseif (z <= -4.4e-266) tmp = Float64(y / z); elseif (z <= -5e-306) tmp = t_0; elseif (z <= 5e-294) tmp = Float64(y / z); elseif (z <= 2.5e-228) tmp = t_0; elseif (z <= 4.5e-83) 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 <= -7.4e+22) tmp = x; elseif (z <= -1.7e-137) tmp = y / z; elseif (z <= -2.5e-185) tmp = t_0; elseif (z <= -4.4e-266) tmp = y / z; elseif (z <= -5e-306) tmp = t_0; elseif (z <= 5e-294) tmp = y / z; elseif (z <= 2.5e-228) tmp = t_0; elseif (z <= 4.5e-83) 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, -7.4e+22], x, If[LessEqual[z, -1.7e-137], N[(y / z), $MachinePrecision], If[LessEqual[z, -2.5e-185], t$95$0, If[LessEqual[z, -4.4e-266], N[(y / z), $MachinePrecision], If[LessEqual[z, -5e-306], t$95$0, If[LessEqual[z, 5e-294], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.5e-228], t$95$0, If[LessEqual[z, 4.5e-83], 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 -7.4 \cdot 10^{+22}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.7 \cdot 10^{-137}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -2.5 \cdot 10^{-185}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -4.4 \cdot 10^{-266}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -5 \cdot 10^{-306}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 5 \cdot 10^{-294}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{-228}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{-83}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.3999999999999996e22 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 76.1%
if -7.3999999999999996e22 < z < -1.70000000000000007e-137 or -2.5000000000000001e-185 < z < -4.3999999999999999e-266 or -4.99999999999999998e-306 < z < 5.0000000000000003e-294 or 2.49999999999999986e-228 < z < 4.49999999999999997e-83Initial program 100.0%
+-commutative100.0%
clear-num99.8%
associate-/r/98.7%
fma-def98.7%
Applied egg-rr98.7%
Taylor expanded in y around inf 68.2%
if -1.70000000000000007e-137 < z < -2.5000000000000001e-185 or -4.3999999999999999e-266 < z < -4.99999999999999998e-306 or 5.0000000000000003e-294 < z < 2.49999999999999986e-228 or 4.49999999999999997e-83 < z < 1Initial program 99.9%
Taylor expanded in y around 0 75.4%
Taylor expanded in z around 0 73.1%
mul-1-neg73.1%
distribute-frac-neg73.1%
Simplified73.1%
Final simplification72.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.8e+36) (not (<= y 2.7e-131))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e+36) || !(y <= 2.7e-131)) {
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.8d+36)) .or. (.not. (y <= 2.7d-131))) 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.8e+36) || !(y <= 2.7e-131)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.8e+36) or not (y <= 2.7e-131): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.8e+36) || !(y <= 2.7e-131)) 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.8e+36) || ~((y <= 2.7e-131))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.8e+36], N[Not[LessEqual[y, 2.7e-131]], $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.8 \cdot 10^{+36} \lor \neg \left(y \leq 2.7 \cdot 10^{-131}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.7999999999999999e36 or 2.70000000000000021e-131 < y Initial program 100.0%
Taylor expanded in y around inf 89.6%
if -1.7999999999999999e36 < y < 2.70000000000000021e-131Initial program 100.0%
Taylor expanded in y around 0 87.6%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -32000000000.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -32000000000.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 <= (-32000000000.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 <= -32000000000.0) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -32000000000.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 <= -32000000000.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 <= -32000000000.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, -32000000000.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 -32000000000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -3.2e10 or 1 < z Initial program 100.0%
Taylor expanded in y around inf 99.9%
if -3.2e10 < z < 1Initial program 100.0%
+-commutative100.0%
clear-num99.7%
associate-/r/99.0%
fma-def99.0%
Applied egg-rr99.0%
Taylor expanded in z around 0 98.7%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (<= z -9e+16) x (if (<= z 2.45e+35) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -9e+16) {
tmp = x;
} else if (z <= 2.45e+35) {
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+16)) then
tmp = x
else if (z <= 2.45d+35) 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+16) {
tmp = x;
} else if (z <= 2.45e+35) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9e+16: tmp = x elif z <= 2.45e+35: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9e+16) tmp = x; elseif (z <= 2.45e+35) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9e+16) tmp = x; elseif (z <= 2.45e+35) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9e+16], x, If[LessEqual[z, 2.45e+35], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{+16}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.45 \cdot 10^{+35}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9e16 or 2.45000000000000013e35 < z Initial program 100.0%
Taylor expanded in z around inf 77.6%
if -9e16 < z < 2.45000000000000013e35Initial program 100.0%
+-commutative100.0%
clear-num99.7%
associate-/r/99.1%
fma-def99.1%
Applied egg-rr99.1%
Taylor expanded in y around inf 54.6%
Final simplification64.5%
(FPCore (x y z) :precision binary64 (if (<= x 1.02e+269) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if (x <= 1.02e+269) {
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 (x <= 1.02d+269) 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 (x <= 1.02e+269) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 1.02e+269: tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if (x <= 1.02e+269) 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 (x <= 1.02e+269) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 1.02e+269], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.02 \cdot 10^{+269}:\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if x < 1.01999999999999994e269Initial program 100.0%
Taylor expanded in y around inf 77.0%
if 1.01999999999999994e269 < x Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in z around 0 100.0%
mul-1-neg100.0%
distribute-frac-neg100.0%
Simplified100.0%
Final simplification77.6%
(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 36.2%
Final simplification36.2%
herbie shell --seed 2023279
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))