
(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 5 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%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.4e-51) (not (<= x 3.5e+95))) (- x (/ x z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e-51) || !(x <= 3.5e+95)) {
tmp = x - (x / 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 ((x <= (-2.4d-51)) .or. (.not. (x <= 3.5d+95))) then
tmp = x - (x / 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 ((x <= -2.4e-51) || !(x <= 3.5e+95)) {
tmp = x - (x / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.4e-51) or not (x <= 3.5e+95): tmp = x - (x / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.4e-51) || !(x <= 3.5e+95)) tmp = Float64(x - Float64(x / z)); else tmp = Float64(Float64(y - x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.4e-51) || ~((x <= 3.5e+95))) tmp = x - (x / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.4e-51], N[Not[LessEqual[x, 3.5e+95]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{-51} \lor \neg \left(x \leq 3.5 \cdot 10^{+95}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if x < -2.4e-51 or 3.5e95 < x Initial program 100.0%
Taylor expanded in x around inf
distribute-rgt-out--N/A
*-lft-identityN/A
associate-*l/N/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f6487.3
Applied rewrites87.3%
if -2.4e-51 < x < 3.5e95Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6479.4
Applied rewrites79.4%
Final simplification82.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.3e+37) (not (<= y 4e-15))) (/ y z) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.3e+37) || !(y <= 4e-15)) {
tmp = 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 <= (-3.3d+37)) .or. (.not. (y <= 4d-15))) then
tmp = 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 <= -3.3e+37) || !(y <= 4e-15)) {
tmp = y / z;
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.3e+37) or not (y <= 4e-15): tmp = y / z else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.3e+37) || !(y <= 4e-15)) tmp = 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 <= -3.3e+37) || ~((y <= 4e-15))) tmp = y / z; else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.3e+37], N[Not[LessEqual[y, 4e-15]], $MachinePrecision]], N[(y / z), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{+37} \lor \neg \left(y \leq 4 \cdot 10^{-15}\right):\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -3.3000000000000001e37 or 4.0000000000000003e-15 < y Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6476.4
Applied rewrites76.4%
if -3.3000000000000001e37 < y < 4.0000000000000003e-15Initial program 100.0%
Taylor expanded in x around inf
distribute-rgt-out--N/A
*-lft-identityN/A
associate-*l/N/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f6479.5
Applied rewrites79.5%
Final simplification78.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.9e-156) (not (<= y 9.5e-16))) (/ y z) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.9e-156) || !(y <= 9.5e-16)) {
tmp = 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 <= (-1.9d-156)) .or. (.not. (y <= 9.5d-16))) then
tmp = 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 <= -1.9e-156) || !(y <= 9.5e-16)) {
tmp = y / z;
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.9e-156) or not (y <= 9.5e-16): tmp = y / z else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.9e-156) || !(y <= 9.5e-16)) tmp = 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 <= -1.9e-156) || ~((y <= 9.5e-16))) tmp = y / z; else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.9e-156], N[Not[LessEqual[y, 9.5e-16]], $MachinePrecision]], N[(y / z), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{-156} \lor \neg \left(y \leq 9.5 \cdot 10^{-16}\right):\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if y < -1.90000000000000004e-156 or 9.5000000000000005e-16 < y Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6466.5
Applied rewrites66.5%
if -1.90000000000000004e-156 < y < 9.5000000000000005e-16Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6456.6
Applied rewrites56.6%
Taylor expanded in x around inf
Applied rewrites45.7%
Final simplification59.3%
(FPCore (x y z) :precision binary64 (/ y z))
double code(double x, double y, double z) {
return y / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y / z
end function
public static double code(double x, double y, double z) {
return y / z;
}
def code(x, y, z): return y / z
function code(x, y, z) return Float64(y / z) end
function tmp = code(x, y, z) tmp = y / z; end
code[x_, y_, z_] := N[(y / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{z}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6448.1
Applied rewrites48.1%
herbie shell --seed 2024322
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))