
(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.8e+61)
x
(if (<= z -1.5e+44)
(/ y z)
(if (<= z -7200.0)
x
(if (<= z -1.4e-75)
(/ y z)
(if (<= z -1.02e-230)
t_0
(if (<= z 5.4e-80)
(/ y z)
(if (<= z 3.4e-26) t_0 (if (<= z 9.5e+24) (/ y z) x))))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -7.8e+61) {
tmp = x;
} else if (z <= -1.5e+44) {
tmp = y / z;
} else if (z <= -7200.0) {
tmp = x;
} else if (z <= -1.4e-75) {
tmp = y / z;
} else if (z <= -1.02e-230) {
tmp = t_0;
} else if (z <= 5.4e-80) {
tmp = y / z;
} else if (z <= 3.4e-26) {
tmp = t_0;
} else if (z <= 9.5e+24) {
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) :: t_0
real(8) :: tmp
t_0 = -x / z
if (z <= (-7.8d+61)) then
tmp = x
else if (z <= (-1.5d+44)) then
tmp = y / z
else if (z <= (-7200.0d0)) then
tmp = x
else if (z <= (-1.4d-75)) then
tmp = y / z
else if (z <= (-1.02d-230)) then
tmp = t_0
else if (z <= 5.4d-80) then
tmp = y / z
else if (z <= 3.4d-26) then
tmp = t_0
else if (z <= 9.5d+24) then
tmp = y / z
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.8e+61) {
tmp = x;
} else if (z <= -1.5e+44) {
tmp = y / z;
} else if (z <= -7200.0) {
tmp = x;
} else if (z <= -1.4e-75) {
tmp = y / z;
} else if (z <= -1.02e-230) {
tmp = t_0;
} else if (z <= 5.4e-80) {
tmp = y / z;
} else if (z <= 3.4e-26) {
tmp = t_0;
} else if (z <= 9.5e+24) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -7.8e+61: tmp = x elif z <= -1.5e+44: tmp = y / z elif z <= -7200.0: tmp = x elif z <= -1.4e-75: tmp = y / z elif z <= -1.02e-230: tmp = t_0 elif z <= 5.4e-80: tmp = y / z elif z <= 3.4e-26: tmp = t_0 elif z <= 9.5e+24: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -7.8e+61) tmp = x; elseif (z <= -1.5e+44) tmp = Float64(y / z); elseif (z <= -7200.0) tmp = x; elseif (z <= -1.4e-75) tmp = Float64(y / z); elseif (z <= -1.02e-230) tmp = t_0; elseif (z <= 5.4e-80) tmp = Float64(y / z); elseif (z <= 3.4e-26) tmp = t_0; elseif (z <= 9.5e+24) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x / z; tmp = 0.0; if (z <= -7.8e+61) tmp = x; elseif (z <= -1.5e+44) tmp = y / z; elseif (z <= -7200.0) tmp = x; elseif (z <= -1.4e-75) tmp = y / z; elseif (z <= -1.02e-230) tmp = t_0; elseif (z <= 5.4e-80) tmp = y / z; elseif (z <= 3.4e-26) tmp = t_0; elseif (z <= 9.5e+24) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -7.8e+61], x, If[LessEqual[z, -1.5e+44], N[(y / z), $MachinePrecision], If[LessEqual[z, -7200.0], x, If[LessEqual[z, -1.4e-75], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.02e-230], t$95$0, If[LessEqual[z, 5.4e-80], N[(y / z), $MachinePrecision], If[LessEqual[z, 3.4e-26], t$95$0, If[LessEqual[z, 9.5e+24], N[(y / z), $MachinePrecision], x]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -7.8 \cdot 10^{+61}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.5 \cdot 10^{+44}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -7200:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.4 \cdot 10^{-75}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -1.02 \cdot 10^{-230}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 5.4 \cdot 10^{-80}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 3.4 \cdot 10^{-26}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 9.5 \cdot 10^{+24}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.79999999999999975e61 or -1.49999999999999993e44 < z < -7200 or 9.5000000000000001e24 < z Initial program 100.0%
Taylor expanded in z around inf 79.1%
if -7.79999999999999975e61 < z < -1.49999999999999993e44 or -7200 < z < -1.39999999999999999e-75 or -1.02e-230 < z < 5.4000000000000004e-80 or 3.40000000000000013e-26 < z < 9.5000000000000001e24Initial program 100.0%
Taylor expanded in y around inf 70.3%
Taylor expanded in x around 0 69.1%
if -1.39999999999999999e-75 < z < -1.02e-230 or 5.4000000000000004e-80 < z < 3.40000000000000013e-26Initial program 100.0%
Taylor expanded in y around 0 75.2%
Taylor expanded in z around 0 75.2%
mul-1-neg75.2%
distribute-frac-neg75.2%
Simplified75.2%
Final simplification75.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (/ y z))) (t_1 (/ (- x) z)))
(if (<= z -6e-79)
t_0
(if (<= z -2.1e-233)
t_1
(if (<= z 2.6e-80) (/ y z) (if (<= z 2.1e-27) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x + (y / z);
double t_1 = -x / z;
double tmp;
if (z <= -6e-79) {
tmp = t_0;
} else if (z <= -2.1e-233) {
tmp = t_1;
} else if (z <= 2.6e-80) {
tmp = y / z;
} else if (z <= 2.1e-27) {
tmp = t_1;
} else {
tmp = t_0;
}
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) :: t_1
real(8) :: tmp
t_0 = x + (y / z)
t_1 = -x / z
if (z <= (-6d-79)) then
tmp = t_0
else if (z <= (-2.1d-233)) then
tmp = t_1
else if (z <= 2.6d-80) then
tmp = y / z
else if (z <= 2.1d-27) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (y / z);
double t_1 = -x / z;
double tmp;
if (z <= -6e-79) {
tmp = t_0;
} else if (z <= -2.1e-233) {
tmp = t_1;
} else if (z <= 2.6e-80) {
tmp = y / z;
} else if (z <= 2.1e-27) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y / z) t_1 = -x / z tmp = 0 if z <= -6e-79: tmp = t_0 elif z <= -2.1e-233: tmp = t_1 elif z <= 2.6e-80: tmp = y / z elif z <= 2.1e-27: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y / z)) t_1 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -6e-79) tmp = t_0; elseif (z <= -2.1e-233) tmp = t_1; elseif (z <= 2.6e-80) tmp = Float64(y / z); elseif (z <= 2.1e-27) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (y / z); t_1 = -x / z; tmp = 0.0; if (z <= -6e-79) tmp = t_0; elseif (z <= -2.1e-233) tmp = t_1; elseif (z <= 2.6e-80) tmp = y / z; elseif (z <= 2.1e-27) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -6e-79], t$95$0, If[LessEqual[z, -2.1e-233], t$95$1, If[LessEqual[z, 2.6e-80], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.1e-27], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
t_1 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -6 \cdot 10^{-79}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -2.1 \cdot 10^{-233}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq 2.6 \cdot 10^{-80}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-27}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -5.99999999999999999e-79 or 2.10000000000000015e-27 < z Initial program 100.0%
Taylor expanded in y around inf 95.8%
if -5.99999999999999999e-79 < z < -2.0999999999999999e-233 or 2.6000000000000001e-80 < z < 2.10000000000000015e-27Initial program 100.0%
Taylor expanded in y around 0 76.3%
Taylor expanded in z around 0 76.3%
mul-1-neg76.3%
distribute-frac-neg76.3%
Simplified76.3%
if -2.0999999999999999e-233 < z < 2.6000000000000001e-80Initial program 100.0%
Taylor expanded in y around inf 61.5%
Taylor expanded in x around 0 61.7%
Final simplification85.2%
(FPCore (x y z)
:precision binary64
(if (<= z -1e+61)
x
(if (<= z -2.8e+45)
(/ y z)
(if (<= z -7200.0) x (if (<= z 4e+25) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1e+61) {
tmp = x;
} else if (z <= -2.8e+45) {
tmp = y / z;
} else if (z <= -7200.0) {
tmp = x;
} else if (z <= 4e+25) {
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 <= (-1d+61)) then
tmp = x
else if (z <= (-2.8d+45)) then
tmp = y / z
else if (z <= (-7200.0d0)) then
tmp = x
else if (z <= 4d+25) 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 <= -1e+61) {
tmp = x;
} else if (z <= -2.8e+45) {
tmp = y / z;
} else if (z <= -7200.0) {
tmp = x;
} else if (z <= 4e+25) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1e+61: tmp = x elif z <= -2.8e+45: tmp = y / z elif z <= -7200.0: tmp = x elif z <= 4e+25: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1e+61) tmp = x; elseif (z <= -2.8e+45) tmp = Float64(y / z); elseif (z <= -7200.0) tmp = x; elseif (z <= 4e+25) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1e+61) tmp = x; elseif (z <= -2.8e+45) tmp = y / z; elseif (z <= -7200.0) tmp = x; elseif (z <= 4e+25) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1e+61], x, If[LessEqual[z, -2.8e+45], N[(y / z), $MachinePrecision], If[LessEqual[z, -7200.0], x, If[LessEqual[z, 4e+25], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{+61}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -2.8 \cdot 10^{+45}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -7200:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4 \cdot 10^{+25}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.99999999999999949e60 or -2.7999999999999999e45 < z < -7200 or 4.00000000000000036e25 < z Initial program 100.0%
Taylor expanded in z around inf 79.1%
if -9.99999999999999949e60 < z < -2.7999999999999999e45 or -7200 < z < 4.00000000000000036e25Initial program 100.0%
Taylor expanded in y around inf 56.6%
Taylor expanded in x around 0 55.5%
Final simplification67.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.5e-78) (not (<= y 4e-40))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.5e-78) || !(y <= 4e-40)) {
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.5d-78)) .or. (.not. (y <= 4d-40))) 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.5e-78) || !(y <= 4e-40)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.5e-78) or not (y <= 4e-40): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.5e-78) || !(y <= 4e-40)) 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.5e-78) || ~((y <= 4e-40))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.5e-78], N[Not[LessEqual[y, 4e-40]], $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.5 \cdot 10^{-78} \lor \neg \left(y \leq 4 \cdot 10^{-40}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -7.50000000000000041e-78 or 3.9999999999999997e-40 < y Initial program 100.0%
Taylor expanded in y around inf 90.1%
if -7.50000000000000041e-78 < y < 3.9999999999999997e-40Initial program 100.0%
Taylor expanded in y around 0 90.5%
Final simplification90.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 8.5e-26))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 8.5e-26)) {
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.5d-26))) 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.5e-26)) {
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.5e-26): 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.5e-26)) 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.5e-26))) 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.5e-26]], $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.5 \cdot 10^{-26}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 8.50000000000000004e-26 < z Initial program 100.0%
Taylor expanded in y around inf 99.1%
if -1 < z < 8.50000000000000004e-26Initial program 100.0%
Taylor expanded in y around 0 93.8%
Taylor expanded in z around 0 99.4%
Final simplification99.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 40.6%
Final simplification40.6%
herbie shell --seed 2023230
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))