
(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 -1.12e-9)
x
(if (<= z -1.4e-127)
t_0
(if (<= z -6.8e-165)
(/ y z)
(if (<= z -5.6e-253) t_0 (if (<= z 2.55e+36) (/ y z) x)))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -1.12e-9) {
tmp = x;
} else if (z <= -1.4e-127) {
tmp = t_0;
} else if (z <= -6.8e-165) {
tmp = y / z;
} else if (z <= -5.6e-253) {
tmp = t_0;
} else if (z <= 2.55e+36) {
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 <= (-1.12d-9)) then
tmp = x
else if (z <= (-1.4d-127)) then
tmp = t_0
else if (z <= (-6.8d-165)) then
tmp = y / z
else if (z <= (-5.6d-253)) then
tmp = t_0
else if (z <= 2.55d+36) 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 <= -1.12e-9) {
tmp = x;
} else if (z <= -1.4e-127) {
tmp = t_0;
} else if (z <= -6.8e-165) {
tmp = y / z;
} else if (z <= -5.6e-253) {
tmp = t_0;
} else if (z <= 2.55e+36) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -1.12e-9: tmp = x elif z <= -1.4e-127: tmp = t_0 elif z <= -6.8e-165: tmp = y / z elif z <= -5.6e-253: tmp = t_0 elif z <= 2.55e+36: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -1.12e-9) tmp = x; elseif (z <= -1.4e-127) tmp = t_0; elseif (z <= -6.8e-165) tmp = Float64(y / z); elseif (z <= -5.6e-253) tmp = t_0; elseif (z <= 2.55e+36) 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 <= -1.12e-9) tmp = x; elseif (z <= -1.4e-127) tmp = t_0; elseif (z <= -6.8e-165) tmp = y / z; elseif (z <= -5.6e-253) tmp = t_0; elseif (z <= 2.55e+36) 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, -1.12e-9], x, If[LessEqual[z, -1.4e-127], t$95$0, If[LessEqual[z, -6.8e-165], N[(y / z), $MachinePrecision], If[LessEqual[z, -5.6e-253], t$95$0, If[LessEqual[z, 2.55e+36], N[(y / z), $MachinePrecision], x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -1.12 \cdot 10^{-9}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.4 \cdot 10^{-127}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -6.8 \cdot 10^{-165}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -5.6 \cdot 10^{-253}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 2.55 \cdot 10^{+36}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.12000000000000006e-9 or 2.54999999999999986e36 < z Initial program 100.0%
Taylor expanded in z around inf 73.0%
if -1.12000000000000006e-9 < z < -1.4e-127 or -6.8e-165 < z < -5.60000000000000011e-253Initial program 100.0%
Taylor expanded in y around 0 66.4%
Taylor expanded in z around 0 66.4%
neg-mul-166.4%
distribute-frac-neg66.4%
Simplified66.4%
if -1.4e-127 < z < -6.8e-165 or -5.60000000000000011e-253 < z < 2.54999999999999986e36Initial program 99.9%
+-commutative99.9%
clear-num99.7%
associate-/r/99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in y around inf 64.7%
Final simplification68.9%
(FPCore (x y z)
:precision binary64
(if (or (<= z -4.4e-97)
(not
(or (<= z -7.6e-128) (and (not (<= z -4.7e-177)) (<= z -3.2e-215)))))
(+ x (/ y z))
(/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.4e-97) || !((z <= -7.6e-128) || (!(z <= -4.7e-177) && (z <= -3.2e-215)))) {
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 <= (-4.4d-97)) .or. (.not. (z <= (-7.6d-128)) .or. (.not. (z <= (-4.7d-177))) .and. (z <= (-3.2d-215)))) 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 <= -4.4e-97) || !((z <= -7.6e-128) || (!(z <= -4.7e-177) && (z <= -3.2e-215)))) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.4e-97) or not ((z <= -7.6e-128) or (not (z <= -4.7e-177) and (z <= -3.2e-215))): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.4e-97) || !((z <= -7.6e-128) || (!(z <= -4.7e-177) && (z <= -3.2e-215)))) 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 <= -4.4e-97) || ~(((z <= -7.6e-128) || (~((z <= -4.7e-177)) && (z <= -3.2e-215))))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.4e-97], N[Not[Or[LessEqual[z, -7.6e-128], And[N[Not[LessEqual[z, -4.7e-177]], $MachinePrecision], LessEqual[z, -3.2e-215]]]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.4 \cdot 10^{-97} \lor \neg \left(z \leq -7.6 \cdot 10^{-128} \lor \neg \left(z \leq -4.7 \cdot 10^{-177}\right) \land z \leq -3.2 \cdot 10^{-215}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if z < -4.3999999999999998e-97 or -7.6000000000000005e-128 < z < -4.69999999999999967e-177 or -3.2000000000000001e-215 < z Initial program 100.0%
Taylor expanded in y around inf 81.0%
if -4.3999999999999998e-97 < z < -7.6000000000000005e-128 or -4.69999999999999967e-177 < z < -3.2000000000000001e-215Initial program 100.0%
Taylor expanded in y around 0 87.5%
Taylor expanded in z around 0 87.5%
neg-mul-187.5%
distribute-frac-neg87.5%
Simplified87.5%
Final simplification81.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1020000000.0) (not (<= x 8e+159))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1020000000.0) || !(x <= 8e+159)) {
tmp = x - (x / z);
} else {
tmp = x + (y / 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 <= (-1020000000.0d0)) .or. (.not. (x <= 8d+159))) then
tmp = x - (x / z)
else
tmp = x + (y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1020000000.0) || !(x <= 8e+159)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1020000000.0) or not (x <= 8e+159): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1020000000.0) || !(x <= 8e+159)) tmp = Float64(x - Float64(x / z)); else tmp = Float64(x + Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1020000000.0) || ~((x <= 8e+159))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1020000000.0], N[Not[LessEqual[x, 8e+159]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1020000000 \lor \neg \left(x \leq 8 \cdot 10^{+159}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.02e9 or 7.9999999999999994e159 < x Initial program 100.0%
Taylor expanded in y around 0 92.2%
if -1.02e9 < x < 7.9999999999999994e159Initial program 100.0%
Taylor expanded in y around inf 86.4%
Final simplification88.4%
(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.4%
if -1 < 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.9%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (<= z -11.0) x (if (<= z 7.2e+36) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -11.0) {
tmp = x;
} else if (z <= 7.2e+36) {
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 <= (-11.0d0)) then
tmp = x
else if (z <= 7.2d+36) 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 <= -11.0) {
tmp = x;
} else if (z <= 7.2e+36) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -11.0: tmp = x elif z <= 7.2e+36: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -11.0) tmp = x; elseif (z <= 7.2e+36) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -11.0) tmp = x; elseif (z <= 7.2e+36) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -11.0], x, If[LessEqual[z, 7.2e+36], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -11:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7.2 \cdot 10^{+36}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -11 or 7.1999999999999995e36 < z Initial program 100.0%
Taylor expanded in z around inf 74.2%
if -11 < z < 7.1999999999999995e36Initial program 100.0%
+-commutative100.0%
clear-num99.7%
associate-/r/99.7%
fma-def99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 55.1%
Final simplification63.7%
(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 35.7%
Final simplification35.7%
herbie shell --seed 2023182
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))