
(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}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (- x) z)))
(if (<= z -7e+16)
x
(if (<= z -3.5e-56)
(/ y z)
(if (<= z -1.85e-143)
t_0
(if (<= z -2.55e-294)
(/ y z)
(if (<= z 1.0)
t_0
(if (<= z 1.45e+106) x (if (<= z 6.2e+137) (/ y z) x)))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -7e+16) {
tmp = x;
} else if (z <= -3.5e-56) {
tmp = y / z;
} else if (z <= -1.85e-143) {
tmp = t_0;
} else if (z <= -2.55e-294) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = t_0;
} else if (z <= 1.45e+106) {
tmp = x;
} else if (z <= 6.2e+137) {
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 <= (-7d+16)) then
tmp = x
else if (z <= (-3.5d-56)) then
tmp = y / z
else if (z <= (-1.85d-143)) then
tmp = t_0
else if (z <= (-2.55d-294)) then
tmp = y / z
else if (z <= 1.0d0) then
tmp = t_0
else if (z <= 1.45d+106) then
tmp = x
else if (z <= 6.2d+137) 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 <= -7e+16) {
tmp = x;
} else if (z <= -3.5e-56) {
tmp = y / z;
} else if (z <= -1.85e-143) {
tmp = t_0;
} else if (z <= -2.55e-294) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = t_0;
} else if (z <= 1.45e+106) {
tmp = x;
} else if (z <= 6.2e+137) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -7e+16: tmp = x elif z <= -3.5e-56: tmp = y / z elif z <= -1.85e-143: tmp = t_0 elif z <= -2.55e-294: tmp = y / z elif z <= 1.0: tmp = t_0 elif z <= 1.45e+106: tmp = x elif z <= 6.2e+137: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -7e+16) tmp = x; elseif (z <= -3.5e-56) tmp = Float64(y / z); elseif (z <= -1.85e-143) tmp = t_0; elseif (z <= -2.55e-294) tmp = Float64(y / z); elseif (z <= 1.0) tmp = t_0; elseif (z <= 1.45e+106) tmp = x; elseif (z <= 6.2e+137) 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 <= -7e+16) tmp = x; elseif (z <= -3.5e-56) tmp = y / z; elseif (z <= -1.85e-143) tmp = t_0; elseif (z <= -2.55e-294) tmp = y / z; elseif (z <= 1.0) tmp = t_0; elseif (z <= 1.45e+106) tmp = x; elseif (z <= 6.2e+137) 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, -7e+16], x, If[LessEqual[z, -3.5e-56], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.85e-143], t$95$0, If[LessEqual[z, -2.55e-294], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.0], t$95$0, If[LessEqual[z, 1.45e+106], x, If[LessEqual[z, 6.2e+137], N[(y / z), $MachinePrecision], x]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -7 \cdot 10^{+16}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -3.5 \cdot 10^{-56}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -1.85 \cdot 10^{-143}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -2.55 \cdot 10^{-294}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{+106}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{+137}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
(FPCore (x y z)
:precision binary64
(if (or (<= z -3.4e-77)
(and (not (<= z -1.05e-134)) (or (<= z -6.5e-298) (not (<= z 0.58)))))
(+ x (/ y z))
(/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.4e-77) || (!(z <= -1.05e-134) && ((z <= -6.5e-298) || !(z <= 0.58)))) {
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 ((z <= (-3.4d-77)) .or. (.not. (z <= (-1.05d-134))) .and. (z <= (-6.5d-298)) .or. (.not. (z <= 0.58d0))) 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 ((z <= -3.4e-77) || (!(z <= -1.05e-134) && ((z <= -6.5e-298) || !(z <= 0.58)))) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.4e-77) or (not (z <= -1.05e-134) and ((z <= -6.5e-298) or not (z <= 0.58))): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.4e-77) || (!(z <= -1.05e-134) && ((z <= -6.5e-298) || !(z <= 0.58)))) 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 ((z <= -3.4e-77) || (~((z <= -1.05e-134)) && ((z <= -6.5e-298) || ~((z <= 0.58))))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.4e-77], And[N[Not[LessEqual[z, -1.05e-134]], $MachinePrecision], Or[LessEqual[z, -6.5e-298], N[Not[LessEqual[z, 0.58]], $MachinePrecision]]]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \cdot 10^{-77} \lor \neg \left(z \leq -1.05 \cdot 10^{-134}\right) \land \left(z \leq -6.5 \cdot 10^{-298} \lor \neg \left(z \leq 0.58\right)\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
(FPCore (x y z)
:precision binary64
(if (<= z -2.45e+18)
x
(if (or (<= z 950000000.0) (and (not (<= z 1.45e+106)) (<= z 9.2e+138)))
(/ y z)
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.45e+18) {
tmp = x;
} else if ((z <= 950000000.0) || (!(z <= 1.45e+106) && (z <= 9.2e+138))) {
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 <= (-2.45d+18)) then
tmp = x
else if ((z <= 950000000.0d0) .or. (.not. (z <= 1.45d+106)) .and. (z <= 9.2d+138)) 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 <= -2.45e+18) {
tmp = x;
} else if ((z <= 950000000.0) || (!(z <= 1.45e+106) && (z <= 9.2e+138))) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.45e+18: tmp = x elif (z <= 950000000.0) or (not (z <= 1.45e+106) and (z <= 9.2e+138)): tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.45e+18) tmp = x; elseif ((z <= 950000000.0) || (!(z <= 1.45e+106) && (z <= 9.2e+138))) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.45e+18) tmp = x; elseif ((z <= 950000000.0) || (~((z <= 1.45e+106)) && (z <= 9.2e+138))) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.45e+18], x, If[Or[LessEqual[z, 950000000.0], And[N[Not[LessEqual[z, 1.45e+106]], $MachinePrecision], LessEqual[z, 9.2e+138]]], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.45 \cdot 10^{+18}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 950000000 \lor \neg \left(z \leq 1.45 \cdot 10^{+106}\right) \land z \leq 9.2 \cdot 10^{+138}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -2.8e+61) (not (<= x 4.8e+81))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e+61) || !(x <= 4.8e+81)) {
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 <= (-2.8d+61)) .or. (.not. (x <= 4.8d+81))) 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 <= -2.8e+61) || !(x <= 4.8e+81)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.8e+61) or not (x <= 4.8e+81): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.8e+61) || !(x <= 4.8e+81)) 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 <= -2.8e+61) || ~((x <= 4.8e+81))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.8e+61], N[Not[LessEqual[x, 4.8e+81]], $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 -2.8 \cdot 10^{+61} \lor \neg \left(x \leq 4.8 \cdot 10^{+81}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
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 <= (-1.0d0)) .or. (.not. (z <= 1.0d0))) 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 <= -1.0) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) 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 <= -1.0) || ~((z <= 1.0))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $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 -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
(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}
herbie shell --seed 2023364
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))