
(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 -1e-62) (not (<= x 5.8e-24))) (- x (/ x z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1e-62) || !(x <= 5.8e-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 ((x <= (-1d-62)) .or. (.not. (x <= 5.8d-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 ((x <= -1e-62) || !(x <= 5.8e-24)) {
tmp = x - (x / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1e-62) or not (x <= 5.8e-24): tmp = x - (x / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1e-62) || !(x <= 5.8e-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 ((x <= -1e-62) || ~((x <= 5.8e-24))) tmp = x - (x / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1e-62], N[Not[LessEqual[x, 5.8e-24]], $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 -1 \cdot 10^{-62} \lor \neg \left(x \leq 5.8 \cdot 10^{-24}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if x < -1e-62 or 5.7999999999999997e-24 < 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-/.f6488.9
Applied rewrites88.9%
if -1e-62 < x < 5.7999999999999997e-24Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6480.8
Applied rewrites80.8%
Final simplification85.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.35e-82) (not (<= x 7.2e-68))) (- x (/ x z)) (/ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.35e-82) || !(x <= 7.2e-68)) {
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.35d-82)) .or. (.not. (x <= 7.2d-68))) 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.35e-82) || !(x <= 7.2e-68)) {
tmp = x - (x / z);
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.35e-82) or not (x <= 7.2e-68): tmp = x - (x / z) else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.35e-82) || !(x <= 7.2e-68)) 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.35e-82) || ~((x <= 7.2e-68))) tmp = x - (x / z); else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.35e-82], N[Not[LessEqual[x, 7.2e-68]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{-82} \lor \neg \left(x \leq 7.2 \cdot 10^{-68}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if x < -1.3500000000000001e-82 or 7.20000000000000015e-68 < 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-/.f6485.2
Applied rewrites85.2%
if -1.3500000000000001e-82 < x < 7.20000000000000015e-68Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6473.5
Applied rewrites73.5%
Final simplification80.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.02e+37) (not (<= x 6.2e-24))) (/ (- x) z) (/ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.02e+37) || !(x <= 6.2e-24)) {
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 <= (-2.02d+37)) .or. (.not. (x <= 6.2d-24))) 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 <= -2.02e+37) || !(x <= 6.2e-24)) {
tmp = -x / z;
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.02e+37) or not (x <= 6.2e-24): tmp = -x / z else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.02e+37) || !(x <= 6.2e-24)) 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 <= -2.02e+37) || ~((x <= 6.2e-24))) tmp = -x / z; else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.02e+37], N[Not[LessEqual[x, 6.2e-24]], $MachinePrecision]], N[((-x) / z), $MachinePrecision], N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.02 \cdot 10^{+37} \lor \neg \left(x \leq 6.2 \cdot 10^{-24}\right):\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if x < -2.0199999999999999e37 or 6.2000000000000001e-24 < x Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6448.3
Applied rewrites48.3%
Taylor expanded in x around inf
Applied rewrites40.6%
if -2.0199999999999999e37 < x < 6.2000000000000001e-24Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6464.6
Applied rewrites64.6%
Final simplification53.2%
(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-/.f6441.7
Applied rewrites41.7%
herbie shell --seed 2024298
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))