
(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 -4.4) 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 <= -4.4) {
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 <= (-4.4d0)) 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 <= -4.4) {
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 <= -4.4: 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 <= -4.4) 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 <= -4.4) 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, -4.4], 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 -4.4:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -4.4000000000000004 or 1 < z Initial program 100.0%
Taylor expanded in y around inf
/-lowering-/.f6498.6%
Simplified98.6%
if -4.4000000000000004 < z < 1Initial program 100.0%
Taylor expanded in z around 0
sub-negN/A
+-commutativeN/A
neg-sub0N/A
associate-+l-N/A
sub0-negN/A
/-lowering-/.f64N/A
sub0-negN/A
associate-+l-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
--lowering--.f6498.4%
Simplified98.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (/ x z)))) (if (<= x -2.6e+96) t_0 (if (<= x 1.9e+44) (+ x (/ y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (x <= -2.6e+96) {
tmp = t_0;
} else if (x <= 1.9e+44) {
tmp = x + (y / 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 / z)
if (x <= (-2.6d+96)) then
tmp = t_0
else if (x <= 1.9d+44) then
tmp = x + (y / 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 / z);
double tmp;
if (x <= -2.6e+96) {
tmp = t_0;
} else if (x <= 1.9e+44) {
tmp = x + (y / z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x / z) tmp = 0 if x <= -2.6e+96: tmp = t_0 elif x <= 1.9e+44: tmp = x + (y / z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x - Float64(x / z)) tmp = 0.0 if (x <= -2.6e+96) tmp = t_0; elseif (x <= 1.9e+44) tmp = Float64(x + Float64(y / z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x - (x / z); tmp = 0.0; if (x <= -2.6e+96) tmp = t_0; elseif (x <= 1.9e+44) tmp = x + (y / z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.6e+96], t$95$0, If[LessEqual[x, 1.9e+44], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \frac{x}{z}\\
\mathbf{if}\;x \leq -2.6 \cdot 10^{+96}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{+44}:\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.6e96 or 1.9000000000000001e44 < x Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
associate-*r/N/A
*-rgt-identityN/A
--lowering--.f64N/A
/-lowering-/.f6498.3%
Simplified98.3%
if -2.6e96 < x < 1.9000000000000001e44Initial program 100.0%
Taylor expanded in y around inf
/-lowering-/.f6487.3%
Simplified87.3%
(FPCore (x y z) :precision binary64 (if (<= z -1.4e+72) x (if (<= z 1.15e+98) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.4e+72) {
tmp = x;
} else if (z <= 1.15e+98) {
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.4d+72)) then
tmp = x
else if (z <= 1.15d+98) 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.4e+72) {
tmp = x;
} else if (z <= 1.15e+98) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.4e+72: tmp = x elif z <= 1.15e+98: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.4e+72) tmp = x; elseif (z <= 1.15e+98) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.4e+72) tmp = x; elseif (z <= 1.15e+98) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.4e+72], x, If[LessEqual[z, 1.15e+98], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{+72}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+98}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.4e72 or 1.15000000000000007e98 < z Initial program 100.0%
Taylor expanded in z around inf
Simplified73.5%
if -1.4e72 < z < 1.15000000000000007e98Initial program 100.0%
Taylor expanded in x around 0
/-lowering-/.f6452.6%
Simplified52.6%
(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
/-lowering-/.f6474.6%
Simplified74.6%
(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
Simplified33.9%
herbie shell --seed 2024150
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))