
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -1.4e+94)
x
(if (<= z -1.45e-38)
(/ y z)
(if (<= z 6e-274) (/ (- x) z) (if (<= z 2.15e+19) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.4e+94) {
tmp = x;
} else if (z <= -1.45e-38) {
tmp = y / z;
} else if (z <= 6e-274) {
tmp = -x / z;
} else if (z <= 2.15e+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 <= (-1.4d+94)) then
tmp = x
else if (z <= (-1.45d-38)) then
tmp = y / z
else if (z <= 6d-274) then
tmp = -x / z
else if (z <= 2.15d+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 <= -1.4e+94) {
tmp = x;
} else if (z <= -1.45e-38) {
tmp = y / z;
} else if (z <= 6e-274) {
tmp = -x / z;
} else if (z <= 2.15e+19) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.4e+94: tmp = x elif z <= -1.45e-38: tmp = y / z elif z <= 6e-274: tmp = -x / z elif z <= 2.15e+19: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.4e+94) tmp = x; elseif (z <= -1.45e-38) tmp = Float64(y / z); elseif (z <= 6e-274) tmp = Float64(Float64(-x) / z); elseif (z <= 2.15e+19) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.4e+94) tmp = x; elseif (z <= -1.45e-38) tmp = y / z; elseif (z <= 6e-274) tmp = -x / z; elseif (z <= 2.15e+19) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.4e+94], x, If[LessEqual[z, -1.45e-38], N[(y / z), $MachinePrecision], If[LessEqual[z, 6e-274], N[((-x) / z), $MachinePrecision], If[LessEqual[z, 2.15e+19], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{+94}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.45 \cdot 10^{-38}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 6 \cdot 10^{-274}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{elif}\;z \leq 2.15 \cdot 10^{+19}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.39999999999999999e94 or 2.15e19 < 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 81.4%
if -1.39999999999999999e94 < z < -1.44999999999999997e-38 or 5.99999999999999954e-274 < z < 2.15e19Initial program 100.0%
div-sub97.7%
sub-neg97.7%
distribute-frac-neg97.7%
+-commutative97.7%
associate-+r+97.7%
distribute-frac-neg97.7%
sub-neg97.7%
associate--r-97.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 60.3%
if -1.44999999999999997e-38 < z < 5.99999999999999954e-274Initial 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 x around inf 60.6%
distribute-rgt-out--60.6%
*-lft-identity60.6%
associate-*l/60.7%
*-lft-identity60.7%
Simplified60.7%
Taylor expanded in z around 0 60.7%
mul-1-neg60.7%
distribute-neg-frac60.7%
Simplified60.7%
Final simplification70.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.8e-212) (not (<= y -4.1e-283))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.8e-212) || !(y <= -4.1e-283)) {
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 ((y <= (-6.8d-212)) .or. (.not. (y <= (-4.1d-283)))) 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 ((y <= -6.8e-212) || !(y <= -4.1e-283)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.8e-212) or not (y <= -4.1e-283): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.8e-212) || !(y <= -4.1e-283)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(Float64(-x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.8e-212) || ~((y <= -4.1e-283))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.8e-212], N[Not[LessEqual[y, -4.1e-283]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{-212} \lor \neg \left(y \leq -4.1 \cdot 10^{-283}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if y < -6.79999999999999995e-212 or -4.09999999999999987e-283 < y Initial 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 81.1%
neg-mul-181.1%
distribute-neg-frac281.1%
Simplified81.1%
Taylor expanded in x around 0 81.1%
cancel-sign-sub-inv81.1%
metadata-eval81.1%
*-lft-identity81.1%
+-commutative81.1%
Simplified81.1%
if -6.79999999999999995e-212 < y < -4.09999999999999987e-283Initial 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 94.9%
distribute-rgt-out--94.8%
*-lft-identity94.8%
associate-*l/95.1%
*-lft-identity95.1%
Simplified95.1%
Taylor expanded in z around 0 71.0%
mul-1-neg71.0%
distribute-neg-frac71.0%
Simplified71.0%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.3e+17) (not (<= x 1.55e+25))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.3e+17) || !(x <= 1.55e+25)) {
tmp = x - (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 <= (-4.3d+17)) .or. (.not. (x <= 1.55d+25))) then
tmp = x - (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 <= -4.3e+17) || !(x <= 1.55e+25)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.3e+17) or not (x <= 1.55e+25): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.3e+17) || !(x <= 1.55e+25)) tmp = Float64(x - Float64(x / z)); else tmp = Float64(x + Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.3e+17) || ~((x <= 1.55e+25))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.3e+17], N[Not[LessEqual[x, 1.55e+25]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.3 \cdot 10^{+17} \lor \neg \left(x \leq 1.55 \cdot 10^{+25}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -4.3e17 or 1.5499999999999999e25 < x Initial program 100.0%
div-sub94.9%
sub-neg94.9%
distribute-frac-neg94.9%
+-commutative94.9%
associate-+r+94.9%
distribute-frac-neg94.9%
sub-neg94.9%
associate--r-94.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 90.6%
distribute-rgt-out--90.6%
*-lft-identity90.6%
associate-*l/90.6%
*-lft-identity90.6%
Simplified90.6%
if -4.3e17 < x < 1.5499999999999999e25Initial 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 91.0%
neg-mul-191.0%
distribute-neg-frac291.0%
Simplified91.0%
Taylor expanded in x around 0 91.0%
cancel-sign-sub-inv91.0%
metadata-eval91.0%
*-lft-identity91.0%
+-commutative91.0%
Simplified91.0%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (<= z -8.6e+93) x (if (<= z 9e+18) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.6e+93) {
tmp = x;
} else if (z <= 9e+18) {
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 <= (-8.6d+93)) then
tmp = x
else if (z <= 9d+18) 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 <= -8.6e+93) {
tmp = x;
} else if (z <= 9e+18) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.6e+93: tmp = x elif z <= 9e+18: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.6e+93) tmp = x; elseif (z <= 9e+18) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.6e+93) tmp = x; elseif (z <= 9e+18) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.6e+93], x, If[LessEqual[z, 9e+18], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.6 \cdot 10^{+93}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 9 \cdot 10^{+18}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.6e93 or 9e18 < 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 81.4%
if -8.6e93 < z < 9e18Initial program 100.0%
div-sub95.6%
sub-neg95.6%
distribute-frac-neg95.6%
+-commutative95.6%
associate-+r+95.6%
distribute-frac-neg95.6%
sub-neg95.6%
associate--r-95.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 54.2%
Final simplification66.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 40.5%
Final simplification40.5%
herbie shell --seed 2024066
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))