
(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 -330.0)
x
(if (<= z -7.2e-200)
t_0
(if (<= z 6.8e-137)
(/ y z)
(if (<= z 5.6e-42) t_0 (if (<= z 4.4e+30) (/ y z) x)))))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (z <= -330.0) {
tmp = x;
} else if (z <= -7.2e-200) {
tmp = t_0;
} else if (z <= 6.8e-137) {
tmp = y / z;
} else if (z <= 5.6e-42) {
tmp = t_0;
} else if (z <= 4.4e+30) {
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 <= (-330.0d0)) then
tmp = x
else if (z <= (-7.2d-200)) then
tmp = t_0
else if (z <= 6.8d-137) then
tmp = y / z
else if (z <= 5.6d-42) then
tmp = t_0
else if (z <= 4.4d+30) 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 <= -330.0) {
tmp = x;
} else if (z <= -7.2e-200) {
tmp = t_0;
} else if (z <= 6.8e-137) {
tmp = y / z;
} else if (z <= 5.6e-42) {
tmp = t_0;
} else if (z <= 4.4e+30) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if z <= -330.0: tmp = x elif z <= -7.2e-200: tmp = t_0 elif z <= 6.8e-137: tmp = y / z elif z <= 5.6e-42: tmp = t_0 elif z <= 4.4e+30: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (z <= -330.0) tmp = x; elseif (z <= -7.2e-200) tmp = t_0; elseif (z <= 6.8e-137) tmp = Float64(y / z); elseif (z <= 5.6e-42) tmp = t_0; elseif (z <= 4.4e+30) 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 <= -330.0) tmp = x; elseif (z <= -7.2e-200) tmp = t_0; elseif (z <= 6.8e-137) tmp = y / z; elseif (z <= 5.6e-42) tmp = t_0; elseif (z <= 4.4e+30) 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, -330.0], x, If[LessEqual[z, -7.2e-200], t$95$0, If[LessEqual[z, 6.8e-137], N[(y / z), $MachinePrecision], If[LessEqual[z, 5.6e-42], t$95$0, If[LessEqual[z, 4.4e+30], N[(y / z), $MachinePrecision], x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;z \leq -330:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -7.2 \cdot 10^{-200}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 6.8 \cdot 10^{-137}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 5.6 \cdot 10^{-42}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.4 \cdot 10^{+30}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -330 or 4.4e30 < 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.9%
if -330 < z < -7.2000000000000003e-200 or 6.80000000000000028e-137 < z < 5.59999999999999996e-42Initial 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 69.5%
Taylor expanded in z around 0 68.1%
mul-1-neg68.1%
distribute-frac-neg68.1%
Simplified68.1%
if -7.2000000000000003e-200 < z < 6.80000000000000028e-137 or 5.59999999999999996e-42 < z < 4.4e30Initial program 100.0%
div-sub96.1%
sub-neg96.1%
distribute-frac-neg96.1%
+-commutative96.1%
associate-+r+96.1%
distribute-frac-neg96.1%
sub-neg96.1%
associate--r-96.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 62.8%
Final simplification70.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (/ y z))) (t_1 (/ x (- z))))
(if (<= z -1.5e-49)
t_0
(if (<= z -4.6e-200)
t_1
(if (<= z 9.5e-135) (/ y z) (if (<= z 5.6e-42) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x + (y / z);
double t_1 = x / -z;
double tmp;
if (z <= -1.5e-49) {
tmp = t_0;
} else if (z <= -4.6e-200) {
tmp = t_1;
} else if (z <= 9.5e-135) {
tmp = y / z;
} else if (z <= 5.6e-42) {
tmp = t_1;
} else {
tmp = t_0;
}
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) :: t_1
real(8) :: tmp
t_0 = x + (y / z)
t_1 = x / -z
if (z <= (-1.5d-49)) then
tmp = t_0
else if (z <= (-4.6d-200)) then
tmp = t_1
else if (z <= 9.5d-135) then
tmp = y / z
else if (z <= 5.6d-42) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (y / z);
double t_1 = x / -z;
double tmp;
if (z <= -1.5e-49) {
tmp = t_0;
} else if (z <= -4.6e-200) {
tmp = t_1;
} else if (z <= 9.5e-135) {
tmp = y / z;
} else if (z <= 5.6e-42) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y / z) t_1 = x / -z tmp = 0 if z <= -1.5e-49: tmp = t_0 elif z <= -4.6e-200: tmp = t_1 elif z <= 9.5e-135: tmp = y / z elif z <= 5.6e-42: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y / z)) t_1 = Float64(x / Float64(-z)) tmp = 0.0 if (z <= -1.5e-49) tmp = t_0; elseif (z <= -4.6e-200) tmp = t_1; elseif (z <= 9.5e-135) tmp = Float64(y / z); elseif (z <= 5.6e-42) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (y / z); t_1 = x / -z; tmp = 0.0; if (z <= -1.5e-49) tmp = t_0; elseif (z <= -4.6e-200) tmp = t_1; elseif (z <= 9.5e-135) tmp = y / z; elseif (z <= 5.6e-42) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / (-z)), $MachinePrecision]}, If[LessEqual[z, -1.5e-49], t$95$0, If[LessEqual[z, -4.6e-200], t$95$1, If[LessEqual[z, 9.5e-135], N[(y / z), $MachinePrecision], If[LessEqual[z, 5.6e-42], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
t_1 := \frac{x}{-z}\\
\mathbf{if}\;z \leq -1.5 \cdot 10^{-49}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -4.6 \cdot 10^{-200}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 9.5 \cdot 10^{-135}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 5.6 \cdot 10^{-42}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.5e-49 or 5.59999999999999996e-42 < 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 94.8%
neg-mul-194.8%
distribute-neg-frac94.8%
Simplified94.8%
Taylor expanded in x around 0 94.8%
cancel-sign-sub-inv94.8%
metadata-eval94.8%
*-lft-identity94.8%
+-commutative94.8%
Simplified94.8%
if -1.5e-49 < z < -4.60000000000000015e-200 or 9.50000000000000007e-135 < z < 5.59999999999999996e-42Initial 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 74.9%
Taylor expanded in z around 0 74.9%
mul-1-neg74.9%
distribute-frac-neg74.9%
Simplified74.9%
if -4.60000000000000015e-200 < z < 9.50000000000000007e-135Initial program 100.0%
div-sub95.0%
sub-neg95.0%
distribute-frac-neg95.0%
+-commutative95.0%
associate-+r+95.0%
distribute-frac-neg95.0%
sub-neg95.0%
associate--r-95.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 63.1%
Final simplification83.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -330.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -330.0) || !(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 <= (-330.0d0)) .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 <= -330.0) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -330.0) 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 <= -330.0) || !(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 <= -330.0) || ~((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, -330.0], 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 -330 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -330 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 99.1%
neg-mul-199.1%
distribute-neg-frac99.1%
Simplified99.1%
Taylor expanded in x around 0 99.1%
cancel-sign-sub-inv99.1%
metadata-eval99.1%
*-lft-identity99.1%
+-commutative99.1%
Simplified99.1%
if -330 < z < 1Initial program 100.0%
div-sub97.5%
sub-neg97.5%
distribute-frac-neg97.5%
+-commutative97.5%
associate-+r+97.5%
distribute-frac-neg97.5%
sub-neg97.5%
associate--r-97.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.2%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e+21) (not (<= y 2.55e-54))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e+21) || !(y <= 2.55e-54)) {
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.5d+21)) .or. (.not. (y <= 2.55d-54))) 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.5e+21) || !(y <= 2.55e-54)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e+21) or not (y <= 2.55e-54): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e+21) || !(y <= 2.55e-54)) 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.5e+21) || ~((y <= 2.55e-54))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e+21], N[Not[LessEqual[y, 2.55e-54]], $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.5 \cdot 10^{+21} \lor \neg \left(y \leq 2.55 \cdot 10^{-54}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.5e21 or 2.55000000000000005e-54 < y Initial program 100.0%
div-sub97.7%
sub-neg97.7%
distribute-frac-neg97.7%
+-commutative97.7%
associate-+r+97.7%
distribute-frac-neg97.7%
sub-neg97.7%
associate--r-97.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 90.6%
neg-mul-190.6%
distribute-neg-frac90.6%
Simplified90.6%
Taylor expanded in x around 0 90.6%
cancel-sign-sub-inv90.6%
metadata-eval90.6%
*-lft-identity90.6%
+-commutative90.6%
Simplified90.6%
if -2.5e21 < y < 2.55000000000000005e-54Initial 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 87.1%
Final simplification88.8%
(FPCore (x y z) :precision binary64 (if (<= z -950000.0) x (if (<= z 1.85e+30) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -950000.0) {
tmp = x;
} else if (z <= 1.85e+30) {
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 <= (-950000.0d0)) then
tmp = x
else if (z <= 1.85d+30) 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 <= -950000.0) {
tmp = x;
} else if (z <= 1.85e+30) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -950000.0: tmp = x elif z <= 1.85e+30: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -950000.0) tmp = x; elseif (z <= 1.85e+30) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -950000.0) tmp = x; elseif (z <= 1.85e+30) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -950000.0], x, If[LessEqual[z, 1.85e+30], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -950000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.85 \cdot 10^{+30}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.5e5 or 1.85000000000000008e30 < 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.9%
if -9.5e5 < z < 1.85000000000000008e30Initial program 100.0%
div-sub97.7%
sub-neg97.7%
distribute-frac-neg97.7%
+-commutative97.7%
associate-+r+97.7%
distribute-frac-neg97.7%
sub-neg97.7%
associate--r-97.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 51.3%
(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.8%
sub-neg98.8%
distribute-frac-neg98.8%
+-commutative98.8%
associate-+r+98.8%
distribute-frac-neg98.8%
sub-neg98.8%
associate--r-98.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 39.1%
herbie shell --seed 2024128
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))