
(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 (if (<= z -5.4e+76) x (if (<= z 1.6e-272) (/ y z) (if (<= z 1.0) (/ x (- z)) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.4e+76) {
tmp = x;
} else if (z <= 1.6e-272) {
tmp = y / z;
} else if (z <= 1.0) {
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 <= (-5.4d+76)) then
tmp = x
else if (z <= 1.6d-272) then
tmp = y / z
else if (z <= 1.0d0) 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 <= -5.4e+76) {
tmp = x;
} else if (z <= 1.6e-272) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = x / -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.4e+76: tmp = x elif z <= 1.6e-272: tmp = y / z elif z <= 1.0: tmp = x / -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.4e+76) tmp = x; elseif (z <= 1.6e-272) tmp = Float64(y / z); elseif (z <= 1.0) tmp = Float64(x / Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.4e+76) tmp = x; elseif (z <= 1.6e-272) tmp = y / z; elseif (z <= 1.0) tmp = x / -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.4e+76], x, If[LessEqual[z, 1.6e-272], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.0], N[(x / (-z)), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.4 \cdot 10^{+76}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{-272}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.3999999999999998e76 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 74.4%
if -5.3999999999999998e76 < z < 1.6e-272Initial program 100.0%
div-sub92.6%
sub-neg92.6%
distribute-frac-neg92.6%
+-commutative92.6%
associate-+r+92.6%
distribute-frac-neg92.6%
sub-neg92.6%
associate--r-92.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 55.2%
if 1.6e-272 < z < 1Initial program 99.9%
div-sub91.9%
sub-neg91.9%
distribute-frac-neg91.9%
+-commutative91.9%
associate-+r+91.9%
distribute-frac-neg91.9%
sub-neg91.9%
associate--r-91.9%
div-sub99.9%
Simplified99.9%
Taylor expanded in z around 0 99.9%
Taylor expanded in y around 0 56.6%
neg-mul-156.6%
Simplified56.6%
Final simplification63.8%
(FPCore (x y z) :precision binary64 (if (<= z -9.5e+75) x (if (<= z 1.85e-16) (/ (- y x) z) (* x (+ 1.0 (/ -1.0 z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.5e+75) {
tmp = x;
} else if (z <= 1.85e-16) {
tmp = (y - x) / z;
} else {
tmp = x * (1.0 + (-1.0 / 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 <= (-9.5d+75)) then
tmp = x
else if (z <= 1.85d-16) then
tmp = (y - x) / z
else
tmp = x * (1.0d0 + ((-1.0d0) / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -9.5e+75) {
tmp = x;
} else if (z <= 1.85e-16) {
tmp = (y - x) / z;
} else {
tmp = x * (1.0 + (-1.0 / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.5e+75: tmp = x elif z <= 1.85e-16: tmp = (y - x) / z else: tmp = x * (1.0 + (-1.0 / z)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.5e+75) tmp = x; elseif (z <= 1.85e-16) tmp = Float64(Float64(y - x) / z); else tmp = Float64(x * Float64(1.0 + Float64(-1.0 / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.5e+75) tmp = x; elseif (z <= 1.85e-16) tmp = (y - x) / z; else tmp = x * (1.0 + (-1.0 / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.5e+75], x, If[LessEqual[z, 1.85e-16], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], N[(x * N[(1.0 + N[(-1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.5 \cdot 10^{+75}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.85 \cdot 10^{-16}:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + \frac{-1}{z}\right)\\
\end{array}
\end{array}
if z < -9.50000000000000061e75Initial 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 79.3%
if -9.50000000000000061e75 < z < 1.85e-16Initial program 100.0%
div-sub92.3%
sub-neg92.3%
distribute-frac-neg92.3%
+-commutative92.3%
associate-+r+92.3%
distribute-frac-neg92.3%
sub-neg92.3%
associate--r-92.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 95.2%
if 1.85e-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 inf 72.3%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.42e+53) (not (<= y 4.6e+87))) (/ y z) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.42e+53) || !(y <= 4.6e+87)) {
tmp = 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.42d+53)) .or. (.not. (y <= 4.6d+87))) then
tmp = 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.42e+53) || !(y <= 4.6e+87)) {
tmp = y / z;
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.42e+53) or not (y <= 4.6e+87): tmp = y / z else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.42e+53) || !(y <= 4.6e+87)) tmp = 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.42e+53) || ~((y <= 4.6e+87))) tmp = y / z; else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.42e+53], N[Not[LessEqual[y, 4.6e+87]], $MachinePrecision]], N[(y / z), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.42 \cdot 10^{+53} \lor \neg \left(y \leq 4.6 \cdot 10^{+87}\right):\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.41999999999999999e53 or 4.6000000000000003e87 < y Initial program 100.0%
div-sub90.1%
sub-neg90.1%
distribute-frac-neg90.1%
+-commutative90.1%
associate-+r+90.1%
distribute-frac-neg90.1%
sub-neg90.1%
associate--r-90.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 74.4%
if -1.41999999999999999e53 < y < 4.6000000000000003e87Initial 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 inf 81.9%
distribute-lft-out--81.9%
*-rgt-identity81.9%
associate-*r/82.0%
*-rgt-identity82.0%
Simplified82.0%
Final simplification79.0%
(FPCore (x y z) :precision binary64 (if (<= z -1.32e+76) x (if (<= z 300000000000.0) (/ (- y x) z) (- x (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.32e+76) {
tmp = x;
} else if (z <= 300000000000.0) {
tmp = (y - x) / 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 (z <= (-1.32d+76)) then
tmp = x
else if (z <= 300000000000.0d0) then
tmp = (y - x) / 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 (z <= -1.32e+76) {
tmp = x;
} else if (z <= 300000000000.0) {
tmp = (y - x) / z;
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.32e+76: tmp = x elif z <= 300000000000.0: tmp = (y - x) / z else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.32e+76) tmp = x; elseif (z <= 300000000000.0) tmp = Float64(Float64(y - x) / z); else tmp = Float64(x - Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.32e+76) tmp = x; elseif (z <= 300000000000.0) tmp = (y - x) / z; else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.32e+76], x, If[LessEqual[z, 300000000000.0], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.32 \cdot 10^{+76}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 300000000000:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if z < -1.31999999999999999e76Initial 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 79.3%
if -1.31999999999999999e76 < z < 3e11Initial program 100.0%
div-sub92.6%
sub-neg92.6%
distribute-frac-neg92.6%
+-commutative92.6%
associate-+r+92.6%
distribute-frac-neg92.6%
sub-neg92.6%
associate--r-92.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 94.1%
if 3e11 < 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 73.4%
distribute-lft-out--73.4%
*-rgt-identity73.4%
associate-*r/73.4%
*-rgt-identity73.4%
Simplified73.4%
(FPCore (x y z) :precision binary64 (if (<= z -9e+75) x (if (<= z 5.2e+19) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -9e+75) {
tmp = x;
} else if (z <= 5.2e+19) {
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 <= (-9d+75)) then
tmp = x
else if (z <= 5.2d+19) 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 <= -9e+75) {
tmp = x;
} else if (z <= 5.2e+19) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9e+75: tmp = x elif z <= 5.2e+19: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9e+75) tmp = x; elseif (z <= 5.2e+19) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9e+75) tmp = x; elseif (z <= 5.2e+19) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9e+75], x, If[LessEqual[z, 5.2e+19], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{+75}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{+19}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.0000000000000007e75 or 5.2e19 < 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 77.0%
if -9.0000000000000007e75 < z < 5.2e19Initial program 100.0%
div-sub92.7%
sub-neg92.7%
distribute-frac-neg92.7%
+-commutative92.7%
associate-+r+92.7%
distribute-frac-neg92.7%
sub-neg92.7%
associate--r-92.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 51.5%
(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-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 inf 36.2%
herbie shell --seed 2024175
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))