
(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 5 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 (if (or (<= z -1.05e-134) (not (<= z 1.75e-36))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.05e-134) || !(z <= 1.75e-36)) {
tmp = x + (y / z);
} else {
tmp = -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.05d-134)) .or. (.not. (z <= 1.75d-36))) then
tmp = x + (y / z)
else
tmp = -x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.05e-134) || !(z <= 1.75e-36)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.05e-134) or not (z <= 1.75e-36): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.05e-134) || !(z <= 1.75e-36)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(Float64(-x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.05e-134) || ~((z <= 1.75e-36))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.05e-134], N[Not[LessEqual[z, 1.75e-36]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{-134} \lor \neg \left(z \leq 1.75 \cdot 10^{-36}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if z < -1.05e-134 or 1.75e-36 < z Initial program 100.0%
Taylor expanded in y around inf 92.0%
if -1.05e-134 < z < 1.75e-36Initial program 100.0%
Taylor expanded in y around 0 70.1%
neg-mul-170.1%
distribute-neg-frac70.1%
Simplified70.1%
Taylor expanded in z around 0 70.1%
mul-1-neg70.1%
distribute-neg-frac70.1%
Simplified70.1%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.2e-93) (not (<= x 7.2e-14))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e-93) || !(x <= 7.2e-14)) {
tmp = x - (x / z);
} else {
tmp = x + (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 <= (-4.2d-93)) .or. (.not. (x <= 7.2d-14))) then
tmp = x - (x / z)
else
tmp = x + (y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e-93) || !(x <= 7.2e-14)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.2e-93) or not (x <= 7.2e-14): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.2e-93) || !(x <= 7.2e-14)) tmp = Float64(x - 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 <= -4.2e-93) || ~((x <= 7.2e-14))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.2e-93], N[Not[LessEqual[x, 7.2e-14]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{-93} \lor \neg \left(x \leq 7.2 \cdot 10^{-14}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -4.2000000000000002e-93 or 7.1999999999999996e-14 < x Initial program 100.0%
Taylor expanded in y around 0 90.7%
neg-mul-190.7%
distribute-neg-frac90.7%
Simplified90.7%
Taylor expanded in x around 0 90.6%
*-commutative90.6%
distribute-lft-out--90.7%
*-rgt-identity90.7%
associate-*r/90.7%
*-rgt-identity90.7%
Simplified90.7%
if -4.2000000000000002e-93 < x < 7.1999999999999996e-14Initial program 100.0%
Taylor expanded in y around inf 92.2%
Final simplification91.3%
(FPCore (x y z) :precision binary64 (if (<= z -0.9) x (if (<= z 0.00012) (/ (- x) z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.9) {
tmp = x;
} else if (z <= 0.00012) {
tmp = -x / 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 <= (-0.9d0)) then
tmp = x
else if (z <= 0.00012d0) then
tmp = -x / z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -0.9) {
tmp = x;
} else if (z <= 0.00012) {
tmp = -x / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.9: tmp = x elif z <= 0.00012: tmp = -x / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.9) tmp = x; elseif (z <= 0.00012) tmp = Float64(Float64(-x) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.9) tmp = x; elseif (z <= 0.00012) tmp = -x / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.9], x, If[LessEqual[z, 0.00012], N[((-x) / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.9:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 0.00012:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -0.900000000000000022 or 1.20000000000000003e-4 < z Initial program 100.0%
Taylor expanded in y around 0 70.6%
neg-mul-170.6%
distribute-neg-frac70.6%
Simplified70.6%
Taylor expanded in z around inf 68.5%
if -0.900000000000000022 < z < 1.20000000000000003e-4Initial program 100.0%
Taylor expanded in y around 0 61.1%
neg-mul-161.1%
distribute-neg-frac61.1%
Simplified61.1%
Taylor expanded in z around 0 60.3%
mul-1-neg60.3%
distribute-neg-frac60.3%
Simplified60.3%
Final simplification64.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 y around 0 66.0%
neg-mul-166.0%
distribute-neg-frac66.0%
Simplified66.0%
Taylor expanded in z around inf 37.1%
Final simplification37.1%
herbie shell --seed 2023221
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))