
(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
(let* ((t_0 (/ x (- z))))
(if (<= z -620000000.0)
x
(if (<= z -7.2e-240)
(/ y z)
(if (<= z 5.6e-293)
t_0
(if (<= z 8e-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 <= -620000000.0) {
tmp = x;
} else if (z <= -7.2e-240) {
tmp = y / z;
} else if (z <= 5.6e-293) {
tmp = t_0;
} else if (z <= 8e-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 <= (-620000000.0d0)) then
tmp = x
else if (z <= (-7.2d-240)) then
tmp = y / z
else if (z <= 5.6d-293) then
tmp = t_0
else if (z <= 8d-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 <= -620000000.0) {
tmp = x;
} else if (z <= -7.2e-240) {
tmp = y / z;
} else if (z <= 5.6e-293) {
tmp = t_0;
} else if (z <= 8e-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 <= -620000000.0: tmp = x elif z <= -7.2e-240: tmp = y / z elif z <= 5.6e-293: tmp = t_0 elif z <= 8e-170: tmp = y / z elif z <= 1.0: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (z <= -620000000.0) tmp = x; elseif (z <= -7.2e-240) tmp = Float64(y / z); elseif (z <= 5.6e-293) tmp = t_0; elseif (z <= 8e-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 <= -620000000.0) tmp = x; elseif (z <= -7.2e-240) tmp = y / z; elseif (z <= 5.6e-293) tmp = t_0; elseif (z <= 8e-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, -620000000.0], x, If[LessEqual[z, -7.2e-240], N[(y / z), $MachinePrecision], If[LessEqual[z, 5.6e-293], t$95$0, If[LessEqual[z, 8e-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 -620000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -7.2 \cdot 10^{-240}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 5.6 \cdot 10^{-293}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 8 \cdot 10^{-170}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.2e8 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.0%
if -6.2e8 < z < -7.1999999999999998e-240 or 5.60000000000000051e-293 < z < 7.99999999999999987e-170Initial program 99.9%
div-sub97.8%
sub-neg97.8%
distribute-frac-neg97.8%
+-commutative97.8%
associate-+r+97.8%
distribute-frac-neg97.8%
sub-neg97.8%
associate--r-97.8%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around 0 62.5%
if -7.1999999999999998e-240 < z < 5.60000000000000051e-293 or 7.99999999999999987e-170 < z < 1Initial program 100.0%
div-sub92.2%
sub-neg92.2%
distribute-frac-neg92.2%
+-commutative92.2%
associate-+r+92.2%
distribute-frac-neg92.2%
sub-neg92.2%
associate--r-92.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 71.7%
Taylor expanded in z around 0 68.8%
associate-*r/68.8%
neg-mul-168.8%
Simplified68.8%
Final simplification68.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (/ y z))) (t_1 (/ x (- z))))
(if (<= z -1.35e-239)
t_0
(if (<= z 2.4e-294)
t_1
(if (<= z 1.15e-169) (/ y z) (if (<= z 0.045) 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.35e-239) {
tmp = t_0;
} else if (z <= 2.4e-294) {
tmp = t_1;
} else if (z <= 1.15e-169) {
tmp = y / z;
} else if (z <= 0.045) {
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.35d-239)) then
tmp = t_0
else if (z <= 2.4d-294) then
tmp = t_1
else if (z <= 1.15d-169) then
tmp = y / z
else if (z <= 0.045d0) 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.35e-239) {
tmp = t_0;
} else if (z <= 2.4e-294) {
tmp = t_1;
} else if (z <= 1.15e-169) {
tmp = y / z;
} else if (z <= 0.045) {
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.35e-239: tmp = t_0 elif z <= 2.4e-294: tmp = t_1 elif z <= 1.15e-169: tmp = y / z elif z <= 0.045: 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.35e-239) tmp = t_0; elseif (z <= 2.4e-294) tmp = t_1; elseif (z <= 1.15e-169) tmp = Float64(y / z); elseif (z <= 0.045) 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.35e-239) tmp = t_0; elseif (z <= 2.4e-294) tmp = t_1; elseif (z <= 1.15e-169) tmp = y / z; elseif (z <= 0.045) 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.35e-239], t$95$0, If[LessEqual[z, 2.4e-294], t$95$1, If[LessEqual[z, 1.15e-169], N[(y / z), $MachinePrecision], If[LessEqual[z, 0.045], 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.35 \cdot 10^{-239}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.4 \cdot 10^{-294}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-169}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 0.045:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.35e-239 or 0.044999999999999998 < z Initial program 100.0%
div-sub99.4%
sub-neg99.4%
distribute-frac-neg99.4%
+-commutative99.4%
associate-+r+99.4%
distribute-frac-neg99.4%
sub-neg99.4%
associate--r-99.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 84.3%
neg-mul-184.3%
distribute-neg-frac284.3%
Simplified84.3%
Taylor expanded in x around 0 84.3%
sub-neg84.3%
mul-1-neg84.3%
remove-double-neg84.3%
+-commutative84.3%
Simplified84.3%
if -1.35e-239 < z < 2.39999999999999997e-294 or 1.15e-169 < z < 0.044999999999999998Initial program 100.0%
div-sub92.2%
sub-neg92.2%
distribute-frac-neg92.2%
+-commutative92.2%
associate-+r+92.2%
distribute-frac-neg92.2%
sub-neg92.2%
associate--r-92.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 71.7%
Taylor expanded in z around 0 68.8%
associate-*r/68.8%
neg-mul-168.8%
Simplified68.8%
if 2.39999999999999997e-294 < z < 1.15e-169Initial program 99.9%
div-sub96.7%
sub-neg96.7%
distribute-frac-neg96.7%
+-commutative96.7%
associate-+r+96.7%
distribute-frac-neg96.7%
sub-neg96.7%
associate--r-96.7%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around 0 77.3%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.9e+18) (not (<= y 1e+79))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.9e+18) || !(y <= 1e+79)) {
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 <= (-6.9d+18)) .or. (.not. (y <= 1d+79))) 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 <= -6.9e+18) || !(y <= 1e+79)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.9e+18) or not (y <= 1e+79): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.9e+18) || !(y <= 1e+79)) 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 <= -6.9e+18) || ~((y <= 1e+79))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.9e+18], N[Not[LessEqual[y, 1e+79]], $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 -6.9 \cdot 10^{+18} \lor \neg \left(y \leq 10^{+79}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -6.9e18 or 9.99999999999999967e78 < y Initial program 100.0%
div-sub94.3%
sub-neg94.3%
distribute-frac-neg94.3%
+-commutative94.3%
associate-+r+94.3%
distribute-frac-neg94.3%
sub-neg94.3%
associate--r-94.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 94.0%
neg-mul-194.0%
distribute-neg-frac294.0%
Simplified94.0%
Taylor expanded in x around 0 94.0%
sub-neg94.0%
mul-1-neg94.0%
remove-double-neg94.0%
+-commutative94.0%
Simplified94.0%
if -6.9e18 < y < 9.99999999999999967e78Initial 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 86.3%
Final simplification89.5%
(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%
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.0%
neg-mul-198.0%
distribute-neg-frac298.0%
Simplified98.0%
Taylor expanded in x around 0 98.0%
sub-neg98.0%
mul-1-neg98.0%
remove-double-neg98.0%
+-commutative98.0%
Simplified98.0%
if -1 < z < 1Initial program 100.0%
div-sub95.7%
sub-neg95.7%
distribute-frac-neg95.7%
+-commutative95.7%
associate-+r+95.7%
distribute-frac-neg95.7%
sub-neg95.7%
associate--r-95.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.9%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (<= z -650000000.0) x (if (<= z 1.6e+28) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -650000000.0) {
tmp = x;
} else if (z <= 1.6e+28) {
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 <= (-650000000.0d0)) then
tmp = x
else if (z <= 1.6d+28) 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 <= -650000000.0) {
tmp = x;
} else if (z <= 1.6e+28) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -650000000.0: tmp = x elif z <= 1.6e+28: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -650000000.0) tmp = x; elseif (z <= 1.6e+28) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -650000000.0) tmp = x; elseif (z <= 1.6e+28) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -650000000.0], x, If[LessEqual[z, 1.6e+28], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -650000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{+28}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.5e8 or 1.6e28 < 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 -6.5e8 < z < 1.6e28Initial program 100.0%
div-sub96.0%
sub-neg96.0%
distribute-frac-neg96.0%
+-commutative96.0%
associate-+r+96.0%
distribute-frac-neg96.0%
sub-neg96.0%
associate--r-96.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 51.6%
Final simplification61.7%
(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%
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 inf 33.8%
Final simplification33.8%
herbie shell --seed 2024079
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))