
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -2.45e+38)
x
(if (<= z -6.6e-144)
(/ y z)
(if (<= z 1.05e-222) (/ (- x) z) (if (<= z 6.1e+38) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.45e+38) {
tmp = x;
} else if (z <= -6.6e-144) {
tmp = y / z;
} else if (z <= 1.05e-222) {
tmp = -x / z;
} else if (z <= 6.1e+38) {
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 <= (-2.45d+38)) then
tmp = x
else if (z <= (-6.6d-144)) then
tmp = y / z
else if (z <= 1.05d-222) then
tmp = -x / z
else if (z <= 6.1d+38) 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 <= -2.45e+38) {
tmp = x;
} else if (z <= -6.6e-144) {
tmp = y / z;
} else if (z <= 1.05e-222) {
tmp = -x / z;
} else if (z <= 6.1e+38) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.45e+38: tmp = x elif z <= -6.6e-144: tmp = y / z elif z <= 1.05e-222: tmp = -x / z elif z <= 6.1e+38: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.45e+38) tmp = x; elseif (z <= -6.6e-144) tmp = Float64(y / z); elseif (z <= 1.05e-222) tmp = Float64(Float64(-x) / z); elseif (z <= 6.1e+38) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.45e+38) tmp = x; elseif (z <= -6.6e-144) tmp = y / z; elseif (z <= 1.05e-222) tmp = -x / z; elseif (z <= 6.1e+38) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.45e+38], x, If[LessEqual[z, -6.6e-144], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.05e-222], N[((-x) / z), $MachinePrecision], If[LessEqual[z, 6.1e+38], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.45 \cdot 10^{+38}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -6.6 \cdot 10^{-144}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{-222}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{elif}\;z \leq 6.1 \cdot 10^{+38}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.45000000000000001e38 or 6.0999999999999999e38 < z Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 76.4%
if -2.45000000000000001e38 < z < -6.5999999999999999e-144 or 1.05e-222 < z < 6.0999999999999999e38Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 65.0%
if -6.5999999999999999e-144 < z < 1.05e-222Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 72.7%
distribute-lft-out--72.7%
*-rgt-identity72.7%
associate-*r/72.9%
*-rgt-identity72.9%
Simplified72.9%
Taylor expanded in z around 0 72.9%
neg-mul-172.9%
distribute-neg-frac72.9%
Simplified72.9%
Final simplification71.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.4e-144) (not (<= z 7e-224))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.4e-144) || !(z <= 7e-224)) {
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 <= (-4.4d-144)) .or. (.not. (z <= 7d-224))) 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 <= -4.4e-144) || !(z <= 7e-224)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.4e-144) or not (z <= 7e-224): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.4e-144) || !(z <= 7e-224)) 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 <= -4.4e-144) || ~((z <= 7e-224))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.4e-144], N[Not[LessEqual[z, 7e-224]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.4 \cdot 10^{-144} \lor \neg \left(z \leq 7 \cdot 10^{-224}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if z < -4.40000000000000012e-144 or 7.00000000000000037e-224 < z Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 87.9%
neg-mul-187.9%
distribute-neg-frac87.9%
Simplified87.9%
Taylor expanded in x around 0 87.9%
+-commutative87.9%
Simplified87.9%
if -4.40000000000000012e-144 < z < 7.00000000000000037e-224Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 72.7%
distribute-lft-out--72.7%
*-rgt-identity72.7%
associate-*r/72.9%
*-rgt-identity72.9%
Simplified72.9%
Taylor expanded in z around 0 72.9%
neg-mul-172.9%
distribute-neg-frac72.9%
Simplified72.9%
Final simplification85.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.8e-123) (not (<= y 1.9e-57))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.8e-123) || !(y <= 1.9e-57)) {
tmp = x + (y / 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 ((y <= (-2.8d-123)) .or. (.not. (y <= 1.9d-57))) then
tmp = x + (y / 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 ((y <= -2.8e-123) || !(y <= 1.9e-57)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.8e-123) or not (y <= 1.9e-57): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.8e-123) || !(y <= 1.9e-57)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(x - Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.8e-123) || ~((y <= 1.9e-57))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.8e-123], N[Not[LessEqual[y, 1.9e-57]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{-123} \lor \neg \left(y \leq 1.9 \cdot 10^{-57}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.7999999999999999e-123 or 1.8999999999999999e-57 < y Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 89.2%
neg-mul-189.2%
distribute-neg-frac89.2%
Simplified89.2%
Taylor expanded in x around 0 89.2%
+-commutative89.2%
Simplified89.2%
if -2.7999999999999999e-123 < y < 1.8999999999999999e-57Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 88.6%
distribute-lft-out--88.6%
*-rgt-identity88.6%
associate-*r/88.7%
*-rgt-identity88.7%
Simplified88.7%
Final simplification89.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -3600.0) (not (<= z 2.5e-30))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3600.0) || !(z <= 2.5e-30)) {
tmp = x + (y / z);
} else {
tmp = (y - 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 <= (-3600.0d0)) .or. (.not. (z <= 2.5d-30))) then
tmp = x + (y / z)
else
tmp = (y - x) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3600.0) || !(z <= 2.5e-30)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3600.0) or not (z <= 2.5e-30): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3600.0) || !(z <= 2.5e-30)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(Float64(y - x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3600.0) || ~((z <= 2.5e-30))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3600.0], N[Not[LessEqual[z, 2.5e-30]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3600 \lor \neg \left(z \leq 2.5 \cdot 10^{-30}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -3600 or 2.49999999999999986e-30 < z Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 98.7%
neg-mul-198.7%
distribute-neg-frac98.7%
Simplified98.7%
Taylor expanded in x around 0 98.7%
+-commutative98.7%
Simplified98.7%
if -3600 < z < 2.49999999999999986e-30Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in z around 0 99.0%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= z -6.5e+32) x (if (<= z 6.1e+25) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.5e+32) {
tmp = x;
} else if (z <= 6.1e+25) {
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 <= (-6.5d+32)) then
tmp = x
else if (z <= 6.1d+25) 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 <= -6.5e+32) {
tmp = x;
} else if (z <= 6.1e+25) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.5e+32: tmp = x elif z <= 6.1e+25: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.5e+32) tmp = x; elseif (z <= 6.1e+25) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.5e+32) tmp = x; elseif (z <= 6.1e+25) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.5e+32], x, If[LessEqual[z, 6.1e+25], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{+32}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6.1 \cdot 10^{+25}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.4999999999999994e32 or 6.1000000000000003e25 < z Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 76.4%
if -6.4999999999999994e32 < z < 6.1000000000000003e25Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 55.0%
Final simplification64.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%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 39.3%
Final simplification39.3%
herbie shell --seed 2023336
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))