
(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 6 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 -2.9e+14)
x
(if (<= z -5.7e-96)
(/ y z)
(if (<= z -2.8e-188)
t_0
(if (<= z -1.45e-286)
(/ y z)
(if (<= z 4.9e-225)
t_0
(if (<= z 7.8e-143)
(/ y z)
(if (<= z 1.25e-136) t_0 (if (<= z 7.6e+116) (/ y z) x))))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -2.9e+14) {
tmp = x;
} else if (z <= -5.7e-96) {
tmp = y / z;
} else if (z <= -2.8e-188) {
tmp = t_0;
} else if (z <= -1.45e-286) {
tmp = y / z;
} else if (z <= 4.9e-225) {
tmp = t_0;
} else if (z <= 7.8e-143) {
tmp = y / z;
} else if (z <= 1.25e-136) {
tmp = t_0;
} else if (z <= 7.6e+116) {
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 <= (-2.9d+14)) then
tmp = x
else if (z <= (-5.7d-96)) then
tmp = y / z
else if (z <= (-2.8d-188)) then
tmp = t_0
else if (z <= (-1.45d-286)) then
tmp = y / z
else if (z <= 4.9d-225) then
tmp = t_0
else if (z <= 7.8d-143) then
tmp = y / z
else if (z <= 1.25d-136) then
tmp = t_0
else if (z <= 7.6d+116) 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 <= -2.9e+14) {
tmp = x;
} else if (z <= -5.7e-96) {
tmp = y / z;
} else if (z <= -2.8e-188) {
tmp = t_0;
} else if (z <= -1.45e-286) {
tmp = y / z;
} else if (z <= 4.9e-225) {
tmp = t_0;
} else if (z <= 7.8e-143) {
tmp = y / z;
} else if (z <= 1.25e-136) {
tmp = t_0;
} else if (z <= 7.6e+116) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -2.9e+14: tmp = x elif z <= -5.7e-96: tmp = y / z elif z <= -2.8e-188: tmp = t_0 elif z <= -1.45e-286: tmp = y / z elif z <= 4.9e-225: tmp = t_0 elif z <= 7.8e-143: tmp = y / z elif z <= 1.25e-136: tmp = t_0 elif z <= 7.6e+116: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -2.9e+14) tmp = x; elseif (z <= -5.7e-96) tmp = Float64(y / z); elseif (z <= -2.8e-188) tmp = t_0; elseif (z <= -1.45e-286) tmp = Float64(y / z); elseif (z <= 4.9e-225) tmp = t_0; elseif (z <= 7.8e-143) tmp = Float64(y / z); elseif (z <= 1.25e-136) tmp = t_0; elseif (z <= 7.6e+116) 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 <= -2.9e+14) tmp = x; elseif (z <= -5.7e-96) tmp = y / z; elseif (z <= -2.8e-188) tmp = t_0; elseif (z <= -1.45e-286) tmp = y / z; elseif (z <= 4.9e-225) tmp = t_0; elseif (z <= 7.8e-143) tmp = y / z; elseif (z <= 1.25e-136) tmp = t_0; elseif (z <= 7.6e+116) 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, -2.9e+14], x, If[LessEqual[z, -5.7e-96], N[(y / z), $MachinePrecision], If[LessEqual[z, -2.8e-188], t$95$0, If[LessEqual[z, -1.45e-286], N[(y / z), $MachinePrecision], If[LessEqual[z, 4.9e-225], t$95$0, If[LessEqual[z, 7.8e-143], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.25e-136], t$95$0, If[LessEqual[z, 7.6e+116], N[(y / z), $MachinePrecision], x]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -2.9 \cdot 10^{+14}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -5.7 \cdot 10^{-96}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -2.8 \cdot 10^{-188}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1.45 \cdot 10^{-286}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 4.9 \cdot 10^{-225}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 7.8 \cdot 10^{-143}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.25 \cdot 10^{-136}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 7.6 \cdot 10^{+116}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.9e14 or 7.5999999999999998e116 < z Initial program 100.0%
Taylor expanded in z around inf 76.9%
if -2.9e14 < z < -5.70000000000000009e-96 or -2.8000000000000001e-188 < z < -1.4499999999999999e-286 or 4.89999999999999971e-225 < z < 7.80000000000000007e-143 or 1.25e-136 < z < 7.5999999999999998e116Initial program 100.0%
flip-+31.5%
div-inv31.4%
pow231.4%
Applied egg-rr31.4%
Taylor expanded in x around 0 60.7%
if -5.70000000000000009e-96 < z < -2.8000000000000001e-188 or -1.4499999999999999e-286 < z < 4.89999999999999971e-225 or 7.80000000000000007e-143 < z < 1.25e-136Initial program 100.0%
Taylor expanded in x around inf 76.4%
Taylor expanded in z around 0 76.7%
mul-1-neg76.7%
distribute-frac-neg76.7%
Simplified76.7%
Final simplification69.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.3e-234) (not (<= y 3.9e-158))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.3e-234) || !(y <= 3.9e-158)) {
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 ((y <= (-3.3d-234)) .or. (.not. (y <= 3.9d-158))) 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 ((y <= -3.3e-234) || !(y <= 3.9e-158)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.3e-234) or not (y <= 3.9e-158): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.3e-234) || !(y <= 3.9e-158)) 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 ((y <= -3.3e-234) || ~((y <= 3.9e-158))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.3e-234], N[Not[LessEqual[y, 3.9e-158]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{-234} \lor \neg \left(y \leq 3.9 \cdot 10^{-158}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if y < -3.30000000000000014e-234 or 3.8999999999999997e-158 < y Initial program 100.0%
Taylor expanded in y around inf 80.1%
if -3.30000000000000014e-234 < y < 3.8999999999999997e-158Initial program 99.9%
Taylor expanded in x around inf 92.9%
Taylor expanded in z around 0 61.8%
mul-1-neg61.8%
distribute-frac-neg61.8%
Simplified61.8%
Final simplification77.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.3e+56) (not (<= x 2.4e-48))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.3e+56) || !(x <= 2.4e-48)) {
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 <= (-1.3d+56)) .or. (.not. (x <= 2.4d-48))) 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 <= -1.3e+56) || !(x <= 2.4e-48)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.3e+56) or not (x <= 2.4e-48): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.3e+56) || !(x <= 2.4e-48)) 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 <= -1.3e+56) || ~((x <= 2.4e-48))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.3e+56], N[Not[LessEqual[x, 2.4e-48]], $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 -1.3 \cdot 10^{+56} \lor \neg \left(x \leq 2.4 \cdot 10^{-48}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.30000000000000005e56 or 2.4e-48 < x Initial program 100.0%
Taylor expanded in y around 0 88.3%
if -1.30000000000000005e56 < x < 2.4e-48Initial program 100.0%
Taylor expanded in y around inf 86.7%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (<= z -9.6e+16) x (if (<= z 8e+116) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.6e+16) {
tmp = x;
} else if (z <= 8e+116) {
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 <= (-9.6d+16)) then
tmp = x
else if (z <= 8d+116) 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 <= -9.6e+16) {
tmp = x;
} else if (z <= 8e+116) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.6e+16: tmp = x elif z <= 8e+116: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.6e+16) tmp = x; elseif (z <= 8e+116) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.6e+16) tmp = x; elseif (z <= 8e+116) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.6e+16], x, If[LessEqual[z, 8e+116], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.6 \cdot 10^{+16}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 8 \cdot 10^{+116}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.6e16 or 8.00000000000000012e116 < z Initial program 100.0%
Taylor expanded in z around inf 76.9%
if -9.6e16 < z < 8.00000000000000012e116Initial program 100.0%
flip-+27.8%
div-inv27.7%
pow227.7%
Applied egg-rr27.7%
Taylor expanded in x around 0 51.3%
Final simplification60.5%
(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 33.3%
Final simplification33.3%
herbie shell --seed 2023268
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))