
(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 6 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
(if (<= z -6e+110)
x
(if (<= z -2.4e+37)
(/ y z)
(if (<= z -180.0)
x
(if (<= z -4.5e-276) (/ y z) (if (<= z 0.00082) (/ x (- z)) x))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6e+110) {
tmp = x;
} else if (z <= -2.4e+37) {
tmp = y / z;
} else if (z <= -180.0) {
tmp = x;
} else if (z <= -4.5e-276) {
tmp = y / z;
} else if (z <= 0.00082) {
tmp = x / -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 <= (-6d+110)) then
tmp = x
else if (z <= (-2.4d+37)) then
tmp = y / z
else if (z <= (-180.0d0)) then
tmp = x
else if (z <= (-4.5d-276)) then
tmp = y / z
else if (z <= 0.00082d0) then
tmp = x / -z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -6e+110) {
tmp = x;
} else if (z <= -2.4e+37) {
tmp = y / z;
} else if (z <= -180.0) {
tmp = x;
} else if (z <= -4.5e-276) {
tmp = y / z;
} else if (z <= 0.00082) {
tmp = x / -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6e+110: tmp = x elif z <= -2.4e+37: tmp = y / z elif z <= -180.0: tmp = x elif z <= -4.5e-276: tmp = y / z elif z <= 0.00082: tmp = x / -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6e+110) tmp = x; elseif (z <= -2.4e+37) tmp = Float64(y / z); elseif (z <= -180.0) tmp = x; elseif (z <= -4.5e-276) tmp = Float64(y / z); elseif (z <= 0.00082) tmp = Float64(x / Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6e+110) tmp = x; elseif (z <= -2.4e+37) tmp = y / z; elseif (z <= -180.0) tmp = x; elseif (z <= -4.5e-276) tmp = y / z; elseif (z <= 0.00082) tmp = x / -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6e+110], x, If[LessEqual[z, -2.4e+37], N[(y / z), $MachinePrecision], If[LessEqual[z, -180.0], x, If[LessEqual[z, -4.5e-276], N[(y / z), $MachinePrecision], If[LessEqual[z, 0.00082], N[(x / (-z)), $MachinePrecision], x]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{+110}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -2.4 \cdot 10^{+37}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -180:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -4.5 \cdot 10^{-276}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 0.00082:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.00000000000000014e110 or -2.4e37 < z < -180 or 8.1999999999999998e-4 < 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 inf 76.8%
Taylor expanded in z around inf 75.1%
if -6.00000000000000014e110 < z < -2.4e37 or -180 < z < -4.49999999999999962e-276Initial 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 0 71.2%
neg-mul-171.2%
distribute-neg-frac71.2%
Simplified71.2%
Taylor expanded in x around 0 64.4%
if -4.49999999999999962e-276 < z < 8.1999999999999998e-4Initial program 100.0%
div-sub94.8%
sub-neg94.8%
distribute-frac-neg94.8%
+-commutative94.8%
associate-+r+94.8%
distribute-frac-neg94.8%
sub-neg94.8%
associate--r-94.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 67.9%
Taylor expanded in z around 0 66.1%
mul-1-neg66.1%
distribute-frac-neg266.1%
Simplified66.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (/ y z))) (t_1 (/ x (- z))))
(if (<= z -2.9e-287)
t_0
(if (<= z 1.15e-138)
t_1
(if (<= z 1.05e-79) (/ y z) (if (<= z 2.4e-11) 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 <= -2.9e-287) {
tmp = t_0;
} else if (z <= 1.15e-138) {
tmp = t_1;
} else if (z <= 1.05e-79) {
tmp = y / z;
} else if (z <= 2.4e-11) {
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 <= (-2.9d-287)) then
tmp = t_0
else if (z <= 1.15d-138) then
tmp = t_1
else if (z <= 1.05d-79) then
tmp = y / z
else if (z <= 2.4d-11) 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 <= -2.9e-287) {
tmp = t_0;
} else if (z <= 1.15e-138) {
tmp = t_1;
} else if (z <= 1.05e-79) {
tmp = y / z;
} else if (z <= 2.4e-11) {
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 <= -2.9e-287: tmp = t_0 elif z <= 1.15e-138: tmp = t_1 elif z <= 1.05e-79: tmp = y / z elif z <= 2.4e-11: 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 <= -2.9e-287) tmp = t_0; elseif (z <= 1.15e-138) tmp = t_1; elseif (z <= 1.05e-79) tmp = Float64(y / z); elseif (z <= 2.4e-11) 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 <= -2.9e-287) tmp = t_0; elseif (z <= 1.15e-138) tmp = t_1; elseif (z <= 1.05e-79) tmp = y / z; elseif (z <= 2.4e-11) 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, -2.9e-287], t$95$0, If[LessEqual[z, 1.15e-138], t$95$1, If[LessEqual[z, 1.05e-79], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.4e-11], 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 -2.9 \cdot 10^{-287}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-138}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{-79}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.4 \cdot 10^{-11}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.8999999999999998e-287 or 2.4000000000000001e-11 < z Initial program 100.0%
div-sub98.5%
sub-neg98.5%
distribute-frac-neg98.5%
+-commutative98.5%
associate-+r+98.5%
distribute-frac-neg98.5%
sub-neg98.5%
associate--r-98.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 86.5%
neg-mul-186.5%
distribute-neg-frac86.5%
Simplified86.5%
sub-neg86.5%
+-commutative86.5%
distribute-frac-neg86.5%
remove-double-neg86.5%
Applied egg-rr86.5%
if -2.8999999999999998e-287 < z < 1.14999999999999995e-138 or 1.05e-79 < z < 2.4000000000000001e-11Initial program 100.0%
div-sub93.9%
sub-neg93.9%
distribute-frac-neg93.9%
+-commutative93.9%
associate-+r+93.9%
distribute-frac-neg93.9%
sub-neg93.9%
associate--r-93.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 75.9%
Taylor expanded in z around 0 74.8%
mul-1-neg74.8%
distribute-frac-neg274.8%
Simplified74.8%
if 1.14999999999999995e-138 < z < 1.05e-79Initial 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 85.7%
neg-mul-185.7%
distribute-neg-frac85.7%
Simplified85.7%
Taylor expanded in x around 0 85.8%
Final simplification84.3%
(FPCore (x y z)
:precision binary64
(if (<= z -9.8e+110)
x
(if (or (<= z -2.15e+37) (and (not (<= z -180.0)) (<= z 2.5e+20)))
(/ y z)
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.8e+110) {
tmp = x;
} else if ((z <= -2.15e+37) || (!(z <= -180.0) && (z <= 2.5e+20))) {
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 <= (-9.8d+110)) then
tmp = x
else if ((z <= (-2.15d+37)) .or. (.not. (z <= (-180.0d0))) .and. (z <= 2.5d+20)) 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 <= -9.8e+110) {
tmp = x;
} else if ((z <= -2.15e+37) || (!(z <= -180.0) && (z <= 2.5e+20))) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.8e+110: tmp = x elif (z <= -2.15e+37) or (not (z <= -180.0) and (z <= 2.5e+20)): tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.8e+110) tmp = x; elseif ((z <= -2.15e+37) || (!(z <= -180.0) && (z <= 2.5e+20))) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.8e+110) tmp = x; elseif ((z <= -2.15e+37) || (~((z <= -180.0)) && (z <= 2.5e+20))) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.8e+110], x, If[Or[LessEqual[z, -2.15e+37], And[N[Not[LessEqual[z, -180.0]], $MachinePrecision], LessEqual[z, 2.5e+20]]], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.8 \cdot 10^{+110}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -2.15 \cdot 10^{+37} \lor \neg \left(z \leq -180\right) \land z \leq 2.5 \cdot 10^{+20}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.80000000000000003e110 or -2.1499999999999998e37 < z < -180 or 2.5e20 < 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 inf 78.5%
Taylor expanded in z around inf 77.3%
if -9.80000000000000003e110 < z < -2.1499999999999998e37 or -180 < z < 2.5e20Initial program 100.0%
div-sub95.9%
sub-neg95.9%
distribute-frac-neg95.9%
+-commutative95.9%
associate-+r+95.9%
distribute-frac-neg95.9%
sub-neg95.9%
associate--r-95.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 57.8%
neg-mul-157.8%
distribute-neg-frac57.8%
Simplified57.8%
Taylor expanded in x around 0 53.8%
Final simplification64.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.25e+15) (not (<= x 5.8e+64))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.25e+15) || !(x <= 5.8e+64)) {
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.25d+15)) .or. (.not. (x <= 5.8d+64))) 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.25e+15) || !(x <= 5.8e+64)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.25e+15) or not (x <= 5.8e+64): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.25e+15) || !(x <= 5.8e+64)) 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.25e+15) || ~((x <= 5.8e+64))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.25e+15], N[Not[LessEqual[x, 5.8e+64]], $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.25 \cdot 10^{+15} \lor \neg \left(x \leq 5.8 \cdot 10^{+64}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -2.25e15 or 5.79999999999999986e64 < x Initial program 100.0%
div-sub94.8%
sub-neg94.8%
distribute-frac-neg94.8%
+-commutative94.8%
associate-+r+94.8%
distribute-frac-neg94.8%
sub-neg94.8%
associate--r-94.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 89.6%
if -2.25e15 < x < 5.79999999999999986e64Initial 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 89.7%
neg-mul-189.7%
distribute-neg-frac89.7%
Simplified89.7%
sub-neg89.7%
+-commutative89.7%
distribute-frac-neg89.7%
remove-double-neg89.7%
Applied egg-rr89.7%
Final simplification89.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-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 inf 62.8%
Taylor expanded in z around inf 37.2%
herbie shell --seed 2024086
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))