
(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 -7.1e+25)
x
(if (<= z -1.04e-57)
(/ y z)
(if (<= z -4.1e-249)
t_0
(if (<= z 7.5e-170) (/ y z) (if (<= z 1.0) t_0 x)))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -7.1e+25) {
tmp = x;
} else if (z <= -1.04e-57) {
tmp = y / z;
} else if (z <= -4.1e-249) {
tmp = t_0;
} else if (z <= 7.5e-170) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = t_0;
} 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 <= (-7.1d+25)) then
tmp = x
else if (z <= (-1.04d-57)) then
tmp = y / z
else if (z <= (-4.1d-249)) then
tmp = t_0
else if (z <= 7.5d-170) then
tmp = y / z
else if (z <= 1.0d0) then
tmp = t_0
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 <= -7.1e+25) {
tmp = x;
} else if (z <= -1.04e-57) {
tmp = y / z;
} else if (z <= -4.1e-249) {
tmp = t_0;
} else if (z <= 7.5e-170) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -7.1e+25: tmp = x elif z <= -1.04e-57: tmp = y / z elif z <= -4.1e-249: tmp = t_0 elif z <= 7.5e-170: tmp = y / z elif z <= 1.0: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -7.1e+25) tmp = x; elseif (z <= -1.04e-57) tmp = Float64(y / z); elseif (z <= -4.1e-249) tmp = t_0; elseif (z <= 7.5e-170) tmp = Float64(y / z); elseif (z <= 1.0) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x / z; tmp = 0.0; if (z <= -7.1e+25) tmp = x; elseif (z <= -1.04e-57) tmp = y / z; elseif (z <= -4.1e-249) tmp = t_0; elseif (z <= 7.5e-170) tmp = y / z; elseif (z <= 1.0) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -7.1e+25], x, If[LessEqual[z, -1.04e-57], N[(y / z), $MachinePrecision], If[LessEqual[z, -4.1e-249], t$95$0, If[LessEqual[z, 7.5e-170], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.0], t$95$0, x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -7.1 \cdot 10^{+25}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.04 \cdot 10^{-57}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -4.1 \cdot 10^{-249}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.5 \cdot 10^{-170}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.1000000000000001e25 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 z around inf 73.9%
if -7.1000000000000001e25 < z < -1.04000000000000003e-57 or -4.10000000000000004e-249 < z < 7.4999999999999998e-170Initial 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 72.2%
if -1.04000000000000003e-57 < z < -4.10000000000000004e-249 or 7.4999999999999998e-170 < z < 1Initial 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 inf 65.0%
distribute-lft-out--65.0%
*-rgt-identity65.0%
associate-*r/65.2%
*-rgt-identity65.2%
Simplified65.2%
Taylor expanded in z around 0 64.8%
mul-1-neg64.8%
distribute-frac-neg64.8%
Simplified64.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (/ y z))) (t_1 (/ (- x) z)))
(if (<= z -5.2e-59)
t_0
(if (<= z -1.15e-248)
t_1
(if (<= z 3.8e-170) (/ y z) (if (<= z 3.6e-16) 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 <= -5.2e-59) {
tmp = t_0;
} else if (z <= -1.15e-248) {
tmp = t_1;
} else if (z <= 3.8e-170) {
tmp = y / z;
} else if (z <= 3.6e-16) {
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 <= (-5.2d-59)) then
tmp = t_0
else if (z <= (-1.15d-248)) then
tmp = t_1
else if (z <= 3.8d-170) then
tmp = y / z
else if (z <= 3.6d-16) 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 <= -5.2e-59) {
tmp = t_0;
} else if (z <= -1.15e-248) {
tmp = t_1;
} else if (z <= 3.8e-170) {
tmp = y / z;
} else if (z <= 3.6e-16) {
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 <= -5.2e-59: tmp = t_0 elif z <= -1.15e-248: tmp = t_1 elif z <= 3.8e-170: tmp = y / z elif z <= 3.6e-16: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y / z)) t_1 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -5.2e-59) tmp = t_0; elseif (z <= -1.15e-248) tmp = t_1; elseif (z <= 3.8e-170) tmp = Float64(y / z); elseif (z <= 3.6e-16) 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 <= -5.2e-59) tmp = t_0; elseif (z <= -1.15e-248) tmp = t_1; elseif (z <= 3.8e-170) tmp = y / z; elseif (z <= 3.6e-16) 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, -5.2e-59], t$95$0, If[LessEqual[z, -1.15e-248], t$95$1, If[LessEqual[z, 3.8e-170], N[(y / z), $MachinePrecision], If[LessEqual[z, 3.6e-16], 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 -5.2 \cdot 10^{-59}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.15 \cdot 10^{-248}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-170}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{-16}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.19999999999999996e-59 or 3.59999999999999983e-16 < 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.4%
neg-mul-194.4%
Simplified94.4%
Taylor expanded in x around 0 94.4%
cancel-sign-sub-inv94.4%
metadata-eval94.4%
*-lft-identity94.4%
+-commutative94.4%
Simplified94.4%
if -5.19999999999999996e-59 < z < -1.15e-248 or 3.7999999999999998e-170 < z < 3.59999999999999983e-16Initial program 100.0%
div-sub98.6%
sub-neg98.6%
distribute-frac-neg98.6%
+-commutative98.6%
associate-+r+98.6%
distribute-frac-neg98.6%
sub-neg98.6%
associate--r-98.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 66.7%
distribute-lft-out--66.7%
*-rgt-identity66.7%
associate-*r/66.9%
*-rgt-identity66.9%
Simplified66.9%
Taylor expanded in z around 0 66.9%
mul-1-neg66.9%
distribute-frac-neg66.9%
Simplified66.9%
if -1.15e-248 < z < 3.7999999999999998e-170Initial program 100.0%
div-sub92.1%
sub-neg92.1%
distribute-frac-neg92.1%
+-commutative92.1%
associate-+r+92.1%
distribute-frac-neg92.1%
sub-neg92.1%
associate--r-92.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 77.6%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.8e+25) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.8e+25) || !(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 <= (-6.8d+25)) .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 <= -6.8e+25) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.8e+25) 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 <= -6.8e+25) || !(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 <= -6.8e+25) || ~((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, -6.8e+25], 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 -6.8 \cdot 10^{+25} \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -6.79999999999999967e25 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.8%
neg-mul-199.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
cancel-sign-sub-inv99.8%
metadata-eval99.8%
*-lft-identity99.8%
+-commutative99.8%
Simplified99.8%
if -6.79999999999999967e25 < z < 1Initial program 100.0%
div-sub96.9%
sub-neg96.9%
distribute-frac-neg96.9%
+-commutative96.9%
associate-+r+96.9%
distribute-frac-neg96.9%
sub-neg96.9%
associate--r-96.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.3%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.2e-38) (not (<= y 2.7e-68))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.2e-38) || !(y <= 2.7e-68)) {
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 <= (-1.2d-38)) .or. (.not. (y <= 2.7d-68))) 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 <= -1.2e-38) || !(y <= 2.7e-68)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.2e-38) or not (y <= 2.7e-68): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.2e-38) || !(y <= 2.7e-68)) 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 <= -1.2e-38) || ~((y <= 2.7e-68))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.2e-38], N[Not[LessEqual[y, 2.7e-68]], $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 -1.2 \cdot 10^{-38} \lor \neg \left(y \leq 2.7 \cdot 10^{-68}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.20000000000000011e-38 or 2.7000000000000002e-68 < y Initial 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 92.2%
neg-mul-192.2%
Simplified92.2%
Taylor expanded in x around 0 92.2%
cancel-sign-sub-inv92.2%
metadata-eval92.2%
*-lft-identity92.2%
+-commutative92.2%
Simplified92.2%
if -1.20000000000000011e-38 < y < 2.7000000000000002e-68Initial 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 90.5%
distribute-lft-out--90.5%
*-rgt-identity90.5%
associate-*r/90.7%
*-rgt-identity90.7%
Simplified90.7%
Final simplification91.5%
(FPCore (x y z) :precision binary64 (if (<= z -7.8e+25) x (if (<= z 8.6e+18) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.8e+25) {
tmp = x;
} else if (z <= 8.6e+18) {
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.8d+25)) then
tmp = x
else if (z <= 8.6d+18) 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.8e+25) {
tmp = x;
} else if (z <= 8.6e+18) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.8e+25: tmp = x elif z <= 8.6e+18: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.8e+25) tmp = x; elseif (z <= 8.6e+18) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.8e+25) tmp = x; elseif (z <= 8.6e+18) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.8e+25], x, If[LessEqual[z, 8.6e+18], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.8 \cdot 10^{+25}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 8.6 \cdot 10^{+18}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.8000000000000004e25 or 8.6e18 < 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 74.3%
if -7.8000000000000004e25 < z < 8.6e18Initial program 100.0%
div-sub97.0%
sub-neg97.0%
distribute-frac-neg97.0%
+-commutative97.0%
associate-+r+97.0%
distribute-frac-neg97.0%
sub-neg97.0%
associate--r-97.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 52.6%
(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 38.0%
herbie shell --seed 2024139
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))