
(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.1e+30)
x
(if (<= z -6e-73)
(/ y z)
(if (<= z -2.25e-113) (/ x (- z)) (if (<= z 2.4e+58) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.1e+30) {
tmp = x;
} else if (z <= -6e-73) {
tmp = y / z;
} else if (z <= -2.25e-113) {
tmp = x / -z;
} else if (z <= 2.4e+58) {
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.1d+30)) then
tmp = x
else if (z <= (-6d-73)) then
tmp = y / z
else if (z <= (-2.25d-113)) then
tmp = x / -z
else if (z <= 2.4d+58) 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.1e+30) {
tmp = x;
} else if (z <= -6e-73) {
tmp = y / z;
} else if (z <= -2.25e-113) {
tmp = x / -z;
} else if (z <= 2.4e+58) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.1e+30: tmp = x elif z <= -6e-73: tmp = y / z elif z <= -2.25e-113: tmp = x / -z elif z <= 2.4e+58: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.1e+30) tmp = x; elseif (z <= -6e-73) tmp = Float64(y / z); elseif (z <= -2.25e-113) tmp = Float64(x / Float64(-z)); elseif (z <= 2.4e+58) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.1e+30) tmp = x; elseif (z <= -6e-73) tmp = y / z; elseif (z <= -2.25e-113) tmp = x / -z; elseif (z <= 2.4e+58) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.1e+30], x, If[LessEqual[z, -6e-73], N[(y / z), $MachinePrecision], If[LessEqual[z, -2.25e-113], N[(x / (-z)), $MachinePrecision], If[LessEqual[z, 2.4e+58], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \cdot 10^{+30}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -6 \cdot 10^{-73}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -2.25 \cdot 10^{-113}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{elif}\;z \leq 2.4 \cdot 10^{+58}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.1e30 or 2.4e58 < 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 75.8%
if -2.1e30 < z < -6e-73 or -2.2500000000000001e-113 < z < 2.4e58Initial program 100.0%
div-sub97.1%
sub-neg97.1%
distribute-frac-neg97.1%
+-commutative97.1%
associate-+r+97.1%
distribute-frac-neg97.1%
sub-neg97.1%
associate--r-97.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 59.4%
if -6e-73 < z < -2.2500000000000001e-113Initial 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 100.0%
Taylor expanded in z around 0 100.0%
mul-1-neg100.0%
distribute-frac-neg2100.0%
Simplified100.0%
Final simplification67.5%
(FPCore (x y z) :precision binary64 (if (or (<= x 2.1e+77) (not (<= x 1.2e+191))) (+ x (/ y z)) (/ x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= 2.1e+77) || !(x <= 1.2e+191)) {
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 ((x <= 2.1d+77) .or. (.not. (x <= 1.2d+191))) 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 ((x <= 2.1e+77) || !(x <= 1.2e+191)) {
tmp = x + (y / z);
} else {
tmp = x / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= 2.1e+77) or not (x <= 1.2e+191): tmp = x + (y / z) else: tmp = x / -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= 2.1e+77) || !(x <= 1.2e+191)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(x / Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= 2.1e+77) || ~((x <= 1.2e+191))) tmp = x + (y / z); else tmp = x / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, 2.1e+77], N[Not[LessEqual[x, 1.2e+191]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.1 \cdot 10^{+77} \lor \neg \left(x \leq 1.2 \cdot 10^{+191}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-z}\\
\end{array}
\end{array}
if x < 2.0999999999999999e77 or 1.19999999999999993e191 < x Initial program 100.0%
div-sub98.7%
sub-neg98.7%
distribute-frac-neg98.7%
+-commutative98.7%
associate-+r+98.7%
distribute-frac-neg98.7%
sub-neg98.7%
associate--r-98.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 82.6%
neg-mul-182.6%
distribute-neg-frac82.6%
Simplified82.6%
sub-neg82.6%
distribute-frac-neg82.6%
remove-double-neg82.6%
+-commutative82.6%
Applied egg-rr82.6%
if 2.0999999999999999e77 < x < 1.19999999999999993e191Initial program 100.0%
div-sub96.2%
sub-neg96.2%
distribute-frac-neg96.2%
+-commutative96.2%
associate-+r+96.2%
distribute-frac-neg96.2%
sub-neg96.2%
associate--r-96.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 92.5%
Taylor expanded in z around 0 65.0%
mul-1-neg65.0%
distribute-frac-neg265.0%
Simplified65.0%
Final simplification80.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.15e+92) (not (<= x 1.1e+75))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.15e+92) || !(x <= 1.1e+75)) {
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 <= (-2.15d+92)) .or. (.not. (x <= 1.1d+75))) 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 <= -2.15e+92) || !(x <= 1.1e+75)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.15e+92) or not (x <= 1.1e+75): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.15e+92) || !(x <= 1.1e+75)) 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 <= -2.15e+92) || ~((x <= 1.1e+75))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.15e+92], N[Not[LessEqual[x, 1.1e+75]], $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 -2.15 \cdot 10^{+92} \lor \neg \left(x \leq 1.1 \cdot 10^{+75}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -2.1499999999999999e92 or 1.10000000000000006e75 < x Initial program 100.0%
div-sub95.7%
sub-neg95.7%
distribute-frac-neg95.7%
+-commutative95.7%
associate-+r+95.7%
distribute-frac-neg95.7%
sub-neg95.7%
associate--r-95.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 91.6%
if -2.1499999999999999e92 < x < 1.10000000000000006e75Initial 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 90.7%
neg-mul-190.7%
distribute-neg-frac90.7%
Simplified90.7%
sub-neg90.7%
distribute-frac-neg90.7%
remove-double-neg90.7%
+-commutative90.7%
Applied egg-rr90.7%
Final simplification91.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.7) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.7) || !(z <= 1.0)) {
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 <= (-3.7d0)) .or. (.not. (z <= 1.0d0))) 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 <= -3.7) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.7) or not (z <= 1.0): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.7) || !(z <= 1.0)) 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 <= -3.7) || ~((z <= 1.0))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.7], N[Not[LessEqual[z, 1.0]], $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 -3.7 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -3.7000000000000002 or 1 < 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.2%
neg-mul-198.2%
distribute-neg-frac98.2%
Simplified98.2%
sub-neg98.2%
distribute-frac-neg98.2%
remove-double-neg98.2%
+-commutative98.2%
Applied egg-rr98.2%
if -3.7000000000000002 < z < 1Initial program 100.0%
div-sub96.8%
sub-neg96.8%
distribute-frac-neg96.8%
+-commutative96.8%
associate-+r+96.8%
distribute-frac-neg96.8%
sub-neg96.8%
associate--r-96.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.2%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.7e+32) x (if (<= z 5e+53) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.7e+32) {
tmp = x;
} else if (z <= 5e+53) {
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.7d+32)) then
tmp = x
else if (z <= 5d+53) 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.7e+32) {
tmp = x;
} else if (z <= 5e+53) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.7e+32: tmp = x elif z <= 5e+53: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.7e+32) tmp = x; elseif (z <= 5e+53) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.7e+32) tmp = x; elseif (z <= 5e+53) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.7e+32], x, If[LessEqual[z, 5e+53], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+32}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5 \cdot 10^{+53}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.69999999999999989e32 or 5.0000000000000004e53 < 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 75.8%
if -1.69999999999999989e32 < z < 5.0000000000000004e53Initial program 100.0%
div-sub97.2%
sub-neg97.2%
distribute-frac-neg97.2%
+-commutative97.2%
associate-+r+97.2%
distribute-frac-neg97.2%
sub-neg97.2%
associate--r-97.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 57.0%
Final simplification65.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%
div-sub98.4%
sub-neg98.4%
distribute-frac-neg98.4%
+-commutative98.4%
associate-+r+98.4%
distribute-frac-neg98.4%
sub-neg98.4%
associate--r-98.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 36.2%
Final simplification36.2%
herbie shell --seed 2024095
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))