
(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 -1.35e+50)
x
(if (<= z -3.2e-185)
(/ y z)
(if (<= z 1.45e-108) (/ x (- z)) (if (<= z 2.06e+65) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.35e+50) {
tmp = x;
} else if (z <= -3.2e-185) {
tmp = y / z;
} else if (z <= 1.45e-108) {
tmp = x / -z;
} else if (z <= 2.06e+65) {
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.35d+50)) then
tmp = x
else if (z <= (-3.2d-185)) then
tmp = y / z
else if (z <= 1.45d-108) then
tmp = x / -z
else if (z <= 2.06d+65) 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.35e+50) {
tmp = x;
} else if (z <= -3.2e-185) {
tmp = y / z;
} else if (z <= 1.45e-108) {
tmp = x / -z;
} else if (z <= 2.06e+65) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.35e+50: tmp = x elif z <= -3.2e-185: tmp = y / z elif z <= 1.45e-108: tmp = x / -z elif z <= 2.06e+65: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.35e+50) tmp = x; elseif (z <= -3.2e-185) tmp = Float64(y / z); elseif (z <= 1.45e-108) tmp = Float64(x / Float64(-z)); elseif (z <= 2.06e+65) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.35e+50) tmp = x; elseif (z <= -3.2e-185) tmp = y / z; elseif (z <= 1.45e-108) tmp = x / -z; elseif (z <= 2.06e+65) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.35e+50], x, If[LessEqual[z, -3.2e-185], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.45e-108], N[(x / (-z)), $MachinePrecision], If[LessEqual[z, 2.06e+65], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{+50}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -3.2 \cdot 10^{-185}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{-108}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{elif}\;z \leq 2.06 \cdot 10^{+65}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.35e50 or 2.06000000000000004e65 < 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.8%
if -1.35e50 < z < -3.1999999999999997e-185 or 1.45e-108 < z < 2.06000000000000004e65Initial 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 60.0%
if -3.1999999999999997e-185 < z < 1.45e-108Initial program 100.0%
div-sub96.3%
sub-neg96.3%
distribute-frac-neg96.3%
+-commutative96.3%
associate-+r+96.3%
distribute-frac-neg96.3%
sub-neg96.3%
associate--r-96.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 66.0%
distribute-lft-out--66.0%
*-rgt-identity66.0%
associate-*r/66.1%
*-rgt-identity66.1%
Simplified66.1%
Taylor expanded in z around 0 66.1%
mul-1-neg66.1%
distribute-frac-neg66.1%
Simplified66.1%
Final simplification68.7%
(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 99.5%
neg-mul-199.5%
Simplified99.5%
sub-neg99.5%
+-commutative99.5%
distribute-frac-neg99.5%
remove-double-neg99.5%
Applied egg-rr99.5%
if -1 < z < 1Initial program 100.0%
div-sub98.2%
sub-neg98.2%
distribute-frac-neg98.2%
+-commutative98.2%
associate-+r+98.2%
distribute-frac-neg98.2%
sub-neg98.2%
associate--r-98.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.7%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.9e-54) (not (<= y 8.6e-103))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.9e-54) || !(y <= 8.6e-103)) {
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 <= (-3.9d-54)) .or. (.not. (y <= 8.6d-103))) 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 <= -3.9e-54) || !(y <= 8.6e-103)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.9e-54) or not (y <= 8.6e-103): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.9e-54) || !(y <= 8.6e-103)) 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 <= -3.9e-54) || ~((y <= 8.6e-103))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.9e-54], N[Not[LessEqual[y, 8.6e-103]], $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 -3.9 \cdot 10^{-54} \lor \neg \left(y \leq 8.6 \cdot 10^{-103}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -3.9e-54 or 8.60000000000000045e-103 < y Initial 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 x around 0 87.4%
neg-mul-187.4%
Simplified87.4%
sub-neg87.4%
+-commutative87.4%
distribute-frac-neg87.4%
remove-double-neg87.4%
Applied egg-rr87.4%
if -3.9e-54 < y < 8.60000000000000045e-103Initial 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 91.8%
distribute-lft-out--91.8%
*-rgt-identity91.8%
associate-*r/91.9%
*-rgt-identity91.9%
Simplified91.9%
Final simplification89.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.2e-181) (not (<= z 1.45e-108))) (+ x (/ y z)) (/ x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e-181) || !(z <= 1.45e-108)) {
tmp = x + (y / z);
} else {
tmp = 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 <= (-3.2d-181)) .or. (.not. (z <= 1.45d-108))) then
tmp = x + (y / z)
else
tmp = x / -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e-181) || !(z <= 1.45e-108)) {
tmp = x + (y / z);
} else {
tmp = x / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.2e-181) or not (z <= 1.45e-108): tmp = x + (y / z) else: tmp = x / -z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.2e-181) || !(z <= 1.45e-108)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(x / Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.2e-181) || ~((z <= 1.45e-108))) tmp = x + (y / z); else tmp = x / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.2e-181], N[Not[LessEqual[z, 1.45e-108]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.2 \cdot 10^{-181} \lor \neg \left(z \leq 1.45 \cdot 10^{-108}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-z}\\
\end{array}
\end{array}
if z < -3.2000000000000002e-181 or 1.45e-108 < 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 87.2%
neg-mul-187.2%
Simplified87.2%
sub-neg87.2%
+-commutative87.2%
distribute-frac-neg87.2%
remove-double-neg87.2%
Applied egg-rr87.2%
if -3.2000000000000002e-181 < z < 1.45e-108Initial program 100.0%
div-sub96.3%
sub-neg96.3%
distribute-frac-neg96.3%
+-commutative96.3%
associate-+r+96.3%
distribute-frac-neg96.3%
sub-neg96.3%
associate--r-96.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 66.0%
distribute-lft-out--66.0%
*-rgt-identity66.0%
associate-*r/66.1%
*-rgt-identity66.1%
Simplified66.1%
Taylor expanded in z around 0 66.1%
mul-1-neg66.1%
distribute-frac-neg66.1%
Simplified66.1%
Final simplification82.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.6e+50) x (if (<= z 3.1e+65) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.6e+50) {
tmp = x;
} else if (z <= 3.1e+65) {
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.6d+50)) then
tmp = x
else if (z <= 3.1d+65) 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.6e+50) {
tmp = x;
} else if (z <= 3.1e+65) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.6e+50: tmp = x elif z <= 3.1e+65: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.6e+50) tmp = x; elseif (z <= 3.1e+65) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.6e+50) tmp = x; elseif (z <= 3.1e+65) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.6e+50], x, If[LessEqual[z, 3.1e+65], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.6 \cdot 10^{+50}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.1 \cdot 10^{+65}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.59999999999999991e50 or 3.09999999999999991e65 < 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.8%
if -1.59999999999999991e50 < z < 3.09999999999999991e65Initial 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 52.9%
(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-sub99.2%
sub-neg99.2%
distribute-frac-neg99.2%
+-commutative99.2%
associate-+r+99.2%
distribute-frac-neg99.2%
sub-neg99.2%
associate--r-99.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 39.8%
herbie shell --seed 2024163
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))