
(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}
Initial program 100.0%
(FPCore (x y z) :precision binary64 (if (<= (+ x (/ (- y x) z)) (- INFINITY)) (- (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x + ((y - x) / z)) <= -((double) INFINITY)) {
tmp = -(x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
public static double code(double x, double y, double z) {
double tmp;
if ((x + ((y - x) / z)) <= -Double.POSITIVE_INFINITY) {
tmp = -(x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + ((y - x) / z)) <= -math.inf: tmp = -(x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + Float64(Float64(y - x) / z)) <= Float64(-Inf)) tmp = Float64(-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 + ((y - x) / z)) <= -Inf) tmp = -(x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], (-Infinity)], (-N[(x / z), $MachinePrecision]), N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + \frac{y - x}{z} \leq -\infty:\\
\;\;\;\;-\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (-.f64 y x) z)) < -inf.0Initial 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-/.f6471.5
Simplified71.5%
Taylor expanded in z around 0
mul-1-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
neg-lowering-neg.f6471.5
Simplified71.5%
if -inf.0 < (+.f64 x (/.f64 (-.f64 y x) z)) Initial program 100.0%
Taylor expanded in y around inf
/-lowering-/.f6480.9
Simplified80.9%
Final simplification80.0%
(FPCore (x y z)
:precision binary64
(if (<= z -195.0)
x
(if (<= z -3.25e-80)
(/ y z)
(if (<= z 1e-274) (- (/ x z)) (if (<= z 2.3e+107) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -195.0) {
tmp = x;
} else if (z <= -3.25e-80) {
tmp = y / z;
} else if (z <= 1e-274) {
tmp = -(x / z);
} else if (z <= 2.3e+107) {
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 <= (-195.0d0)) then
tmp = x
else if (z <= (-3.25d-80)) then
tmp = y / z
else if (z <= 1d-274) then
tmp = -(x / z)
else if (z <= 2.3d+107) 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 <= -195.0) {
tmp = x;
} else if (z <= -3.25e-80) {
tmp = y / z;
} else if (z <= 1e-274) {
tmp = -(x / z);
} else if (z <= 2.3e+107) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -195.0: tmp = x elif z <= -3.25e-80: tmp = y / z elif z <= 1e-274: tmp = -(x / z) elif z <= 2.3e+107: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -195.0) tmp = x; elseif (z <= -3.25e-80) tmp = Float64(y / z); elseif (z <= 1e-274) tmp = Float64(-Float64(x / z)); elseif (z <= 2.3e+107) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -195.0) tmp = x; elseif (z <= -3.25e-80) tmp = y / z; elseif (z <= 1e-274) tmp = -(x / z); elseif (z <= 2.3e+107) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -195.0], x, If[LessEqual[z, -3.25e-80], N[(y / z), $MachinePrecision], If[LessEqual[z, 1e-274], (-N[(x / z), $MachinePrecision]), If[LessEqual[z, 2.3e+107], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -195:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -3.25 \cdot 10^{-80}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 10^{-274}:\\
\;\;\;\;-\frac{x}{z}\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{+107}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -195 or 2.3e107 < z Initial program 100.0%
Taylor expanded in z around inf
Simplified82.1%
if -195 < z < -3.24999999999999992e-80 or 9.99999999999999966e-275 < z < 2.3e107Initial program 100.0%
Taylor expanded in x around 0
/-lowering-/.f6458.3
Simplified58.3%
if -3.24999999999999992e-80 < z < 9.99999999999999966e-275Initial 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-/.f6459.8
Simplified59.8%
Taylor expanded in z around 0
mul-1-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
neg-lowering-neg.f6459.8
Simplified59.8%
Final simplification69.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ x (/ y z)))) (if (<= z -1.0) t_0 (if (<= z 0.000175) (/ (- 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 <= 0.000175) {
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 <= 0.000175d0) 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 <= 0.000175) {
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 <= 0.000175: 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 <= 0.000175) 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 <= 0.000175) 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, 0.000175], 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 0.000175:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 1.74999999999999998e-4 < z Initial program 100.0%
Taylor expanded in y around inf
/-lowering-/.f6497.7
Simplified97.7%
if -1 < z < 1.74999999999999998e-4Initial program 100.0%
Taylor expanded in z around 0
/-lowering-/.f64N/A
--lowering--.f6499.4
Simplified99.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (/ x z)))) (if (<= x -2.15e+73) t_0 (if (<= x 5.6e-50) (+ x (/ y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (x <= -2.15e+73) {
tmp = t_0;
} else if (x <= 5.6e-50) {
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.15d+73)) then
tmp = t_0
else if (x <= 5.6d-50) 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.15e+73) {
tmp = t_0;
} else if (x <= 5.6e-50) {
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.15e+73: tmp = t_0 elif x <= 5.6e-50: 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.15e+73) tmp = t_0; elseif (x <= 5.6e-50) 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.15e+73) tmp = t_0; elseif (x <= 5.6e-50) 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.15e+73], t$95$0, If[LessEqual[x, 5.6e-50], 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.15 \cdot 10^{+73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{-50}:\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.15000000000000007e73 or 5.5999999999999996e-50 < 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-/.f6493.8
Simplified93.8%
if -2.15000000000000007e73 < x < 5.5999999999999996e-50Initial program 100.0%
Taylor expanded in y around inf
/-lowering-/.f6487.8
Simplified87.8%
(FPCore (x y z) :precision binary64 (if (<= z -195.0) x (if (<= z 4.2e+107) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -195.0) {
tmp = x;
} else if (z <= 4.2e+107) {
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 <= (-195.0d0)) then
tmp = x
else if (z <= 4.2d+107) 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 <= -195.0) {
tmp = x;
} else if (z <= 4.2e+107) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -195.0: tmp = x elif z <= 4.2e+107: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -195.0) tmp = x; elseif (z <= 4.2e+107) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -195.0) tmp = x; elseif (z <= 4.2e+107) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -195.0], x, If[LessEqual[z, 4.2e+107], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -195:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.2 \cdot 10^{+107}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -195 or 4.1999999999999999e107 < z Initial program 100.0%
Taylor expanded in z around inf
Simplified82.1%
if -195 < z < 4.1999999999999999e107Initial program 100.0%
Taylor expanded in x around 0
/-lowering-/.f6452.8
Simplified52.8%
(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
Simplified41.0%
herbie shell --seed 2024199
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))