
(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 -14.0)
x
(if (<= z -2.7e-116)
(/ y z)
(if (<= z -2.5e-197)
t_0
(if (<= z -1.1e-224)
(/ y z)
(if (<= z 4.3e-275)
t_0
(if (<= z 6.5e-196) (/ 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 <= -14.0) {
tmp = x;
} else if (z <= -2.7e-116) {
tmp = y / z;
} else if (z <= -2.5e-197) {
tmp = t_0;
} else if (z <= -1.1e-224) {
tmp = y / z;
} else if (z <= 4.3e-275) {
tmp = t_0;
} else if (z <= 6.5e-196) {
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 <= (-14.0d0)) then
tmp = x
else if (z <= (-2.7d-116)) then
tmp = y / z
else if (z <= (-2.5d-197)) then
tmp = t_0
else if (z <= (-1.1d-224)) then
tmp = y / z
else if (z <= 4.3d-275) then
tmp = t_0
else if (z <= 6.5d-196) 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 <= -14.0) {
tmp = x;
} else if (z <= -2.7e-116) {
tmp = y / z;
} else if (z <= -2.5e-197) {
tmp = t_0;
} else if (z <= -1.1e-224) {
tmp = y / z;
} else if (z <= 4.3e-275) {
tmp = t_0;
} else if (z <= 6.5e-196) {
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 <= -14.0: tmp = x elif z <= -2.7e-116: tmp = y / z elif z <= -2.5e-197: tmp = t_0 elif z <= -1.1e-224: tmp = y / z elif z <= 4.3e-275: tmp = t_0 elif z <= 6.5e-196: 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 <= -14.0) tmp = x; elseif (z <= -2.7e-116) tmp = Float64(y / z); elseif (z <= -2.5e-197) tmp = t_0; elseif (z <= -1.1e-224) tmp = Float64(y / z); elseif (z <= 4.3e-275) tmp = t_0; elseif (z <= 6.5e-196) 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 <= -14.0) tmp = x; elseif (z <= -2.7e-116) tmp = y / z; elseif (z <= -2.5e-197) tmp = t_0; elseif (z <= -1.1e-224) tmp = y / z; elseif (z <= 4.3e-275) tmp = t_0; elseif (z <= 6.5e-196) 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, -14.0], x, If[LessEqual[z, -2.7e-116], N[(y / z), $MachinePrecision], If[LessEqual[z, -2.5e-197], t$95$0, If[LessEqual[z, -1.1e-224], N[(y / z), $MachinePrecision], If[LessEqual[z, 4.3e-275], t$95$0, If[LessEqual[z, 6.5e-196], 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 -14:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -2.7 \cdot 10^{-116}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -2.5 \cdot 10^{-197}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1.1 \cdot 10^{-224}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 4.3 \cdot 10^{-275}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{-196}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -14 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 73.5%
if -14 < z < -2.7e-116 or -2.5000000000000001e-197 < z < -1.1e-224 or 4.29999999999999976e-275 < z < 6.5000000000000004e-196Initial program 100.0%
Taylor expanded in y around inf 76.1%
Taylor expanded in x around 0 75.6%
if -2.7e-116 < z < -2.5000000000000001e-197 or -1.1e-224 < z < 4.29999999999999976e-275 or 6.5000000000000004e-196 < z < 1Initial program 100.0%
+-commutative100.0%
div-sub96.5%
associate-+l-96.5%
Applied egg-rr96.5%
Taylor expanded in z around 0 96.5%
sub-div100.0%
clear-num99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 66.9%
mul-1-neg66.9%
distribute-frac-neg66.9%
Simplified66.9%
Final simplification71.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (/ y z))) (t_1 (/ (- x) z)))
(if (<= z -1.35e-116)
t_0
(if (<= z -1.65e-196)
t_1
(if (<= z -1.55e-227)
(/ y z)
(if (<= z 2.3e-277)
t_1
(if (<= z 2.2e-196) (/ y z) (if (<= z 1.52e-86) 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 <= -1.35e-116) {
tmp = t_0;
} else if (z <= -1.65e-196) {
tmp = t_1;
} else if (z <= -1.55e-227) {
tmp = y / z;
} else if (z <= 2.3e-277) {
tmp = t_1;
} else if (z <= 2.2e-196) {
tmp = y / z;
} else if (z <= 1.52e-86) {
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 <= (-1.35d-116)) then
tmp = t_0
else if (z <= (-1.65d-196)) then
tmp = t_1
else if (z <= (-1.55d-227)) then
tmp = y / z
else if (z <= 2.3d-277) then
tmp = t_1
else if (z <= 2.2d-196) then
tmp = y / z
else if (z <= 1.52d-86) 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 <= -1.35e-116) {
tmp = t_0;
} else if (z <= -1.65e-196) {
tmp = t_1;
} else if (z <= -1.55e-227) {
tmp = y / z;
} else if (z <= 2.3e-277) {
tmp = t_1;
} else if (z <= 2.2e-196) {
tmp = y / z;
} else if (z <= 1.52e-86) {
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 <= -1.35e-116: tmp = t_0 elif z <= -1.65e-196: tmp = t_1 elif z <= -1.55e-227: tmp = y / z elif z <= 2.3e-277: tmp = t_1 elif z <= 2.2e-196: tmp = y / z elif z <= 1.52e-86: 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 <= -1.35e-116) tmp = t_0; elseif (z <= -1.65e-196) tmp = t_1; elseif (z <= -1.55e-227) tmp = Float64(y / z); elseif (z <= 2.3e-277) tmp = t_1; elseif (z <= 2.2e-196) tmp = Float64(y / z); elseif (z <= 1.52e-86) 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 <= -1.35e-116) tmp = t_0; elseif (z <= -1.65e-196) tmp = t_1; elseif (z <= -1.55e-227) tmp = y / z; elseif (z <= 2.3e-277) tmp = t_1; elseif (z <= 2.2e-196) tmp = y / z; elseif (z <= 1.52e-86) 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, -1.35e-116], t$95$0, If[LessEqual[z, -1.65e-196], t$95$1, If[LessEqual[z, -1.55e-227], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.3e-277], t$95$1, If[LessEqual[z, 2.2e-196], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.52e-86], 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 -1.35 \cdot 10^{-116}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1.65 \cdot 10^{-196}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -1.55 \cdot 10^{-227}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-277}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{-196}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.52 \cdot 10^{-86}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -1.35e-116 or 1.52e-86 < z Initial program 100.0%
Taylor expanded in y around inf 88.8%
if -1.35e-116 < z < -1.64999999999999999e-196 or -1.5499999999999999e-227 < z < 2.3e-277 or 2.20000000000000015e-196 < z < 1.52e-86Initial program 100.0%
+-commutative100.0%
div-sub95.5%
associate-+l-95.5%
Applied egg-rr95.5%
Taylor expanded in z around 0 95.5%
sub-div100.0%
clear-num99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 72.6%
mul-1-neg72.6%
distribute-frac-neg72.6%
Simplified72.6%
if -1.64999999999999999e-196 < z < -1.5499999999999999e-227 or 2.3e-277 < z < 2.20000000000000015e-196Initial program 100.0%
Taylor expanded in y around inf 82.9%
Taylor expanded in x around 0 83.0%
Final simplification83.9%
(FPCore (x y z)
:precision binary64
(if (or (<= x -4.3e-7)
(not
(or (<= x -1.9e-85)
(and (not (<= x -1.15e-157)) (<= x 90000000.0)))))
(- x (/ x z))
(+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.3e-7) || !((x <= -1.9e-85) || (!(x <= -1.15e-157) && (x <= 90000000.0)))) {
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 <= (-4.3d-7)) .or. (.not. (x <= (-1.9d-85)) .or. (.not. (x <= (-1.15d-157))) .and. (x <= 90000000.0d0))) 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 <= -4.3e-7) || !((x <= -1.9e-85) || (!(x <= -1.15e-157) && (x <= 90000000.0)))) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.3e-7) or not ((x <= -1.9e-85) or (not (x <= -1.15e-157) and (x <= 90000000.0))): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.3e-7) || !((x <= -1.9e-85) || (!(x <= -1.15e-157) && (x <= 90000000.0)))) 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 <= -4.3e-7) || ~(((x <= -1.9e-85) || (~((x <= -1.15e-157)) && (x <= 90000000.0))))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.3e-7], N[Not[Or[LessEqual[x, -1.9e-85], And[N[Not[LessEqual[x, -1.15e-157]], $MachinePrecision], LessEqual[x, 90000000.0]]]], $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 -4.3 \cdot 10^{-7} \lor \neg \left(x \leq -1.9 \cdot 10^{-85} \lor \neg \left(x \leq -1.15 \cdot 10^{-157}\right) \land x \leq 90000000\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -4.3000000000000001e-7 or -1.8999999999999999e-85 < x < -1.14999999999999994e-157 or 9e7 < x Initial program 100.0%
Taylor expanded in y around 0 87.9%
if -4.3000000000000001e-7 < x < -1.8999999999999999e-85 or -1.14999999999999994e-157 < x < 9e7Initial program 100.0%
Taylor expanded in y around inf 91.6%
Final simplification89.7%
(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.7%
if -1 < z < 1Initial program 100.0%
+-commutative100.0%
div-sub96.3%
associate-+l-96.3%
Applied egg-rr96.3%
Taylor expanded in z around 0 96.0%
sub-div99.7%
clear-num99.5%
Applied egg-rr99.5%
Taylor expanded in z around 0 99.7%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (<= z -14.0) x (if (<= z 3500000000000.0) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -14.0) {
tmp = x;
} else if (z <= 3500000000000.0) {
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 <= (-14.0d0)) then
tmp = x
else if (z <= 3500000000000.0d0) 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 <= -14.0) {
tmp = x;
} else if (z <= 3500000000000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -14.0: tmp = x elif z <= 3500000000000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -14.0) tmp = x; elseif (z <= 3500000000000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -14.0) tmp = x; elseif (z <= 3500000000000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -14.0], x, If[LessEqual[z, 3500000000000.0], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -14:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3500000000000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -14 or 3.5e12 < z Initial program 100.0%
Taylor expanded in z around inf 74.0%
if -14 < z < 3.5e12Initial program 100.0%
Taylor expanded in y around inf 49.9%
Taylor expanded in x around 0 49.7%
Final simplification61.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 35.9%
Final simplification35.9%
herbie shell --seed 2023293
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))