
(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 -1.0)
x
(if (<= z -2.2e-115)
t_0
(if (<= z -4.6e-229)
(/ y z)
(if (<= z 1.58e-285) t_0 (if (<= z 2.2e+15) (/ y z) x)))))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (z <= -1.0) {
tmp = x;
} else if (z <= -2.2e-115) {
tmp = t_0;
} else if (z <= -4.6e-229) {
tmp = y / z;
} else if (z <= 1.58e-285) {
tmp = t_0;
} else if (z <= 2.2e+15) {
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) :: t_0
real(8) :: tmp
t_0 = x / -z
if (z <= (-1.0d0)) then
tmp = x
else if (z <= (-2.2d-115)) then
tmp = t_0
else if (z <= (-4.6d-229)) then
tmp = y / z
else if (z <= 1.58d-285) then
tmp = t_0
else if (z <= 2.2d+15) then
tmp = y / z
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 <= -1.0) {
tmp = x;
} else if (z <= -2.2e-115) {
tmp = t_0;
} else if (z <= -4.6e-229) {
tmp = y / z;
} else if (z <= 1.58e-285) {
tmp = t_0;
} else if (z <= 2.2e+15) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if z <= -1.0: tmp = x elif z <= -2.2e-115: tmp = t_0 elif z <= -4.6e-229: tmp = y / z elif z <= 1.58e-285: tmp = t_0 elif z <= 2.2e+15: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (z <= -1.0) tmp = x; elseif (z <= -2.2e-115) tmp = t_0; elseif (z <= -4.6e-229) tmp = Float64(y / z); elseif (z <= 1.58e-285) tmp = t_0; elseif (z <= 2.2e+15) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x / -z; tmp = 0.0; if (z <= -1.0) tmp = x; elseif (z <= -2.2e-115) tmp = t_0; elseif (z <= -4.6e-229) tmp = y / z; elseif (z <= 1.58e-285) tmp = t_0; elseif (z <= 2.2e+15) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x / (-z)), $MachinePrecision]}, If[LessEqual[z, -1.0], x, If[LessEqual[z, -2.2e-115], t$95$0, If[LessEqual[z, -4.6e-229], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.58e-285], t$95$0, If[LessEqual[z, 2.2e+15], N[(y / z), $MachinePrecision], x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -2.2 \cdot 10^{-115}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -4.6 \cdot 10^{-229}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.58 \cdot 10^{-285}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{+15}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 2.2e15 < 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 76.5%
if -1 < z < -2.1999999999999999e-115 or -4.59999999999999992e-229 < z < 1.58e-285Initial program 99.9%
div-sub97.1%
sub-neg97.1%
distribute-frac-neg97.1%
+-commutative97.1%
associate-+r+97.1%
distribute-frac-neg97.1%
sub-neg97.1%
associate--r-97.1%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around inf 75.2%
distribute-rgt-out--75.2%
*-lft-identity75.2%
associate-*l/75.3%
*-lft-identity75.3%
Simplified75.3%
Taylor expanded in z around 0 69.9%
associate-*r/69.9%
neg-mul-169.9%
Simplified69.9%
if -2.1999999999999999e-115 < z < -4.59999999999999992e-229 or 1.58e-285 < z < 2.2e15Initial program 100.0%
div-sub97.4%
sub-neg97.4%
distribute-frac-neg97.4%
+-commutative97.4%
associate-+r+97.4%
distribute-frac-neg97.4%
sub-neg97.4%
associate--r-97.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 66.6%
Final simplification72.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.1e-6) (not (<= y 5.5e-79))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.1e-6) || !(y <= 5.5e-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 <= (-2.1d-6)) .or. (.not. (y <= 5.5d-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 <= -2.1e-6) || !(y <= 5.5e-79)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.1e-6) or not (y <= 5.5e-79): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.1e-6) || !(y <= 5.5e-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 <= -2.1e-6) || ~((y <= 5.5e-79))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.1e-6], N[Not[LessEqual[y, 5.5e-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 -2.1 \cdot 10^{-6} \lor \neg \left(y \leq 5.5 \cdot 10^{-79}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.0999999999999998e-6 or 5.4999999999999997e-79 < y Initial program 100.0%
div-sub98.0%
sub-neg98.0%
distribute-frac-neg98.0%
+-commutative98.0%
associate-+r+98.0%
distribute-frac-neg98.0%
sub-neg98.0%
associate--r-98.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 91.6%
neg-mul-191.6%
distribute-neg-frac291.6%
Simplified91.6%
Taylor expanded in y around 0 91.6%
if -2.0999999999999998e-6 < y < 5.4999999999999997e-79Initial program 99.9%
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-sub99.9%
Simplified99.9%
Taylor expanded in x around inf 89.6%
distribute-rgt-out--89.6%
*-lft-identity89.6%
associate-*l/89.7%
*-lft-identity89.7%
Simplified89.7%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.3e-19))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.3e-19)) {
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.3d-19))) 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.3e-19)) {
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.3e-19): 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.3e-19)) 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.3e-19))) 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.3e-19]], $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.3 \cdot 10^{-19}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 1.30000000000000006e-19 < 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.8%
neg-mul-198.8%
distribute-neg-frac298.8%
Simplified98.8%
Taylor expanded in y around 0 98.8%
if -1 < z < 1.30000000000000006e-19Initial program 99.9%
div-sub97.2%
sub-neg97.2%
distribute-frac-neg97.2%
+-commutative97.2%
associate-+r+97.2%
distribute-frac-neg97.2%
sub-neg97.2%
associate--r-97.2%
div-sub99.9%
Simplified99.9%
Taylor expanded in z around 0 98.1%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (<= z -17000000000000.0) x (if (<= z 7e+14) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -17000000000000.0) {
tmp = x;
} else if (z <= 7e+14) {
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 <= (-17000000000000.0d0)) then
tmp = x
else if (z <= 7d+14) 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 <= -17000000000000.0) {
tmp = x;
} else if (z <= 7e+14) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -17000000000000.0: tmp = x elif z <= 7e+14: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -17000000000000.0) tmp = x; elseif (z <= 7e+14) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -17000000000000.0) tmp = x; elseif (z <= 7e+14) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -17000000000000.0], x, If[LessEqual[z, 7e+14], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -17000000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+14}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.7e13 or 7e14 < 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.7%
if -1.7e13 < z < 7e14Initial program 99.9%
div-sub97.4%
sub-neg97.4%
distribute-frac-neg97.4%
+-commutative97.4%
associate-+r+97.4%
distribute-frac-neg97.4%
sub-neg97.4%
associate--r-97.4%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around 0 57.1%
Final simplification68.3%
(FPCore (x y z) :precision binary64 (+ x (/ y z)))
double code(double x, double y, double z) {
return x + (y / 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 / z)
end function
public static double code(double x, double y, double z) {
return x + (y / z);
}
def code(x, y, z): return x + (y / z)
function code(x, y, z) return Float64(x + Float64(y / z)) end
function tmp = code(x, y, z) tmp = x + (y / z); end
code[x_, y_, z_] := N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{z}
\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 x around 0 80.7%
neg-mul-180.7%
distribute-neg-frac280.7%
Simplified80.7%
Taylor expanded in y around 0 80.7%
Final simplification80.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-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 43.8%
Final simplification43.8%
herbie shell --seed 2024080
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))