
(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 (<= z -2.2e+64) (not (<= z 1.92e+24))) (- x (/ x z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.2e+64) || !(z <= 1.92e+24)) {
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 ((z <= (-2.2d+64)) .or. (.not. (z <= 1.92d+24))) 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 ((z <= -2.2e+64) || !(z <= 1.92e+24)) {
tmp = x - (x / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.2e+64) or not (z <= 1.92e+24): tmp = x - (x / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.2e+64) || !(z <= 1.92e+24)) 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 ((z <= -2.2e+64) || ~((z <= 1.92e+24))) tmp = x - (x / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.2e+64], N[Not[LessEqual[z, 1.92e+24]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+64} \lor \neg \left(z \leq 1.92 \cdot 10^{+24}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -2.20000000000000002e64 or 1.92e24 < z Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
associate-*r/N/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6479.8
Applied rewrites79.8%
if -2.20000000000000002e64 < z < 1.92e24Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6494.8
Applied rewrites94.8%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.85e-9) (not (<= x 2.6e-66))) (- x (/ x z)) (/ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.85e-9) || !(x <= 2.6e-66)) {
tmp = x - (x / z);
} else {
tmp = 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.85d-9)) .or. (.not. (x <= 2.6d-66))) then
tmp = x - (x / z)
else
tmp = y / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.85e-9) || !(x <= 2.6e-66)) {
tmp = x - (x / z);
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.85e-9) or not (x <= 2.6e-66): tmp = x - (x / z) else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.85e-9) || !(x <= 2.6e-66)) tmp = Float64(x - Float64(x / z)); else tmp = Float64(y / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.85e-9) || ~((x <= 2.6e-66))) tmp = x - (x / z); else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.85e-9], N[Not[LessEqual[x, 2.6e-66]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{-9} \lor \neg \left(x \leq 2.6 \cdot 10^{-66}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if x < -1.85e-9 or 2.5999999999999999e-66 < x Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
associate-*r/N/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6489.1
Applied rewrites89.1%
if -1.85e-9 < x < 2.5999999999999999e-66Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6467.1
Applied rewrites67.1%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.2e+58) (not (<= x 1.4e-22))) (/ (- x) z) (/ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.2e+58) || !(x <= 1.4e-22)) {
tmp = -x / z;
} else {
tmp = 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 <= (-5.2d+58)) .or. (.not. (x <= 1.4d-22))) then
tmp = -x / z
else
tmp = y / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.2e+58) || !(x <= 1.4e-22)) {
tmp = -x / z;
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.2e+58) or not (x <= 1.4e-22): tmp = -x / z else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.2e+58) || !(x <= 1.4e-22)) tmp = Float64(Float64(-x) / z); else tmp = Float64(y / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.2e+58) || ~((x <= 1.4e-22))) tmp = -x / z; else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.2e+58], N[Not[LessEqual[x, 1.4e-22]], $MachinePrecision]], N[((-x) / z), $MachinePrecision], N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{+58} \lor \neg \left(x \leq 1.4 \cdot 10^{-22}\right):\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if x < -5.19999999999999976e58 or 1.39999999999999997e-22 < x Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6454.2
Applied rewrites54.2%
Taylor expanded in x around inf
Applied rewrites47.3%
if -5.19999999999999976e58 < x < 1.39999999999999997e-22Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6462.4
Applied rewrites62.4%
Final simplification55.8%
(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-/.f6440.3
Applied rewrites40.3%
herbie shell --seed 2024320
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))