
(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 -8.5e+66)
x
(if (<= z -3.8e-99)
(/ y z)
(if (<= z -2.9e-239)
t_0
(if (<= z 1.5e-251)
(/ y z)
(if (<= z 1.8e-19) t_0 (if (<= z 4e+98) (/ y z) x))))))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (z <= -8.5e+66) {
tmp = x;
} else if (z <= -3.8e-99) {
tmp = y / z;
} else if (z <= -2.9e-239) {
tmp = t_0;
} else if (z <= 1.5e-251) {
tmp = y / z;
} else if (z <= 1.8e-19) {
tmp = t_0;
} else if (z <= 4e+98) {
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 <= (-8.5d+66)) then
tmp = x
else if (z <= (-3.8d-99)) then
tmp = y / z
else if (z <= (-2.9d-239)) then
tmp = t_0
else if (z <= 1.5d-251) then
tmp = y / z
else if (z <= 1.8d-19) then
tmp = t_0
else if (z <= 4d+98) 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 <= -8.5e+66) {
tmp = x;
} else if (z <= -3.8e-99) {
tmp = y / z;
} else if (z <= -2.9e-239) {
tmp = t_0;
} else if (z <= 1.5e-251) {
tmp = y / z;
} else if (z <= 1.8e-19) {
tmp = t_0;
} else if (z <= 4e+98) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if z <= -8.5e+66: tmp = x elif z <= -3.8e-99: tmp = y / z elif z <= -2.9e-239: tmp = t_0 elif z <= 1.5e-251: tmp = y / z elif z <= 1.8e-19: tmp = t_0 elif z <= 4e+98: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (z <= -8.5e+66) tmp = x; elseif (z <= -3.8e-99) tmp = Float64(y / z); elseif (z <= -2.9e-239) tmp = t_0; elseif (z <= 1.5e-251) tmp = Float64(y / z); elseif (z <= 1.8e-19) tmp = t_0; elseif (z <= 4e+98) 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 <= -8.5e+66) tmp = x; elseif (z <= -3.8e-99) tmp = y / z; elseif (z <= -2.9e-239) tmp = t_0; elseif (z <= 1.5e-251) tmp = y / z; elseif (z <= 1.8e-19) tmp = t_0; elseif (z <= 4e+98) 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, -8.5e+66], x, If[LessEqual[z, -3.8e-99], N[(y / z), $MachinePrecision], If[LessEqual[z, -2.9e-239], t$95$0, If[LessEqual[z, 1.5e-251], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.8e-19], t$95$0, If[LessEqual[z, 4e+98], N[(y / z), $MachinePrecision], x]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;z \leq -8.5 \cdot 10^{+66}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -3.8 \cdot 10^{-99}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -2.9 \cdot 10^{-239}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{-251}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{-19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4 \cdot 10^{+98}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.5000000000000004e66 or 3.99999999999999999e98 < 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.5%
if -8.5000000000000004e66 < z < -3.7999999999999997e-99 or -2.9000000000000002e-239 < z < 1.4999999999999999e-251 or 1.8000000000000001e-19 < z < 3.99999999999999999e98Initial program 100.0%
div-sub97.4%
sub-neg97.4%
distribute-frac-neg97.4%
+-commutative97.4%
associate-+r+97.4%
distribute-frac-neg97.4%
sub-neg97.4%
associate--r-97.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 69.8%
if -3.7999999999999997e-99 < z < -2.9000000000000002e-239 or 1.4999999999999999e-251 < z < 1.8000000000000001e-19Initial 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 z around 0 100.0%
Taylor expanded in y around 0 72.1%
neg-mul-172.1%
Simplified72.1%
Final simplification71.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (/ y z))) (t_1 (/ x (- z))))
(if (<= z -1.3e-106)
t_0
(if (<= z -2.5e-239)
t_1
(if (<= z 1.05e-246) (/ y z) (if (<= z 1.5e-24) 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.3e-106) {
tmp = t_0;
} else if (z <= -2.5e-239) {
tmp = t_1;
} else if (z <= 1.05e-246) {
tmp = y / z;
} else if (z <= 1.5e-24) {
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.3d-106)) then
tmp = t_0
else if (z <= (-2.5d-239)) then
tmp = t_1
else if (z <= 1.05d-246) then
tmp = y / z
else if (z <= 1.5d-24) 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.3e-106) {
tmp = t_0;
} else if (z <= -2.5e-239) {
tmp = t_1;
} else if (z <= 1.05e-246) {
tmp = y / z;
} else if (z <= 1.5e-24) {
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.3e-106: tmp = t_0 elif z <= -2.5e-239: tmp = t_1 elif z <= 1.05e-246: tmp = y / z elif z <= 1.5e-24: 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.3e-106) tmp = t_0; elseif (z <= -2.5e-239) tmp = t_1; elseif (z <= 1.05e-246) tmp = Float64(y / z); elseif (z <= 1.5e-24) 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.3e-106) tmp = t_0; elseif (z <= -2.5e-239) tmp = t_1; elseif (z <= 1.05e-246) tmp = y / z; elseif (z <= 1.5e-24) 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.3e-106], t$95$0, If[LessEqual[z, -2.5e-239], t$95$1, If[LessEqual[z, 1.05e-246], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.5e-24], 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.3 \cdot 10^{-106}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -2.5 \cdot 10^{-239}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{-246}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{-24}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.3e-106 or 1.49999999999999998e-24 < 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 92.9%
neg-mul-192.9%
Simplified92.9%
Taylor expanded in x around 0 92.9%
cancel-sign-sub-inv92.9%
metadata-eval92.9%
*-lft-identity92.9%
+-commutative92.9%
Simplified92.9%
if -1.3e-106 < z < -2.5e-239 or 1.04999999999999997e-246 < z < 1.49999999999999998e-24Initial 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 z around 0 100.0%
Taylor expanded in y around 0 72.1%
neg-mul-172.1%
Simplified72.1%
if -2.5e-239 < z < 1.04999999999999997e-246Initial program 100.0%
div-sub90.9%
sub-neg90.9%
distribute-frac-neg90.9%
+-commutative90.9%
associate-+r+90.9%
distribute-frac-neg90.9%
sub-neg90.9%
associate--r-90.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 79.8%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.4) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.4) || !(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 <= (-4.4d0)) .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 <= -4.4) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.4) 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 <= -4.4) || !(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 <= -4.4) || ~((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, -4.4], 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 -4.4 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -4.4000000000000004 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.6%
neg-mul-198.6%
Simplified98.6%
Taylor expanded in x around 0 98.6%
cancel-sign-sub-inv98.6%
metadata-eval98.6%
*-lft-identity98.6%
+-commutative98.6%
Simplified98.6%
if -4.4000000000000004 < z < 1Initial program 100.0%
div-sub97.6%
sub-neg97.6%
distribute-frac-neg97.6%
+-commutative97.6%
associate-+r+97.6%
distribute-frac-neg97.6%
sub-neg97.6%
associate--r-97.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.4%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.6e+96) (not (<= x 1.9e+44))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e+96) || !(x <= 1.9e+44)) {
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.6d+96)) .or. (.not. (x <= 1.9d+44))) 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.6e+96) || !(x <= 1.9e+44)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.6e+96) or not (x <= 1.9e+44): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.6e+96) || !(x <= 1.9e+44)) 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.6e+96) || ~((x <= 1.9e+44))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.6e+96], N[Not[LessEqual[x, 1.9e+44]], $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.6 \cdot 10^{+96} \lor \neg \left(x \leq 1.9 \cdot 10^{+44}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -2.6e96 or 1.9000000000000001e44 < x Initial program 100.0%
div-sub98.1%
sub-neg98.1%
distribute-frac-neg98.1%
+-commutative98.1%
associate-+r+98.1%
distribute-frac-neg98.1%
sub-neg98.1%
associate--r-98.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 98.2%
distribute-lft-out--98.2%
*-rgt-identity98.2%
associate-*r/98.3%
*-rgt-identity98.3%
Simplified98.3%
if -2.6e96 < x < 1.9000000000000001e44Initial program 100.0%
div-sub99.3%
sub-neg99.3%
distribute-frac-neg99.3%
+-commutative99.3%
associate-+r+99.3%
distribute-frac-neg99.3%
sub-neg99.3%
associate--r-99.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 87.3%
neg-mul-187.3%
Simplified87.3%
Taylor expanded in x around 0 87.3%
cancel-sign-sub-inv87.3%
metadata-eval87.3%
*-lft-identity87.3%
+-commutative87.3%
Simplified87.3%
Final simplification91.8%
(FPCore (x y z) :precision binary64 (if (<= z -7.6e+66) x (if (<= z 1e+98) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.6e+66) {
tmp = x;
} else if (z <= 1e+98) {
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.6d+66)) then
tmp = x
else if (z <= 1d+98) 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.6e+66) {
tmp = x;
} else if (z <= 1e+98) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.6e+66: tmp = x elif z <= 1e+98: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.6e+66) tmp = x; elseif (z <= 1e+98) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.6e+66) tmp = x; elseif (z <= 1e+98) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.6e+66], x, If[LessEqual[z, 1e+98], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.6 \cdot 10^{+66}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 10^{+98}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.6000000000000004e66 or 9.99999999999999998e97 < 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.5%
if -7.6000000000000004e66 < z < 9.99999999999999998e97Initial program 100.0%
div-sub98.0%
sub-neg98.0%
distribute-frac-neg98.0%
+-commutative98.0%
associate-+r+98.0%
distribute-frac-neg98.0%
sub-neg98.0%
associate--r-98.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.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 33.9%
herbie shell --seed 2024150
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))