
(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}
Initial program 100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ x (/ y z)))) (if (<= z -1.0) t_0 (if (<= z 1.0) (/ (- y x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x + (y / z);
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 1.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 + (y / z)
if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 1.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 + (y / z);
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = (y - x) / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y / z) tmp = 0 if z <= -1.0: tmp = t_0 elif z <= 1.0: tmp = (y - x) / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y / z)) tmp = 0.0 if (z <= -1.0) tmp = t_0; elseif (z <= 1.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 + (y / z); tmp = 0.0; if (z <= -1.0) tmp = t_0; elseif (z <= 1.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[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 1.0], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6499.0
Applied rewrites99.0%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6499.3
Applied rewrites99.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ (- y x) z))) (if (<= y -8.0) t_0 (if (<= y 7e-22) (- x (/ x z)) t_0))))
double code(double x, double y, double z) {
double t_0 = (y - x) / z;
double tmp;
if (y <= -8.0) {
tmp = t_0;
} else if (y <= 7e-22) {
tmp = x - (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 = (y - x) / z
if (y <= (-8.0d0)) then
tmp = t_0
else if (y <= 7d-22) then
tmp = x - (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 = (y - x) / z;
double tmp;
if (y <= -8.0) {
tmp = t_0;
} else if (y <= 7e-22) {
tmp = x - (x / z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - x) / z tmp = 0 if y <= -8.0: tmp = t_0 elif y <= 7e-22: tmp = x - (x / z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y - x) / z) tmp = 0.0 if (y <= -8.0) tmp = t_0; elseif (y <= 7e-22) tmp = Float64(x - Float64(x / z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y - x) / z; tmp = 0.0; if (y <= -8.0) tmp = t_0; elseif (y <= 7e-22) tmp = x - (x / z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[y, -8.0], t$95$0, If[LessEqual[y, 7e-22], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y - x}{z}\\
\mathbf{if}\;y \leq -8:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-22}:\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8 or 7.00000000000000011e-22 < y Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6481.6
Applied rewrites81.6%
if -8 < y < 7.00000000000000011e-22Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
associate-*r/N/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6489.1
Applied rewrites89.1%
(FPCore (x y z) :precision binary64 (if (<= y -1e+157) (/ y z) (if (<= y 1.1e+118) (- x (/ x z)) (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1e+157) {
tmp = y / z;
} else if (y <= 1.1e+118) {
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 (y <= (-1d+157)) then
tmp = y / z
else if (y <= 1.1d+118) 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 (y <= -1e+157) {
tmp = y / z;
} else if (y <= 1.1e+118) {
tmp = x - (x / z);
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1e+157: tmp = y / z elif y <= 1.1e+118: tmp = x - (x / z) else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1e+157) tmp = Float64(y / z); elseif (y <= 1.1e+118) 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 (y <= -1e+157) tmp = y / z; elseif (y <= 1.1e+118) tmp = x - (x / z); else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1e+157], N[(y / z), $MachinePrecision], If[LessEqual[y, 1.1e+118], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y / z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+157}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+118}:\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if y < -9.99999999999999983e156 or 1.09999999999999993e118 < y Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6490.5
Applied rewrites90.5%
if -9.99999999999999983e156 < y < 1.09999999999999993e118Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
associate-*r/N/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6479.2
Applied rewrites79.2%
(FPCore (x y z) :precision binary64 (if (<= y -1.45) (/ y z) (if (<= y 2.6e-22) (/ (- x) z) (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.45) {
tmp = y / z;
} else if (y <= 2.6e-22) {
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 (y <= (-1.45d0)) then
tmp = y / z
else if (y <= 2.6d-22) 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 (y <= -1.45) {
tmp = y / z;
} else if (y <= 2.6e-22) {
tmp = -x / z;
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.45: tmp = y / z elif y <= 2.6e-22: tmp = -x / z else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.45) tmp = Float64(y / z); elseif (y <= 2.6e-22) 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 (y <= -1.45) tmp = y / z; elseif (y <= 2.6e-22) tmp = -x / z; else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.45], N[(y / z), $MachinePrecision], If[LessEqual[y, 2.6e-22], N[((-x) / z), $MachinePrecision], N[(y / z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-22}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if y < -1.44999999999999996 or 2.6e-22 < y Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6470.4
Applied rewrites70.4%
if -1.44999999999999996 < y < 2.6e-22Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6448.0
Applied rewrites48.0%
Taylor expanded in y around 0
Applied rewrites37.4%
(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.3
Applied rewrites41.3%
herbie shell --seed 2024233
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))