
(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 4 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 (let* ((t_0 (+ x (+ x (- y x))))) (if (<= z -2.4e+40) t_0 (if (<= z 106000000.0) (/ (- y x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x + (x + (y - x));
double tmp;
if (z <= -2.4e+40) {
tmp = t_0;
} else if (z <= 106000000.0) {
tmp = (y - x) / z;
} else {
tmp = t_0;
}
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 + (x + (y - x))
if (z <= (-2.4d+40)) then
tmp = t_0
else if (z <= 106000000.0d0) then
tmp = (y - x) / z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (x + (y - x));
double tmp;
if (z <= -2.4e+40) {
tmp = t_0;
} else if (z <= 106000000.0) {
tmp = (y - x) / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (x + (y - x)) tmp = 0 if z <= -2.4e+40: tmp = t_0 elif z <= 106000000.0: tmp = (y - x) / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(x + Float64(y - x))) tmp = 0.0 if (z <= -2.4e+40) tmp = t_0; elseif (z <= 106000000.0) tmp = Float64(Float64(y - x) / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (x + (y - x)); tmp = 0.0; if (z <= -2.4e+40) tmp = t_0; elseif (z <= 106000000.0) tmp = (y - x) / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(x + N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.4e+40], t$95$0, If[LessEqual[z, 106000000.0], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \left(x + \left(y - x\right)\right)\\
\mathbf{if}\;z \leq -2.4 \cdot 10^{+40}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 106000000:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.4e40 or 1.06e8 < z Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites3.6%
Taylor expanded in x around 0
Applied rewrites51.9%
if -2.4e40 < z < 1.06e8Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.0%
(FPCore (x y z) :precision binary64 (+ x (+ x (- y x))))
double code(double x, double y, double z) {
return x + (x + (y - 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 + (x + (y - x))
end function
public static double code(double x, double y, double z) {
return x + (x + (y - x));
}
def code(x, y, z): return x + (x + (y - x))
function code(x, y, z) return Float64(x + Float64(x + Float64(y - x))) end
function tmp = code(x, y, z) tmp = x + (x + (y - x)); end
code[x_, y_, z_] := N[(x + N[(x + N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(x + \left(y - x\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites3.3%
Taylor expanded in x around 0
Applied rewrites30.2%
(FPCore (x y z) :precision binary64 (- y x))
double code(double x, double y, double z) {
return y - x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y - x
end function
public static double code(double x, double y, double z) {
return y - x;
}
def code(x, y, z): return y - x
function code(x, y, z) return Float64(y - x) end
function tmp = code(x, y, z) tmp = y - x; end
code[x_, y_, z_] := N[(y - x), $MachinePrecision]
\begin{array}{l}
\\
y - x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites58.9%
Taylor expanded in x around 0
Applied rewrites3.5%
herbie shell --seed 2024313
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))