
(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 (<= x -4.5e-65) (not (<= x 1.75e-10))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-65) || !(x <= 1.75e-10)) {
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.5d-65)) .or. (.not. (x <= 1.75d-10))) 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.5e-65) || !(x <= 1.75e-10)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.5e-65) or not (x <= 1.75e-10): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.5e-65) || !(x <= 1.75e-10)) 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.5e-65) || ~((x <= 1.75e-10))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.5e-65], N[Not[LessEqual[x, 1.75e-10]], $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.5 \cdot 10^{-65} \lor \neg \left(x \leq 1.75 \cdot 10^{-10}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -4.4999999999999998e-65 or 1.7499999999999999e-10 < x Initial program 100.0%
Taylor expanded in y around 0 91.2%
metadata-eval91.2%
times-frac91.2%
*-lft-identity91.2%
neg-mul-191.2%
Simplified91.2%
Taylor expanded in x around 0 91.1%
sub-neg91.1%
distribute-neg-frac91.1%
metadata-eval91.1%
distribute-lft-in91.2%
*-rgt-identity91.2%
associate-*r/91.2%
*-commutative91.2%
associate-*r/91.2%
mul-1-neg91.2%
sub-neg91.2%
Simplified91.2%
if -4.4999999999999998e-65 < x < 1.7499999999999999e-10Initial program 100.0%
Taylor expanded in y around inf 91.4%
Final simplification91.3%
(FPCore (x y z) :precision binary64 (if (<= z -11200.0) x (if (<= z 7.2) (/ (- x) z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -11200.0) {
tmp = x;
} else if (z <= 7.2) {
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 <= (-11200.0d0)) then
tmp = x
else if (z <= 7.2d0) 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 <= -11200.0) {
tmp = x;
} else if (z <= 7.2) {
tmp = -x / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -11200.0: tmp = x elif z <= 7.2: tmp = -x / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -11200.0) tmp = x; elseif (z <= 7.2) tmp = Float64(Float64(-x) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -11200.0) tmp = x; elseif (z <= 7.2) tmp = -x / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -11200.0], x, If[LessEqual[z, 7.2], N[((-x) / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -11200:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7.2:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -11200 or 7.20000000000000018 < z Initial program 100.0%
Taylor expanded in y around 0 73.8%
metadata-eval73.8%
times-frac73.8%
*-lft-identity73.8%
neg-mul-173.8%
Simplified73.8%
Taylor expanded in z around inf 71.8%
if -11200 < z < 7.20000000000000018Initial program 100.0%
Taylor expanded in y around 0 56.6%
metadata-eval56.6%
times-frac56.6%
*-lft-identity56.6%
neg-mul-156.6%
Simplified56.6%
Taylor expanded in x around 0 56.5%
sub-neg56.5%
distribute-neg-frac56.5%
metadata-eval56.5%
distribute-lft-in56.5%
*-rgt-identity56.5%
associate-*r/56.6%
*-commutative56.6%
associate-*r/56.6%
mul-1-neg56.6%
sub-neg56.6%
Simplified56.6%
Taylor expanded in z around 0 56.0%
associate-*r/56.0%
neg-mul-156.0%
Simplified56.0%
Final simplification64.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.35e+198) (/ (- x) z) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.35e+198) {
tmp = -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 <= (-1.35d+198)) then
tmp = -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 <= -1.35e+198) {
tmp = -x / z;
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.35e+198: tmp = -x / z else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.35e+198) 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 <= -1.35e+198) tmp = -x / z; else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.35e+198], N[((-x) / z), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{+198}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.35e198Initial program 100.0%
Taylor expanded in y around 0 99.9%
metadata-eval99.9%
times-frac99.9%
*-lft-identity99.9%
neg-mul-199.9%
Simplified99.9%
Taylor expanded in x around 0 99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
distribute-lft-in99.8%
*-rgt-identity99.8%
associate-*r/99.9%
*-commutative99.9%
associate-*r/99.9%
mul-1-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in z around 0 63.6%
associate-*r/63.6%
neg-mul-163.6%
Simplified63.6%
if -1.35e198 < x Initial program 100.0%
Taylor expanded in y around inf 79.4%
Final simplification78.0%
(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 65.5%
metadata-eval65.5%
times-frac65.5%
*-lft-identity65.5%
neg-mul-165.5%
Simplified65.5%
Taylor expanded in z around inf 38.4%
Final simplification38.4%
herbie shell --seed 2023297
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))