
(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 -8.2e+132)
x
(if (<= z -1.6e-141)
(/ y z)
(if (<= z -2.1e-210)
(/ (- x) z)
(if (or (<= z 3.2e+54) (and (not (<= z 1.9e+142)) (<= z 6.6e+168)))
(/ y z)
x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.2e+132) {
tmp = x;
} else if (z <= -1.6e-141) {
tmp = y / z;
} else if (z <= -2.1e-210) {
tmp = -x / z;
} else if ((z <= 3.2e+54) || (!(z <= 1.9e+142) && (z <= 6.6e+168))) {
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 <= (-8.2d+132)) then
tmp = x
else if (z <= (-1.6d-141)) then
tmp = y / z
else if (z <= (-2.1d-210)) then
tmp = -x / z
else if ((z <= 3.2d+54) .or. (.not. (z <= 1.9d+142)) .and. (z <= 6.6d+168)) 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 <= -8.2e+132) {
tmp = x;
} else if (z <= -1.6e-141) {
tmp = y / z;
} else if (z <= -2.1e-210) {
tmp = -x / z;
} else if ((z <= 3.2e+54) || (!(z <= 1.9e+142) && (z <= 6.6e+168))) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.2e+132: tmp = x elif z <= -1.6e-141: tmp = y / z elif z <= -2.1e-210: tmp = -x / z elif (z <= 3.2e+54) or (not (z <= 1.9e+142) and (z <= 6.6e+168)): tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.2e+132) tmp = x; elseif (z <= -1.6e-141) tmp = Float64(y / z); elseif (z <= -2.1e-210) tmp = Float64(Float64(-x) / z); elseif ((z <= 3.2e+54) || (!(z <= 1.9e+142) && (z <= 6.6e+168))) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.2e+132) tmp = x; elseif (z <= -1.6e-141) tmp = y / z; elseif (z <= -2.1e-210) tmp = -x / z; elseif ((z <= 3.2e+54) || (~((z <= 1.9e+142)) && (z <= 6.6e+168))) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.2e+132], x, If[LessEqual[z, -1.6e-141], N[(y / z), $MachinePrecision], If[LessEqual[z, -2.1e-210], N[((-x) / z), $MachinePrecision], If[Or[LessEqual[z, 3.2e+54], And[N[Not[LessEqual[z, 1.9e+142]], $MachinePrecision], LessEqual[z, 6.6e+168]]], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.2 \cdot 10^{+132}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.6 \cdot 10^{-141}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -2.1 \cdot 10^{-210}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{elif}\;z \leq 3.2 \cdot 10^{+54} \lor \neg \left(z \leq 1.9 \cdot 10^{+142}\right) \land z \leq 6.6 \cdot 10^{+168}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.19999999999999983e132 or 3.2e54 < z < 1.89999999999999995e142 or 6.5999999999999997e168 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 84.3%
if -8.19999999999999983e132 < z < -1.6000000000000001e-141 or -2.10000000000000016e-210 < z < 3.2e54 or 1.89999999999999995e142 < z < 6.5999999999999997e168Initial program 99.9%
div-sub96.1%
associate-+r-96.1%
remove-double-neg96.1%
distribute-frac-neg96.1%
unsub-neg96.1%
associate--r+96.1%
+-commutative96.1%
distribute-frac-neg96.1%
sub-neg96.1%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around 0 59.2%
if -1.6000000000000001e-141 < z < -2.10000000000000016e-210Initial program 99.9%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around inf 83.9%
distribute-lft-out--83.9%
*-rgt-identity83.9%
associate-*r/83.9%
*-rgt-identity83.9%
Simplified83.9%
Taylor expanded in z around 0 83.9%
mul-1-neg83.9%
Simplified83.9%
Final simplification69.0%
(FPCore (x y z)
:precision binary64
(if (<= z -1.38e+138)
x
(if (or (<= z 3.5e+54) (and (not (<= z 1.9e+142)) (<= z 4.5e+168)))
(/ y z)
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.38e+138) {
tmp = x;
} else if ((z <= 3.5e+54) || (!(z <= 1.9e+142) && (z <= 4.5e+168))) {
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.38d+138)) then
tmp = x
else if ((z <= 3.5d+54) .or. (.not. (z <= 1.9d+142)) .and. (z <= 4.5d+168)) 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.38e+138) {
tmp = x;
} else if ((z <= 3.5e+54) || (!(z <= 1.9e+142) && (z <= 4.5e+168))) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.38e+138: tmp = x elif (z <= 3.5e+54) or (not (z <= 1.9e+142) and (z <= 4.5e+168)): tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.38e+138) tmp = x; elseif ((z <= 3.5e+54) || (!(z <= 1.9e+142) && (z <= 4.5e+168))) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.38e+138) tmp = x; elseif ((z <= 3.5e+54) || (~((z <= 1.9e+142)) && (z <= 4.5e+168))) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.38e+138], x, If[Or[LessEqual[z, 3.5e+54], And[N[Not[LessEqual[z, 1.9e+142]], $MachinePrecision], LessEqual[z, 4.5e+168]]], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.38 \cdot 10^{+138}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+54} \lor \neg \left(z \leq 1.9 \cdot 10^{+142}\right) \land z \leq 4.5 \cdot 10^{+168}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.38000000000000008e138 or 3.5000000000000001e54 < z < 1.89999999999999995e142 or 4.50000000000000012e168 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 84.3%
if -1.38000000000000008e138 < z < 3.5000000000000001e54 or 1.89999999999999995e142 < z < 4.50000000000000012e168Initial program 99.9%
div-sub96.4%
associate-+r-96.4%
remove-double-neg96.4%
distribute-frac-neg96.4%
unsub-neg96.4%
associate--r+96.4%
+-commutative96.4%
distribute-frac-neg96.4%
sub-neg96.4%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around 0 55.8%
Final simplification65.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.6e-45) (not (<= y 5.8e-68))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.6e-45) || !(y <= 5.8e-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.6d-45)) .or. (.not. (y <= 5.8d-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.6e-45) || !(y <= 5.8e-68)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.6e-45) or not (y <= 5.8e-68): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.6e-45) || !(y <= 5.8e-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.6e-45) || ~((y <= 5.8e-68))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.6e-45], N[Not[LessEqual[y, 5.8e-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.6 \cdot 10^{-45} \lor \neg \left(y \leq 5.8 \cdot 10^{-68}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.60000000000000004e-45 or 5.8000000000000001e-68 < y Initial program 99.9%
div-sub96.2%
associate-+r-96.2%
remove-double-neg96.2%
distribute-frac-neg96.2%
unsub-neg96.2%
associate--r+96.2%
+-commutative96.2%
distribute-frac-neg96.2%
sub-neg96.2%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around 0 88.1%
neg-mul-188.1%
distribute-neg-frac88.1%
Simplified88.1%
div-inv87.9%
cancel-sign-sub87.9%
div-inv88.1%
+-commutative88.1%
Applied egg-rr88.1%
if -1.60000000000000004e-45 < y < 5.8000000000000001e-68Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 90.3%
distribute-lft-out--90.3%
*-rgt-identity90.3%
associate-*r/90.4%
*-rgt-identity90.4%
Simplified90.4%
Final simplification89.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.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 <= (-1.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 <= -1.0) || !(z <= 1.0)) {
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.0): 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.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 <= -1.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, -1.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 -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 98.0%
neg-mul-198.0%
distribute-neg-frac98.0%
Simplified98.0%
div-inv97.9%
cancel-sign-sub97.9%
div-inv98.0%
+-commutative98.0%
Applied egg-rr98.0%
if -1 < z < 1Initial program 99.9%
div-sub95.1%
associate-+r-95.1%
remove-double-neg95.1%
distribute-frac-neg95.1%
unsub-neg95.1%
associate--r+95.1%
+-commutative95.1%
distribute-frac-neg95.1%
sub-neg95.1%
div-sub99.9%
Simplified99.9%
Taylor expanded in z around 0 98.9%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (+ x (/ y z)))
double code(double x, double y, double z) {
return x + (y / 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 / z)
end function
public static double code(double x, double y, double z) {
return x + (y / z);
}
def code(x, y, z): return x + (y / z)
function code(x, y, z) return Float64(x + Float64(y / z)) end
function tmp = code(x, y, z) tmp = x + (y / z); end
code[x_, y_, z_] := N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{z}
\end{array}
Initial program 100.0%
div-sub97.6%
associate-+r-97.6%
remove-double-neg97.6%
distribute-frac-neg97.6%
unsub-neg97.6%
associate--r+97.6%
+-commutative97.6%
distribute-frac-neg97.6%
sub-neg97.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 77.3%
neg-mul-177.3%
distribute-neg-frac77.3%
Simplified77.3%
div-inv77.1%
cancel-sign-sub77.1%
div-inv77.3%
+-commutative77.3%
Applied egg-rr77.3%
Final simplification77.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-sub97.6%
associate-+r-97.6%
remove-double-neg97.6%
distribute-frac-neg97.6%
unsub-neg97.6%
associate--r+97.6%
+-commutative97.6%
distribute-frac-neg97.6%
sub-neg97.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 36.8%
Final simplification36.8%
herbie shell --seed 2024027
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))