
(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 (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.6%
neg-mul-198.6%
Simplified98.6%
Taylor expanded in x around 0 98.6%
cancel-sign-sub-inv98.6%
metadata-eval98.6%
*-lft-identity98.6%
+-commutative98.6%
Simplified98.6%
if -1 < z < 1Initial 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 0 98.1%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.4e-101) (not (<= y 4.2e-136))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e-101) || !(y <= 4.2e-136)) {
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.4d-101)) .or. (.not. (y <= 4.2d-136))) 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.4e-101) || !(y <= 4.2e-136)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.4e-101) or not (y <= 4.2e-136): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.4e-101) || !(y <= 4.2e-136)) 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.4e-101) || ~((y <= 4.2e-136))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.4e-101], N[Not[LessEqual[y, 4.2e-136]], $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.4 \cdot 10^{-101} \lor \neg \left(y \leq 4.2 \cdot 10^{-136}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -3.39999999999999989e-101 or 4.1999999999999997e-136 < y Initial program 100.0%
div-sub98.3%
sub-neg98.3%
distribute-frac-neg98.3%
+-commutative98.3%
associate-+r+98.3%
distribute-frac-neg98.3%
sub-neg98.3%
associate--r-98.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 86.4%
neg-mul-186.4%
Simplified86.4%
Taylor expanded in x around 0 86.4%
cancel-sign-sub-inv86.4%
metadata-eval86.4%
*-lft-identity86.4%
+-commutative86.4%
Simplified86.4%
if -3.39999999999999989e-101 < y < 4.1999999999999997e-136Initial program 100.0%
div-sub99.9%
sub-neg99.9%
distribute-frac-neg99.9%
+-commutative99.9%
associate-+r+99.9%
distribute-frac-neg99.9%
sub-neg99.9%
associate--r-99.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 93.4%
distribute-lft-out--93.4%
*-rgt-identity93.4%
associate-*r/93.5%
*-rgt-identity93.5%
Simplified93.5%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (<= z -2.5e+129) x (if (<= z 8.5e+58) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.5e+129) {
tmp = x;
} else if (z <= 8.5e+58) {
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 <= (-2.5d+129)) then
tmp = x
else if (z <= 8.5d+58) 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 <= -2.5e+129) {
tmp = x;
} else if (z <= 8.5e+58) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.5e+129: tmp = x elif z <= 8.5e+58: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.5e+129) tmp = x; elseif (z <= 8.5e+58) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.5e+129) tmp = x; elseif (z <= 8.5e+58) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.5e+129], x, If[LessEqual[z, 8.5e+58], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{+129}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{+58}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.5000000000000001e129 or 8.50000000000000015e58 < 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 78.9%
if -2.5000000000000001e129 < z < 8.50000000000000015e58Initial program 100.0%
div-sub98.1%
sub-neg98.1%
distribute-frac-neg98.1%
+-commutative98.1%
associate-+r+98.1%
distribute-frac-neg98.1%
sub-neg98.1%
associate--r-98.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 54.9%
(FPCore (x y z) :precision binary64 (if (<= x -1.5e+188) (/ x (- z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.5e+188) {
tmp = 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 <= (-1.5d+188)) then
tmp = 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 <= -1.5e+188) {
tmp = x / -z;
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.5e+188: tmp = x / -z else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.5e+188) tmp = Float64(x / Float64(-z)); else tmp = Float64(x + Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.5e+188) tmp = x / -z; else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.5e+188], N[(x / (-z)), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+188}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.5e188Initial 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 95.3%
distribute-lft-out--95.3%
*-rgt-identity95.3%
associate-*r/95.5%
*-rgt-identity95.5%
Simplified95.5%
Taylor expanded in z around 0 68.2%
mul-1-neg68.2%
distribute-frac-neg268.2%
Simplified68.2%
if -1.5e188 < x 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 78.1%
neg-mul-178.1%
Simplified78.1%
Taylor expanded in x around 0 78.1%
cancel-sign-sub-inv78.1%
metadata-eval78.1%
*-lft-identity78.1%
+-commutative78.1%
Simplified78.1%
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-sub98.8%
sub-neg98.8%
distribute-frac-neg98.8%
+-commutative98.8%
associate-+r+98.8%
distribute-frac-neg98.8%
sub-neg98.8%
associate--r-98.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 32.1%
herbie shell --seed 2024145
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))