
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (- x) z)))
(if (<= z -4e+84)
x
(if (<= z -3.2e-16)
(/ y z)
(if (<= z -1.15e-89)
t_0
(if (<= z -4.4e-270) (/ y z) (if (<= z 1.0) t_0 x)))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -4e+84) {
tmp = x;
} else if (z <= -3.2e-16) {
tmp = y / z;
} else if (z <= -1.15e-89) {
tmp = t_0;
} else if (z <= -4.4e-270) {
tmp = y / z;
} else if (z <= 1.0) {
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 <= (-4d+84)) then
tmp = x
else if (z <= (-3.2d-16)) then
tmp = y / z
else if (z <= (-1.15d-89)) then
tmp = t_0
else if (z <= (-4.4d-270)) then
tmp = y / z
else if (z <= 1.0d0) 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 <= -4e+84) {
tmp = x;
} else if (z <= -3.2e-16) {
tmp = y / z;
} else if (z <= -1.15e-89) {
tmp = t_0;
} else if (z <= -4.4e-270) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -4e+84: tmp = x elif z <= -3.2e-16: tmp = y / z elif z <= -1.15e-89: tmp = t_0 elif z <= -4.4e-270: tmp = y / z elif z <= 1.0: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -4e+84) tmp = x; elseif (z <= -3.2e-16) tmp = Float64(y / z); elseif (z <= -1.15e-89) tmp = t_0; elseif (z <= -4.4e-270) tmp = Float64(y / z); elseif (z <= 1.0) 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 <= -4e+84) tmp = x; elseif (z <= -3.2e-16) tmp = y / z; elseif (z <= -1.15e-89) tmp = t_0; elseif (z <= -4.4e-270) tmp = y / z; elseif (z <= 1.0) 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, -4e+84], x, If[LessEqual[z, -3.2e-16], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.15e-89], t$95$0, If[LessEqual[z, -4.4e-270], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.0], t$95$0, x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -4 \cdot 10^{+84}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -3.2 \cdot 10^{-16}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -1.15 \cdot 10^{-89}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -4.4 \cdot 10^{-270}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.00000000000000023e84 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 73.5%
if -4.00000000000000023e84 < z < -3.20000000000000023e-16 or -1.15e-89 < z < -4.3999999999999997e-270Initial program 100.0%
Taylor expanded in x around 0 65.3%
if -3.20000000000000023e-16 < z < -1.15e-89 or -4.3999999999999997e-270 < z < 1Initial program 100.0%
Taylor expanded in x around inf 62.5%
*-commutative62.5%
sub-neg62.5%
distribute-lft-in62.5%
*-rgt-identity62.5%
distribute-rgt-neg-out62.5%
associate-*r/62.5%
*-rgt-identity62.5%
sub-neg62.5%
Simplified62.5%
Taylor expanded in z around 0 61.4%
mul-1-neg61.4%
distribute-frac-neg61.4%
Simplified61.4%
Final simplification67.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.5e-130) (not (<= x 1.4e-54))) (- x (/ x z)) (/ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e-130) || !(x <= 1.4e-54)) {
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 <= (-6.5d-130)) .or. (.not. (x <= 1.4d-54))) 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 <= -6.5e-130) || !(x <= 1.4e-54)) {
tmp = x - (x / z);
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.5e-130) or not (x <= 1.4e-54): tmp = x - (x / z) else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.5e-130) || !(x <= 1.4e-54)) 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 <= -6.5e-130) || ~((x <= 1.4e-54))) tmp = x - (x / z); else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.5e-130], N[Not[LessEqual[x, 1.4e-54]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-130} \lor \neg \left(x \leq 1.4 \cdot 10^{-54}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if x < -6.5000000000000002e-130 or 1.4000000000000001e-54 < x Initial program 100.0%
Taylor expanded in x around inf 79.0%
*-commutative79.0%
sub-neg79.0%
distribute-lft-in79.0%
*-rgt-identity79.0%
distribute-rgt-neg-out79.0%
associate-*r/79.0%
*-rgt-identity79.0%
sub-neg79.0%
Simplified79.0%
if -6.5000000000000002e-130 < x < 1.4000000000000001e-54Initial program 100.0%
Taylor expanded in x around 0 70.8%
Final simplification76.4%
(FPCore (x y z) :precision binary64 (if (<= z -1.95e+83) x (if (<= z 16500000000.0) (/ (- y x) z) (- x (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.95e+83) {
tmp = x;
} else if (z <= 16500000000.0) {
tmp = (y - x) / z;
} else {
tmp = x - (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 <= (-1.95d+83)) then
tmp = x
else if (z <= 16500000000.0d0) then
tmp = (y - x) / z
else
tmp = x - (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.95e+83) {
tmp = x;
} else if (z <= 16500000000.0) {
tmp = (y - x) / z;
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.95e+83: tmp = x elif z <= 16500000000.0: tmp = (y - x) / z else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.95e+83) tmp = x; elseif (z <= 16500000000.0) tmp = Float64(Float64(y - x) / z); else tmp = Float64(x - Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.95e+83) tmp = x; elseif (z <= 16500000000.0) tmp = (y - x) / z; else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.95e+83], x, If[LessEqual[z, 16500000000.0], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{+83}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 16500000000:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if z < -1.9500000000000001e83Initial program 100.0%
Taylor expanded in z around inf 85.5%
if -1.9500000000000001e83 < z < 1.65e10Initial program 100.0%
Taylor expanded in z around 0 94.3%
if 1.65e10 < z Initial program 100.0%
Taylor expanded in x around inf 68.8%
*-commutative68.8%
sub-neg68.8%
distribute-lft-in68.8%
*-rgt-identity68.8%
distribute-rgt-neg-out68.8%
associate-*r/68.8%
*-rgt-identity68.8%
sub-neg68.8%
Simplified68.8%
Final simplification86.4%
(FPCore (x y z) :precision binary64 (if (<= z -8.2e+85) x (if (<= z 1.9e+15) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.2e+85) {
tmp = x;
} else if (z <= 1.9e+15) {
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 <= (-8.2d+85)) then
tmp = x
else if (z <= 1.9d+15) 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 <= -8.2e+85) {
tmp = x;
} else if (z <= 1.9e+15) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.2e+85: tmp = x elif z <= 1.9e+15: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.2e+85) tmp = x; elseif (z <= 1.9e+15) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.2e+85) tmp = x; elseif (z <= 1.9e+15) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.2e+85], x, If[LessEqual[z, 1.9e+15], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.2 \cdot 10^{+85}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{+15}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.19999999999999957e85 or 1.9e15 < z Initial program 100.0%
Taylor expanded in z around inf 76.5%
if -8.19999999999999957e85 < z < 1.9e15Initial program 100.0%
Taylor expanded in x around 0 50.9%
Final simplification62.2%
(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 37.5%
Final simplification37.5%
herbie shell --seed 2023174
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))