
(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
(let* ((t_0 (/ x (- z))))
(if (<= z -1.5e+73)
x
(if (<= z -1.7e-16)
(/ y z)
(if (<= z -1.58e-211)
t_0
(if (<= z 2.4e-261)
(/ y z)
(if (<= z 1.15e-226)
t_0
(if (<= z 4.2e-149)
(/ y z)
(if (<= z 1.4e-105) t_0 (if (<= z 2.3e+47) (/ y z) x))))))))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (z <= -1.5e+73) {
tmp = x;
} else if (z <= -1.7e-16) {
tmp = y / z;
} else if (z <= -1.58e-211) {
tmp = t_0;
} else if (z <= 2.4e-261) {
tmp = y / z;
} else if (z <= 1.15e-226) {
tmp = t_0;
} else if (z <= 4.2e-149) {
tmp = y / z;
} else if (z <= 1.4e-105) {
tmp = t_0;
} else if (z <= 2.3e+47) {
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) :: t_0
real(8) :: tmp
t_0 = x / -z
if (z <= (-1.5d+73)) then
tmp = x
else if (z <= (-1.7d-16)) then
tmp = y / z
else if (z <= (-1.58d-211)) then
tmp = t_0
else if (z <= 2.4d-261) then
tmp = y / z
else if (z <= 1.15d-226) then
tmp = t_0
else if (z <= 4.2d-149) then
tmp = y / z
else if (z <= 1.4d-105) then
tmp = t_0
else if (z <= 2.3d+47) then
tmp = y / z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (z <= -1.5e+73) {
tmp = x;
} else if (z <= -1.7e-16) {
tmp = y / z;
} else if (z <= -1.58e-211) {
tmp = t_0;
} else if (z <= 2.4e-261) {
tmp = y / z;
} else if (z <= 1.15e-226) {
tmp = t_0;
} else if (z <= 4.2e-149) {
tmp = y / z;
} else if (z <= 1.4e-105) {
tmp = t_0;
} else if (z <= 2.3e+47) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if z <= -1.5e+73: tmp = x elif z <= -1.7e-16: tmp = y / z elif z <= -1.58e-211: tmp = t_0 elif z <= 2.4e-261: tmp = y / z elif z <= 1.15e-226: tmp = t_0 elif z <= 4.2e-149: tmp = y / z elif z <= 1.4e-105: tmp = t_0 elif z <= 2.3e+47: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (z <= -1.5e+73) tmp = x; elseif (z <= -1.7e-16) tmp = Float64(y / z); elseif (z <= -1.58e-211) tmp = t_0; elseif (z <= 2.4e-261) tmp = Float64(y / z); elseif (z <= 1.15e-226) tmp = t_0; elseif (z <= 4.2e-149) tmp = Float64(y / z); elseif (z <= 1.4e-105) tmp = t_0; elseif (z <= 2.3e+47) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x / -z; tmp = 0.0; if (z <= -1.5e+73) tmp = x; elseif (z <= -1.7e-16) tmp = y / z; elseif (z <= -1.58e-211) tmp = t_0; elseif (z <= 2.4e-261) tmp = y / z; elseif (z <= 1.15e-226) tmp = t_0; elseif (z <= 4.2e-149) tmp = y / z; elseif (z <= 1.4e-105) tmp = t_0; elseif (z <= 2.3e+47) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x / (-z)), $MachinePrecision]}, If[LessEqual[z, -1.5e+73], x, If[LessEqual[z, -1.7e-16], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.58e-211], t$95$0, If[LessEqual[z, 2.4e-261], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.15e-226], t$95$0, If[LessEqual[z, 4.2e-149], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.4e-105], t$95$0, If[LessEqual[z, 2.3e+47], N[(y / z), $MachinePrecision], x]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;z \leq -1.5 \cdot 10^{+73}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.7 \cdot 10^{-16}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -1.58 \cdot 10^{-211}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.4 \cdot 10^{-261}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-226}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.2 \cdot 10^{-149}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{-105}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{+47}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.50000000000000005e73 or 2.2999999999999999e47 < 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.6%
if -1.50000000000000005e73 < z < -1.7e-16 or -1.5800000000000001e-211 < z < 2.40000000000000014e-261 or 1.15e-226 < z < 4.20000000000000022e-149 or 1.4e-105 < z < 2.2999999999999999e47Initial program 99.9%
div-sub97.9%
sub-neg97.9%
distribute-frac-neg97.9%
+-commutative97.9%
associate-+r+97.9%
distribute-frac-neg97.9%
sub-neg97.9%
associate--r-97.9%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around 0 68.4%
if -1.7e-16 < z < -1.5800000000000001e-211 or 2.40000000000000014e-261 < z < 1.15e-226 or 4.20000000000000022e-149 < z < 1.4e-105Initial program 100.0%
div-sub96.4%
sub-neg96.4%
distribute-frac-neg96.4%
+-commutative96.4%
associate-+r+96.4%
distribute-frac-neg96.4%
sub-neg96.4%
associate--r-96.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 72.3%
Taylor expanded in z around 0 72.3%
mul-1-neg72.3%
distribute-neg-frac272.3%
Simplified72.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.2e-6))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.2e-6)) {
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.2d-6))) 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.2e-6)) {
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.2e-6): 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.2e-6)) 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.2e-6))) 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.2e-6]], $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.2 \cdot 10^{-6}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 1.1999999999999999e-6 < 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 99.3%
neg-mul-199.3%
distribute-neg-frac299.3%
Simplified99.3%
sub-neg99.3%
+-commutative99.3%
distribute-frac-neg299.3%
remove-double-neg99.3%
Applied egg-rr99.3%
if -1 < z < 1.1999999999999999e-6Initial program 99.9%
div-sub96.6%
sub-neg96.6%
distribute-frac-neg96.6%
+-commutative96.6%
associate-+r+96.6%
distribute-frac-neg96.6%
sub-neg96.6%
associate--r-96.6%
div-sub99.9%
Simplified99.9%
Taylor expanded in z around 0 99.4%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -6e-123) (not (<= y 7.2e-138))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6e-123) || !(y <= 7.2e-138)) {
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 <= (-6d-123)) .or. (.not. (y <= 7.2d-138))) 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 <= -6e-123) || !(y <= 7.2e-138)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6e-123) or not (y <= 7.2e-138): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6e-123) || !(y <= 7.2e-138)) 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 <= -6e-123) || ~((y <= 7.2e-138))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6e-123], N[Not[LessEqual[y, 7.2e-138]], $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 -6 \cdot 10^{-123} \lor \neg \left(y \leq 7.2 \cdot 10^{-138}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -5.99999999999999968e-123 or 7.20000000000000036e-138 < y Initial 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 90.7%
neg-mul-190.7%
distribute-neg-frac290.7%
Simplified90.7%
sub-neg90.7%
+-commutative90.7%
distribute-frac-neg290.7%
remove-double-neg90.7%
Applied egg-rr90.7%
if -5.99999999999999968e-123 < y < 7.20000000000000036e-138Initial 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 98.4%
Final simplification92.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.2e-185) (not (<= y 1.3e-143))) (+ x (/ y z)) (/ x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.2e-185) || !(y <= 1.3e-143)) {
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 ((y <= (-3.2d-185)) .or. (.not. (y <= 1.3d-143))) 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 ((y <= -3.2e-185) || !(y <= 1.3e-143)) {
tmp = x + (y / z);
} else {
tmp = x / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.2e-185) or not (y <= 1.3e-143): tmp = x + (y / z) else: tmp = x / -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.2e-185) || !(y <= 1.3e-143)) 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 ((y <= -3.2e-185) || ~((y <= 1.3e-143))) tmp = x + (y / z); else tmp = x / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.2e-185], N[Not[LessEqual[y, 1.3e-143]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{-185} \lor \neg \left(y \leq 1.3 \cdot 10^{-143}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-z}\\
\end{array}
\end{array}
if y < -3.1999999999999997e-185 or 1.29999999999999994e-143 < y Initial program 100.0%
div-sub97.9%
sub-neg97.9%
distribute-frac-neg97.9%
+-commutative97.9%
associate-+r+97.9%
distribute-frac-neg97.9%
sub-neg97.9%
associate--r-97.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 88.1%
neg-mul-188.1%
distribute-neg-frac288.1%
Simplified88.1%
sub-neg88.1%
+-commutative88.1%
distribute-frac-neg288.1%
remove-double-neg88.1%
Applied egg-rr88.1%
if -3.1999999999999997e-185 < y < 1.29999999999999994e-143Initial 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 99.5%
Taylor expanded in z around 0 62.7%
mul-1-neg62.7%
distribute-neg-frac262.7%
Simplified62.7%
Final simplification82.0%
(FPCore (x y z) :precision binary64 (if (<= z -7.2e+72) x (if (<= z 1.3e+47) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.2e+72) {
tmp = x;
} else if (z <= 1.3e+47) {
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 <= (-7.2d+72)) then
tmp = x
else if (z <= 1.3d+47) 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 <= -7.2e+72) {
tmp = x;
} else if (z <= 1.3e+47) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.2e+72: tmp = x elif z <= 1.3e+47: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.2e+72) tmp = x; elseif (z <= 1.3e+47) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.2e+72) tmp = x; elseif (z <= 1.3e+47) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.2e+72], x, If[LessEqual[z, 1.3e+47], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{+72}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{+47}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.20000000000000069e72 or 1.30000000000000002e47 < 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.6%
if -7.20000000000000069e72 < z < 1.30000000000000002e47Initial program 99.9%
div-sub97.3%
sub-neg97.3%
distribute-frac-neg97.3%
+-commutative97.3%
associate-+r+97.4%
distribute-frac-neg97.4%
sub-neg97.4%
associate--r-97.3%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around 0 54.1%
(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 35.4%
herbie shell --seed 2024084
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))