
(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.2)
x
(if (<= z -1.12e-77)
(/ y z)
(if (<= z 9.5e-297) (/ x (- z)) (if (<= z 1.95e+76) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2) {
tmp = x;
} else if (z <= -1.12e-77) {
tmp = y / z;
} else if (z <= 9.5e-297) {
tmp = x / -z;
} else if (z <= 1.95e+76) {
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.2d0)) then
tmp = x
else if (z <= (-1.12d-77)) then
tmp = y / z
else if (z <= 9.5d-297) then
tmp = x / -z
else if (z <= 1.95d+76) 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.2) {
tmp = x;
} else if (z <= -1.12e-77) {
tmp = y / z;
} else if (z <= 9.5e-297) {
tmp = x / -z;
} else if (z <= 1.95e+76) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2: tmp = x elif z <= -1.12e-77: tmp = y / z elif z <= 9.5e-297: tmp = x / -z elif z <= 1.95e+76: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2) tmp = x; elseif (z <= -1.12e-77) tmp = Float64(y / z); elseif (z <= 9.5e-297) tmp = Float64(x / Float64(-z)); elseif (z <= 1.95e+76) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.2) tmp = x; elseif (z <= -1.12e-77) tmp = y / z; elseif (z <= 9.5e-297) tmp = x / -z; elseif (z <= 1.95e+76) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2], x, If[LessEqual[z, -1.12e-77], N[(y / z), $MachinePrecision], If[LessEqual[z, 9.5e-297], N[(x / (-z)), $MachinePrecision], If[LessEqual[z, 1.95e+76], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.12 \cdot 10^{-77}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 9.5 \cdot 10^{-297}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{elif}\;z \leq 1.95 \cdot 10^{+76}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.2000000000000002 or 1.94999999999999995e76 < 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.6%
if -2.2000000000000002 < z < -1.12000000000000009e-77 or 9.5000000000000005e-297 < z < 1.94999999999999995e76Initial program 100.0%
div-sub97.0%
sub-neg97.0%
distribute-frac-neg97.0%
+-commutative97.0%
associate-+r+97.0%
distribute-frac-neg97.0%
sub-neg97.0%
associate--r-97.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 58.1%
if -1.12000000000000009e-77 < z < 9.5000000000000005e-297Initial program 100.0%
div-sub88.9%
sub-neg88.9%
distribute-frac-neg88.9%
+-commutative88.9%
associate-+r+88.9%
distribute-frac-neg88.9%
sub-neg88.9%
associate--r-88.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 65.1%
Taylor expanded in z around 0 65.1%
mul-1-neg65.1%
distribute-frac-neg65.1%
Simplified65.1%
Final simplification66.8%
(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 97.3%
neg-mul-197.3%
distribute-neg-frac97.3%
Simplified97.3%
sub-neg97.3%
+-commutative97.3%
distribute-frac-neg97.3%
remove-double-neg97.3%
Applied egg-rr97.3%
if -1 < z < 1Initial 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 z around 0 99.7%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.9e-79) (not (<= x 8.8e+89))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.9e-79) || !(x <= 8.8e+89)) {
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 <= (-2.9d-79)) .or. (.not. (x <= 8.8d+89))) 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 <= -2.9e-79) || !(x <= 8.8e+89)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.9e-79) or not (x <= 8.8e+89): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.9e-79) || !(x <= 8.8e+89)) 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 <= -2.9e-79) || ~((x <= 8.8e+89))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.9e-79], N[Not[LessEqual[x, 8.8e+89]], $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 -2.9 \cdot 10^{-79} \lor \neg \left(x \leq 8.8 \cdot 10^{+89}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -2.9000000000000001e-79 or 8.8000000000000001e89 < x Initial 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 x around inf 85.5%
if -2.9000000000000001e-79 < x < 8.8000000000000001e89Initial 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 88.7%
neg-mul-188.7%
distribute-neg-frac88.7%
Simplified88.7%
sub-neg88.7%
+-commutative88.7%
distribute-frac-neg88.7%
remove-double-neg88.7%
Applied egg-rr88.7%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.26e-77) (not (<= z 8e-268))) (+ x (/ y z)) (/ x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.26e-77) || !(z <= 8e-268)) {
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 ((z <= (-1.26d-77)) .or. (.not. (z <= 8d-268))) 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 ((z <= -1.26e-77) || !(z <= 8e-268)) {
tmp = x + (y / z);
} else {
tmp = x / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.26e-77) or not (z <= 8e-268): tmp = x + (y / z) else: tmp = x / -z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.26e-77) || !(z <= 8e-268)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(x / Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.26e-77) || ~((z <= 8e-268))) tmp = x + (y / z); else tmp = x / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.26e-77], N[Not[LessEqual[z, 8e-268]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.26 \cdot 10^{-77} \lor \neg \left(z \leq 8 \cdot 10^{-268}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-z}\\
\end{array}
\end{array}
if z < -1.2599999999999999e-77 or 7.99999999999999966e-268 < z Initial program 100.0%
div-sub99.0%
sub-neg99.0%
distribute-frac-neg99.0%
+-commutative99.0%
associate-+r+99.0%
distribute-frac-neg99.0%
sub-neg99.0%
associate--r-99.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 82.4%
neg-mul-182.4%
distribute-neg-frac82.4%
Simplified82.4%
sub-neg82.4%
+-commutative82.4%
distribute-frac-neg82.4%
remove-double-neg82.4%
Applied egg-rr82.4%
if -1.2599999999999999e-77 < z < 7.99999999999999966e-268Initial program 100.0%
div-sub88.5%
sub-neg88.5%
distribute-frac-neg88.5%
+-commutative88.5%
associate-+r+88.5%
distribute-frac-neg88.5%
sub-neg88.5%
associate--r-88.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 64.3%
Taylor expanded in z around 0 64.3%
mul-1-neg64.3%
distribute-frac-neg64.3%
Simplified64.3%
Final simplification78.1%
(FPCore (x y z) :precision binary64 (if (<= z -2.2) x (if (<= z 5.5e+76) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2) {
tmp = x;
} else if (z <= 5.5e+76) {
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.2d0)) then
tmp = x
else if (z <= 5.5d+76) 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.2) {
tmp = x;
} else if (z <= 5.5e+76) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2: tmp = x elif z <= 5.5e+76: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2) tmp = x; elseif (z <= 5.5e+76) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.2) tmp = x; elseif (z <= 5.5e+76) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2], x, If[LessEqual[z, 5.5e+76], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{+76}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.2000000000000002 or 5.5000000000000001e76 < 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.6%
if -2.2000000000000002 < z < 5.5000000000000001e76Initial 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 x around 0 51.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-sub96.5%
sub-neg96.5%
distribute-frac-neg96.5%
+-commutative96.5%
associate-+r+96.5%
distribute-frac-neg96.5%
sub-neg96.5%
associate--r-96.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 34.9%
herbie shell --seed 2024118
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))