
(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 -7e+36)
x
(if (<= z 2.65e-233)
(/ y z)
(if (<= z 6e-108) (/ x (- z)) (if (<= z 3.6e+46) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7e+36) {
tmp = x;
} else if (z <= 2.65e-233) {
tmp = y / z;
} else if (z <= 6e-108) {
tmp = x / -z;
} else if (z <= 3.6e+46) {
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 <= (-7d+36)) then
tmp = x
else if (z <= 2.65d-233) then
tmp = y / z
else if (z <= 6d-108) then
tmp = x / -z
else if (z <= 3.6d+46) 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 <= -7e+36) {
tmp = x;
} else if (z <= 2.65e-233) {
tmp = y / z;
} else if (z <= 6e-108) {
tmp = x / -z;
} else if (z <= 3.6e+46) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7e+36: tmp = x elif z <= 2.65e-233: tmp = y / z elif z <= 6e-108: tmp = x / -z elif z <= 3.6e+46: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7e+36) tmp = x; elseif (z <= 2.65e-233) tmp = Float64(y / z); elseif (z <= 6e-108) tmp = Float64(x / Float64(-z)); elseif (z <= 3.6e+46) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7e+36) tmp = x; elseif (z <= 2.65e-233) tmp = y / z; elseif (z <= 6e-108) tmp = x / -z; elseif (z <= 3.6e+46) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7e+36], x, If[LessEqual[z, 2.65e-233], N[(y / z), $MachinePrecision], If[LessEqual[z, 6e-108], N[(x / (-z)), $MachinePrecision], If[LessEqual[z, 3.6e+46], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{+36}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.65 \cdot 10^{-233}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 6 \cdot 10^{-108}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+46}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.9999999999999996e36 or 3.5999999999999999e46 < 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.0%
if -6.9999999999999996e36 < z < 2.64999999999999986e-233 or 5.99999999999999986e-108 < z < 3.5999999999999999e46Initial 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 x around 0 58.8%
if 2.64999999999999986e-233 < z < 5.99999999999999986e-108Initial 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 69.9%
distribute-lft-out--69.9%
*-rgt-identity69.9%
associate-*r/70.0%
*-rgt-identity70.0%
Simplified70.0%
Taylor expanded in z around 0 70.0%
mul-1-neg70.0%
distribute-frac-neg70.0%
Simplified70.0%
Final simplification66.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.8e+32) (not (<= z 5.7e-6))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e+32) || !(z <= 5.7e-6)) {
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 <= (-4.8d+32)) .or. (.not. (z <= 5.7d-6))) 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 <= -4.8e+32) || !(z <= 5.7e-6)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.8e+32) or not (z <= 5.7e-6): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.8e+32) || !(z <= 5.7e-6)) 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 <= -4.8e+32) || ~((z <= 5.7e-6))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.8e+32], N[Not[LessEqual[z, 5.7e-6]], $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 -4.8 \cdot 10^{+32} \lor \neg \left(z \leq 5.7 \cdot 10^{-6}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -4.79999999999999983e32 or 5.6999999999999996e-6 < 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.0%
neg-mul-199.0%
Simplified99.0%
Taylor expanded in x around 0 99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
*-lft-identity99.0%
+-commutative99.0%
Simplified99.0%
if -4.79999999999999983e32 < z < 5.6999999999999996e-6Initial program 100.0%
div-sub97.8%
sub-neg97.8%
distribute-frac-neg97.8%
+-commutative97.8%
associate-+r+97.8%
distribute-frac-neg97.8%
sub-neg97.8%
associate--r-97.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.7%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.8e-123) (not (<= y 1.45e-28))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.8e-123) || !(y <= 1.45e-28)) {
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.8d-123)) .or. (.not. (y <= 1.45d-28))) 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.8e-123) || !(y <= 1.45e-28)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.8e-123) or not (y <= 1.45e-28): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.8e-123) || !(y <= 1.45e-28)) 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.8e-123) || ~((y <= 1.45e-28))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.8e-123], N[Not[LessEqual[y, 1.45e-28]], $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.8 \cdot 10^{-123} \lor \neg \left(y \leq 1.45 \cdot 10^{-28}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.7999999999999999e-123 or 1.45000000000000006e-28 < y Initial 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 90.0%
neg-mul-190.0%
Simplified90.0%
Taylor expanded in x around 0 90.0%
cancel-sign-sub-inv90.0%
metadata-eval90.0%
*-lft-identity90.0%
+-commutative90.0%
Simplified90.0%
if -2.7999999999999999e-123 < y < 1.45000000000000006e-28Initial 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 92.1%
distribute-lft-out--92.1%
*-rgt-identity92.1%
associate-*r/92.2%
*-rgt-identity92.2%
Simplified92.2%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (<= z -1e+38) x (if (<= z 1.7e+46) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1e+38) {
tmp = x;
} else if (z <= 1.7e+46) {
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 <= (-1d+38)) then
tmp = x
else if (z <= 1.7d+46) 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 <= -1e+38) {
tmp = x;
} else if (z <= 1.7e+46) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1e+38: tmp = x elif z <= 1.7e+46: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1e+38) tmp = x; elseif (z <= 1.7e+46) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1e+38) tmp = x; elseif (z <= 1.7e+46) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1e+38], x, If[LessEqual[z, 1.7e+46], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{+38}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.7 \cdot 10^{+46}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.99999999999999977e37 or 1.6999999999999999e46 < 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.0%
if -9.99999999999999977e37 < z < 1.6999999999999999e46Initial 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 54.1%
(FPCore (x y z) :precision binary64 (if (<= x -1.02e+144) (/ x (- z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.02e+144) {
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.02d+144)) 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.02e+144) {
tmp = x / -z;
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.02e+144: tmp = x / -z else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.02e+144) 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.02e+144) tmp = x / -z; else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.02e+144], N[(x / (-z)), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.02 \cdot 10^{+144}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.02000000000000008e144Initial program 100.0%
div-sub95.5%
sub-neg95.5%
distribute-frac-neg95.5%
+-commutative95.5%
associate-+r+95.5%
distribute-frac-neg95.5%
sub-neg95.5%
associate--r-95.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 99.5%
distribute-lft-out--99.5%
*-rgt-identity99.5%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
Taylor expanded in z around 0 72.9%
mul-1-neg72.9%
distribute-frac-neg72.9%
Simplified72.9%
if -1.02000000000000008e144 < x Initial program 100.0%
div-sub99.1%
sub-neg99.1%
distribute-frac-neg99.1%
+-commutative99.1%
associate-+r+99.1%
distribute-frac-neg99.1%
sub-neg99.1%
associate--r-99.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 79.4%
neg-mul-179.4%
Simplified79.4%
Taylor expanded in x around 0 79.4%
cancel-sign-sub-inv79.4%
metadata-eval79.4%
*-lft-identity79.4%
+-commutative79.4%
Simplified79.4%
Final simplification78.8%
(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 34.5%
herbie shell --seed 2024116
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))