
(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 6 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 -2200000000000.0)
x
(if (<= z -1.25e-60)
(/ y z)
(if (<= z -2.3e-232)
t_0
(if (<= z 4.3e-280) (/ y z) (if (<= z 1.3e-9) t_0 x)))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -2200000000000.0) {
tmp = x;
} else if (z <= -1.25e-60) {
tmp = y / z;
} else if (z <= -2.3e-232) {
tmp = t_0;
} else if (z <= 4.3e-280) {
tmp = y / z;
} else if (z <= 1.3e-9) {
tmp = t_0;
} 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 <= (-2200000000000.0d0)) then
tmp = x
else if (z <= (-1.25d-60)) then
tmp = y / z
else if (z <= (-2.3d-232)) then
tmp = t_0
else if (z <= 4.3d-280) then
tmp = y / z
else if (z <= 1.3d-9) then
tmp = t_0
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 <= -2200000000000.0) {
tmp = x;
} else if (z <= -1.25e-60) {
tmp = y / z;
} else if (z <= -2.3e-232) {
tmp = t_0;
} else if (z <= 4.3e-280) {
tmp = y / z;
} else if (z <= 1.3e-9) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -2200000000000.0: tmp = x elif z <= -1.25e-60: tmp = y / z elif z <= -2.3e-232: tmp = t_0 elif z <= 4.3e-280: tmp = y / z elif z <= 1.3e-9: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -2200000000000.0) tmp = x; elseif (z <= -1.25e-60) tmp = Float64(y / z); elseif (z <= -2.3e-232) tmp = t_0; elseif (z <= 4.3e-280) tmp = Float64(y / z); elseif (z <= 1.3e-9) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x / z; tmp = 0.0; if (z <= -2200000000000.0) tmp = x; elseif (z <= -1.25e-60) tmp = y / z; elseif (z <= -2.3e-232) tmp = t_0; elseif (z <= 4.3e-280) tmp = y / z; elseif (z <= 1.3e-9) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -2200000000000.0], x, If[LessEqual[z, -1.25e-60], N[(y / z), $MachinePrecision], If[LessEqual[z, -2.3e-232], t$95$0, If[LessEqual[z, 4.3e-280], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.3e-9], t$95$0, x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -2200000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.25 \cdot 10^{-60}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -2.3 \cdot 10^{-232}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 4.3 \cdot 10^{-280}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{-9}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.05e+25)
(not
(or (<= x -4.8e-92) (and (not (<= x -3.3e-144)) (<= x 2.7e-95)))))
(- x (/ x z))
(/ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e+25) || !((x <= -4.8e-92) || (!(x <= -3.3e-144) && (x <= 2.7e-95)))) {
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.05d+25)) .or. (.not. (x <= (-4.8d-92)) .or. (.not. (x <= (-3.3d-144))) .and. (x <= 2.7d-95))) 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.05e+25) || !((x <= -4.8e-92) || (!(x <= -3.3e-144) && (x <= 2.7e-95)))) {
tmp = x - (x / z);
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.05e+25) or not ((x <= -4.8e-92) or (not (x <= -3.3e-144) and (x <= 2.7e-95))): tmp = x - (x / z) else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.05e+25) || !((x <= -4.8e-92) || (!(x <= -3.3e-144) && (x <= 2.7e-95)))) 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.05e+25) || ~(((x <= -4.8e-92) || (~((x <= -3.3e-144)) && (x <= 2.7e-95))))) tmp = x - (x / z); else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.05e+25], N[Not[Or[LessEqual[x, -4.8e-92], And[N[Not[LessEqual[x, -3.3e-144]], $MachinePrecision], LessEqual[x, 2.7e-95]]]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+25} \lor \neg \left(x \leq -4.8 \cdot 10^{-92} \lor \neg \left(x \leq -3.3 \cdot 10^{-144}\right) \land x \leq 2.7 \cdot 10^{-95}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= z -4.9e-5) (not (<= z 2.1e-5))) (- x (/ x z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.9e-5) || !(z <= 2.1e-5)) {
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 <= (-4.9d-5)) .or. (.not. (z <= 2.1d-5))) 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 <= -4.9e-5) || !(z <= 2.1e-5)) {
tmp = x - (x / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.9e-5) or not (z <= 2.1e-5): tmp = x - (x / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.9e-5) || !(z <= 2.1e-5)) 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 <= -4.9e-5) || ~((z <= 2.1e-5))) tmp = x - (x / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.9e-5], N[Not[LessEqual[z, 2.1e-5]], $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 -4.9 \cdot 10^{-5} \lor \neg \left(z \leq 2.1 \cdot 10^{-5}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= z -72000000000000.0) x (if (<= z 1.75e+16) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -72000000000000.0) {
tmp = x;
} else if (z <= 1.75e+16) {
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 <= (-72000000000000.0d0)) then
tmp = x
else if (z <= 1.75d+16) 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 <= -72000000000000.0) {
tmp = x;
} else if (z <= 1.75e+16) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -72000000000000.0: tmp = x elif z <= 1.75e+16: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -72000000000000.0) tmp = x; elseif (z <= 1.75e+16) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -72000000000000.0) tmp = x; elseif (z <= 1.75e+16) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -72000000000000.0], x, If[LessEqual[z, 1.75e+16], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -72000000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.75 \cdot 10^{+16}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\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 2023343
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))