
(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 (<= z -1.0) x (if (<= z 2.65e-118) (/ x (- z)) (if (<= z 1750000000000.0) (/ y z) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x;
} else if (z <= 2.65e-118) {
tmp = x / -z;
} else if (z <= 1750000000000.0) {
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 <= (-1.0d0)) then
tmp = x
else if (z <= 2.65d-118) then
tmp = x / -z
else if (z <= 1750000000000.0d0) 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 <= -1.0) {
tmp = x;
} else if (z <= 2.65e-118) {
tmp = x / -z;
} else if (z <= 1750000000000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x elif z <= 2.65e-118: tmp = x / -z elif z <= 1750000000000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = x; elseif (z <= 2.65e-118) tmp = Float64(x / Float64(-z)); elseif (z <= 1750000000000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = x; elseif (z <= 2.65e-118) tmp = x / -z; elseif (z <= 1750000000000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], x, If[LessEqual[z, 2.65e-118], N[(x / (-z)), $MachinePrecision], If[LessEqual[z, 1750000000000.0], N[(y / z), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.65 \cdot 10^{-118}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{elif}\;z \leq 1750000000000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 1.75e12 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 72.7%
if -1 < z < 2.65000000000000019e-118Initial program 100.0%
div-sub94.2%
sub-neg94.2%
distribute-frac-neg94.2%
+-commutative94.2%
associate-+r+94.2%
distribute-frac-neg94.2%
sub-neg94.2%
associate--r-94.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 56.2%
distribute-lft-out--56.2%
*-rgt-identity56.2%
associate-*r/56.3%
*-rgt-identity56.3%
Simplified56.3%
Taylor expanded in z around 0 55.7%
mul-1-neg55.7%
distribute-frac-neg55.7%
Simplified55.7%
if 2.65000000000000019e-118 < z < 1.75e12Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 58.1%
Final simplification63.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.8e-15))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.8e-15)) {
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 <= (-1.0d0)) .or. (.not. (z <= 1.8d-15))) 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 <= -1.0) || !(z <= 1.8e-15)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.8e-15): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.8e-15)) 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 <= -1.0) || ~((z <= 1.8e-15))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.8e-15]], $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 -1 \lor \neg \left(z \leq 1.8 \cdot 10^{-15}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 1.8000000000000001e-15 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 98.3%
neg-mul-198.3%
Simplified98.3%
Taylor expanded in x around 0 98.3%
cancel-sign-sub-inv98.3%
metadata-eval98.3%
*-lft-identity98.3%
+-commutative98.3%
Simplified98.3%
if -1 < z < 1.8000000000000001e-15Initial program 100.0%
div-sub94.9%
sub-neg94.9%
distribute-frac-neg94.9%
+-commutative94.9%
associate-+r+94.9%
distribute-frac-neg94.9%
sub-neg94.9%
associate--r-94.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.5%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.9e+31) (not (<= y 440000.0))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.9e+31) || !(y <= 440000.0)) {
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.9d+31)) .or. (.not. (y <= 440000.0d0))) 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.9e+31) || !(y <= 440000.0)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.9e+31) or not (y <= 440000.0): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.9e+31) || !(y <= 440000.0)) 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.9e+31) || ~((y <= 440000.0))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.9e+31], N[Not[LessEqual[y, 440000.0]], $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.9 \cdot 10^{+31} \lor \neg \left(y \leq 440000\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.9e31 or 4.4e5 < y Initial program 100.0%
div-sub94.5%
sub-neg94.5%
distribute-frac-neg94.5%
+-commutative94.5%
associate-+r+94.5%
distribute-frac-neg94.5%
sub-neg94.5%
associate--r-94.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 86.7%
neg-mul-186.7%
Simplified86.7%
Taylor expanded in x around 0 86.7%
cancel-sign-sub-inv86.7%
metadata-eval86.7%
*-lft-identity86.7%
+-commutative86.7%
Simplified86.7%
if -2.9e31 < y < 4.4e5Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.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 simplification87.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.8e+257) (not (<= x 1.15e+237))) (/ x (- z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.8e+257) || !(x <= 1.15e+237)) {
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 <= (-6.8d+257)) .or. (.not. (x <= 1.15d+237))) 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 <= -6.8e+257) || !(x <= 1.15e+237)) {
tmp = x / -z;
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.8e+257) or not (x <= 1.15e+237): tmp = x / -z else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.8e+257) || !(x <= 1.15e+237)) tmp = Float64(x / Float64(-z)); else tmp = Float64(x + Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.8e+257) || ~((x <= 1.15e+237))) tmp = x / -z; else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.8e+257], N[Not[LessEqual[x, 1.15e+237]], $MachinePrecision]], N[(x / (-z)), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{+257} \lor \neg \left(x \leq 1.15 \cdot 10^{+237}\right):\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -6.8000000000000005e257 or 1.14999999999999998e237 < x Initial program 100.0%
div-sub92.6%
sub-neg92.6%
distribute-frac-neg92.6%
+-commutative92.6%
associate-+r+92.6%
distribute-frac-neg92.6%
sub-neg92.6%
associate--r-92.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 96.3%
distribute-lft-out--96.3%
*-rgt-identity96.3%
associate-*r/96.3%
*-rgt-identity96.3%
Simplified96.3%
Taylor expanded in z around 0 73.3%
mul-1-neg73.3%
distribute-frac-neg73.3%
Simplified73.3%
if -6.8000000000000005e257 < x < 1.14999999999999998e237Initial program 100.0%
div-sub97.8%
sub-neg97.8%
distribute-frac-neg97.8%
+-commutative97.8%
associate-+r+97.8%
distribute-frac-neg97.8%
sub-neg97.8%
associate--r-97.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 77.6%
neg-mul-177.6%
Simplified77.6%
Taylor expanded in x around 0 77.6%
cancel-sign-sub-inv77.6%
metadata-eval77.6%
*-lft-identity77.6%
+-commutative77.6%
Simplified77.6%
Final simplification77.2%
(FPCore (x y z) :precision binary64 (if (<= z -1.16e+20) x (if (<= z 1600000000000.0) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.16e+20) {
tmp = x;
} else if (z <= 1600000000000.0) {
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 <= (-1.16d+20)) then
tmp = x
else if (z <= 1600000000000.0d0) 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 <= -1.16e+20) {
tmp = x;
} else if (z <= 1600000000000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.16e+20: tmp = x elif z <= 1600000000000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.16e+20) tmp = x; elseif (z <= 1600000000000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.16e+20) tmp = x; elseif (z <= 1600000000000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.16e+20], x, If[LessEqual[z, 1600000000000.0], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.16 \cdot 10^{+20}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1600000000000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.16e20 or 1.6e12 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 73.7%
if -1.16e20 < z < 1.6e12Initial program 100.0%
div-sub95.1%
sub-neg95.1%
distribute-frac-neg95.1%
+-commutative95.1%
associate-+r+95.1%
distribute-frac-neg95.1%
sub-neg95.1%
associate--r-95.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 49.9%
(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%
div-sub97.3%
sub-neg97.3%
distribute-frac-neg97.3%
+-commutative97.3%
associate-+r+97.3%
distribute-frac-neg97.3%
sub-neg97.3%
associate--r-97.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 34.6%
herbie shell --seed 2024170
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))