
(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 -2.7e+46) x (if (<= z -6.5e-37) (/ y z) (if (<= z 1.0) (/ (- x) z) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.7e+46) {
tmp = x;
} else if (z <= -6.5e-37) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = -x / 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.7d+46)) then
tmp = x
else if (z <= (-6.5d-37)) then
tmp = y / z
else if (z <= 1.0d0) then
tmp = -x / 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.7e+46) {
tmp = x;
} else if (z <= -6.5e-37) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = -x / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.7e+46: tmp = x elif z <= -6.5e-37: tmp = y / z elif z <= 1.0: tmp = -x / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.7e+46) tmp = x; elseif (z <= -6.5e-37) tmp = Float64(y / z); elseif (z <= 1.0) tmp = Float64(Float64(-x) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.7e+46) tmp = x; elseif (z <= -6.5e-37) tmp = y / z; elseif (z <= 1.0) tmp = -x / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.7e+46], x, If[LessEqual[z, -6.5e-37], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.0], N[((-x) / z), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{+46}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -6.5 \cdot 10^{-37}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.7000000000000002e46 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 z around inf 77.2%
if -2.7000000000000002e46 < z < -6.5000000000000001e-37Initial 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 0 60.8%
if -6.5000000000000001e-37 < z < 1Initial program 100.0%
div-sub93.7%
sub-neg93.7%
distribute-frac-neg93.7%
+-commutative93.7%
associate-+r+93.7%
distribute-frac-neg93.7%
sub-neg93.7%
associate--r-93.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.9%
Taylor expanded in y around 0 57.2%
neg-mul-157.2%
Simplified57.2%
(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.3%
neg-mul-199.3%
Simplified99.3%
Taylor expanded in x around 0 99.3%
cancel-sign-sub-inv99.3%
metadata-eval99.3%
*-lft-identity99.3%
+-commutative99.3%
Simplified99.3%
if -1 < z < 1Initial program 100.0%
div-sub94.2%
sub-neg94.2%
distribute-frac-neg94.2%
+-commutative94.2%
associate-+r+94.2%
distribute-frac-neg94.2%
sub-neg94.2%
associate--r-94.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.3%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.4e+48) (not (<= y 2.25e+30))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.4e+48) || !(y <= 2.25e+30)) {
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.4d+48)) .or. (.not. (y <= 2.25d+30))) 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.4e+48) || !(y <= 2.25e+30)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.4e+48) or not (y <= 2.25e+30): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.4e+48) || !(y <= 2.25e+30)) 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.4e+48) || ~((y <= 2.25e+30))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.4e+48], N[Not[LessEqual[y, 2.25e+30]], $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.4 \cdot 10^{+48} \lor \neg \left(y \leq 2.25 \cdot 10^{+30}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.4000000000000001e48 or 2.24999999999999997e30 < y Initial program 100.0%
div-sub93.3%
sub-neg93.3%
distribute-frac-neg93.3%
+-commutative93.3%
associate-+r+93.3%
distribute-frac-neg93.3%
sub-neg93.3%
associate--r-93.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 94.3%
neg-mul-194.3%
Simplified94.3%
Taylor expanded in x around 0 94.3%
cancel-sign-sub-inv94.3%
metadata-eval94.3%
*-lft-identity94.3%
+-commutative94.3%
Simplified94.3%
if -2.4000000000000001e48 < y < 2.24999999999999997e30Initial 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 87.7%
distribute-lft-out--87.7%
*-rgt-identity87.7%
associate-*r/87.9%
*-rgt-identity87.9%
Simplified87.9%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.8e-135) (not (<= y 1.76e-212))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.8e-135) || !(y <= 1.76e-212)) {
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 <= (-3.8d-135)) .or. (.not. (y <= 1.76d-212))) 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 <= -3.8e-135) || !(y <= 1.76e-212)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.8e-135) or not (y <= 1.76e-212): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.8e-135) || !(y <= 1.76e-212)) 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 <= -3.8e-135) || ~((y <= 1.76e-212))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.8e-135], N[Not[LessEqual[y, 1.76e-212]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{-135} \lor \neg \left(y \leq 1.76 \cdot 10^{-212}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if y < -3.8000000000000003e-135 or 1.76000000000000008e-212 < y Initial program 100.0%
div-sub96.0%
sub-neg96.0%
distribute-frac-neg96.0%
+-commutative96.0%
associate-+r+96.0%
distribute-frac-neg96.0%
sub-neg96.0%
associate--r-96.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 83.0%
neg-mul-183.0%
Simplified83.0%
Taylor expanded in x around 0 83.0%
cancel-sign-sub-inv83.0%
metadata-eval83.0%
*-lft-identity83.0%
+-commutative83.0%
Simplified83.0%
if -3.8000000000000003e-135 < y < 1.76000000000000008e-212Initial 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 z around 0 69.9%
Taylor expanded in y around 0 66.7%
neg-mul-166.7%
Simplified66.7%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (<= z -5.5e+42) x (if (<= z 1.4e+33) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.5e+42) {
tmp = x;
} else if (z <= 1.4e+33) {
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 <= (-5.5d+42)) then
tmp = x
else if (z <= 1.4d+33) 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 <= -5.5e+42) {
tmp = x;
} else if (z <= 1.4e+33) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.5e+42: tmp = x elif z <= 1.4e+33: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.5e+42) tmp = x; elseif (z <= 1.4e+33) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.5e+42) tmp = x; elseif (z <= 1.4e+33) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.5e+42], x, If[LessEqual[z, 1.4e+33], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{+42}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{+33}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.50000000000000001e42 or 1.4e33 < 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 -5.50000000000000001e42 < z < 1.4e33Initial program 100.0%
div-sub94.6%
sub-neg94.6%
distribute-frac-neg94.6%
+-commutative94.6%
associate-+r+94.6%
distribute-frac-neg94.6%
sub-neg94.6%
associate--r-94.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 49.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-sub96.8%
sub-neg96.8%
distribute-frac-neg96.8%
+-commutative96.8%
associate-+r+96.8%
distribute-frac-neg96.8%
sub-neg96.8%
associate--r-96.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 35.7%
herbie shell --seed 2024157
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))