
(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%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) x (if (<= z -6.5e-69) (/ (- x) z) (if (<= z 7.5e+75) (/ y z) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x;
} else if (z <= -6.5e-69) {
tmp = -x / z;
} else if (z <= 7.5e+75) {
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 <= (-1.0d0)) then
tmp = x
else if (z <= (-6.5d-69)) then
tmp = -x / z
else if (z <= 7.5d+75) 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 <= -1.0) {
tmp = x;
} else if (z <= -6.5e-69) {
tmp = -x / z;
} else if (z <= 7.5e+75) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x elif z <= -6.5e-69: tmp = -x / z elif z <= 7.5e+75: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = x; elseif (z <= -6.5e-69) tmp = Float64(Float64(-x) / z); elseif (z <= 7.5e+75) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = x; elseif (z <= -6.5e-69) tmp = -x / z; elseif (z <= 7.5e+75) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], x, If[LessEqual[z, -6.5e-69], N[((-x) / z), $MachinePrecision], If[LessEqual[z, 7.5e+75], N[(y / z), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -6.5 \cdot 10^{-69}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{elif}\;z \leq 7.5 \cdot 10^{+75}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 7.4999999999999995e75 < z Initial program 100.0%
Taylor expanded in z around inf 76.1%
if -1 < z < -6.49999999999999951e-69Initial program 99.9%
Taylor expanded in x around inf 80.0%
distribute-rgt-out--79.8%
*-lft-identity79.8%
associate-*l/80.2%
*-lft-identity80.2%
Simplified80.2%
Taylor expanded in z around 0 70.9%
mul-1-neg70.9%
distribute-neg-frac270.9%
Simplified70.9%
if -6.49999999999999951e-69 < z < 7.4999999999999995e75Initial program 100.0%
+-commutative100.0%
div-sub97.7%
associate-+l-97.6%
div-inv97.6%
fma-neg99.1%
Applied egg-rr99.1%
Taylor expanded in y around inf 63.7%
Final simplification69.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -13500000000.0) (not (<= z 4.1e-7))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -13500000000.0) || !(z <= 4.1e-7)) {
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 <= (-13500000000.0d0)) .or. (.not. (z <= 4.1d-7))) 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 <= -13500000000.0) || !(z <= 4.1e-7)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -13500000000.0) or not (z <= 4.1e-7): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -13500000000.0) || !(z <= 4.1e-7)) 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 <= -13500000000.0) || ~((z <= 4.1e-7))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -13500000000.0], N[Not[LessEqual[z, 4.1e-7]], $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 -13500000000 \lor \neg \left(z \leq 4.1 \cdot 10^{-7}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1.35e10 or 4.0999999999999999e-7 < z Initial program 100.0%
Taylor expanded in y around inf 98.8%
if -1.35e10 < z < 4.0999999999999999e-7Initial program 100.0%
+-commutative100.0%
div-sub97.6%
associate-+l-97.6%
div-inv97.5%
fma-neg99.1%
Applied egg-rr99.1%
Taylor expanded in z around 0 98.4%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.5e+54) (not (<= y 2.45e-51))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.5e+54) || !(y <= 2.45e-51)) {
tmp = x + (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 <= (-7.5d+54)) .or. (.not. (y <= 2.45d-51))) then
tmp = x + (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 <= -7.5e+54) || !(y <= 2.45e-51)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.5e+54) or not (y <= 2.45e-51): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.5e+54) || !(y <= 2.45e-51)) tmp = Float64(x + 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 <= -7.5e+54) || ~((y <= 2.45e-51))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.5e+54], N[Not[LessEqual[y, 2.45e-51]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+54} \lor \neg \left(y \leq 2.45 \cdot 10^{-51}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -7.50000000000000042e54 or 2.44999999999999987e-51 < y Initial program 100.0%
Taylor expanded in y around inf 93.3%
if -7.50000000000000042e54 < y < 2.44999999999999987e-51Initial program 100.0%
Taylor expanded in x around inf 85.9%
distribute-rgt-out--85.8%
*-lft-identity85.8%
associate-*l/85.9%
*-lft-identity85.9%
Simplified85.9%
Final simplification90.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.2e+32) (not (<= z 3.9e+76))) x (/ y z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e+32) || !(z <= 3.9e+76)) {
tmp = x;
} 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 ((z <= (-3.2d+32)) .or. (.not. (z <= 3.9d+76))) then
tmp = x
else
tmp = y / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e+32) || !(z <= 3.9e+76)) {
tmp = x;
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.2e+32) or not (z <= 3.9e+76): tmp = x else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.2e+32) || !(z <= 3.9e+76)) tmp = x; else tmp = Float64(y / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.2e+32) || ~((z <= 3.9e+76))) tmp = x; else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.2e+32], N[Not[LessEqual[z, 3.9e+76]], $MachinePrecision]], x, N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.2 \cdot 10^{+32} \lor \neg \left(z \leq 3.9 \cdot 10^{+76}\right):\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if z < -3.1999999999999999e32 or 3.89999999999999989e76 < z Initial program 100.0%
Taylor expanded in z around inf 79.2%
if -3.1999999999999999e32 < z < 3.89999999999999989e76Initial program 100.0%
+-commutative100.0%
div-sub98.0%
associate-+l-98.0%
div-inv97.9%
fma-neg99.2%
Applied egg-rr99.2%
Taylor expanded in y around inf 59.3%
Final simplification67.3%
(FPCore (x y z) :precision binary64 (+ x (/ y z)))
double code(double x, double y, double z) {
return x + (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 = x + (y / z)
end function
public static double code(double x, double y, double z) {
return x + (y / z);
}
def code(x, y, z): return x + (y / z)
function code(x, y, z) return Float64(x + Float64(y / z)) end
function tmp = code(x, y, z) tmp = x + (y / z); end
code[x_, y_, z_] := N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{z}
\end{array}
Initial program 100.0%
Taylor expanded in y around inf 79.2%
(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 36.9%
herbie shell --seed 2024096
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))