
(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 (or (<= x -15500.0)
(and (not (<= x -4.5e-158))
(or (<= x -4e-204) (not (<= x 5.8e-130)))))
(- x (/ x z))
(/ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -15500.0) || (!(x <= -4.5e-158) && ((x <= -4e-204) || !(x <= 5.8e-130)))) {
tmp = x - (x / z);
} else {
tmp = 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 <= (-15500.0d0)) .or. (.not. (x <= (-4.5d-158))) .and. (x <= (-4d-204)) .or. (.not. (x <= 5.8d-130))) then
tmp = x - (x / z)
else
tmp = y / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -15500.0) || (!(x <= -4.5e-158) && ((x <= -4e-204) || !(x <= 5.8e-130)))) {
tmp = x - (x / z);
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -15500.0) or (not (x <= -4.5e-158) and ((x <= -4e-204) or not (x <= 5.8e-130))): tmp = x - (x / z) else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -15500.0) || (!(x <= -4.5e-158) && ((x <= -4e-204) || !(x <= 5.8e-130)))) tmp = Float64(x - Float64(x / z)); else tmp = Float64(y / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -15500.0) || (~((x <= -4.5e-158)) && ((x <= -4e-204) || ~((x <= 5.8e-130))))) tmp = x - (x / z); else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -15500.0], And[N[Not[LessEqual[x, -4.5e-158]], $MachinePrecision], Or[LessEqual[x, -4e-204], N[Not[LessEqual[x, 5.8e-130]], $MachinePrecision]]]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -15500 \lor \neg \left(x \leq -4.5 \cdot 10^{-158}\right) \land \left(x \leq -4 \cdot 10^{-204} \lor \neg \left(x \leq 5.8 \cdot 10^{-130}\right)\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if x < -15500 or -4.5e-158 < x < -4e-204 or 5.8e-130 < x Initial program 100.0%
div-sub95.8%
sub-neg95.8%
distribute-frac-neg95.8%
+-commutative95.8%
associate-+r+95.8%
distribute-frac-neg95.8%
sub-neg95.8%
associate--r-95.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 78.9%
if -15500 < x < -4.5e-158 or -4e-204 < x < 5.8e-130Initial 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 78.2%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (<= z -4e+25) x (if (<= z 9.5e-261) (/ y z) (if (<= z 2.3) (/ x (- z)) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4e+25) {
tmp = x;
} else if (z <= 9.5e-261) {
tmp = y / z;
} else if (z <= 2.3) {
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 <= (-4d+25)) then
tmp = x
else if (z <= 9.5d-261) then
tmp = y / z
else if (z <= 2.3d0) 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 <= -4e+25) {
tmp = x;
} else if (z <= 9.5e-261) {
tmp = y / z;
} else if (z <= 2.3) {
tmp = x / -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4e+25: tmp = x elif z <= 9.5e-261: tmp = y / z elif z <= 2.3: tmp = x / -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4e+25) tmp = x; elseif (z <= 9.5e-261) tmp = Float64(y / z); elseif (z <= 2.3) tmp = Float64(x / Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4e+25) tmp = x; elseif (z <= 9.5e-261) tmp = y / z; elseif (z <= 2.3) tmp = x / -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4e+25], x, If[LessEqual[z, 9.5e-261], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.3], N[(x / (-z)), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+25}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 9.5 \cdot 10^{-261}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.3:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.00000000000000036e25 or 2.2999999999999998 < 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 72.7%
if -4.00000000000000036e25 < z < 9.5000000000000008e-261Initial program 100.0%
div-sub96.3%
sub-neg96.3%
distribute-frac-neg96.3%
+-commutative96.3%
associate-+r+96.3%
distribute-frac-neg96.3%
sub-neg96.3%
associate--r-96.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 63.5%
if 9.5000000000000008e-261 < z < 2.2999999999999998Initial program 99.9%
div-sub92.2%
sub-neg92.2%
distribute-frac-neg92.2%
+-commutative92.2%
associate-+r+92.2%
distribute-frac-neg92.2%
sub-neg92.2%
associate--r-92.2%
div-sub99.9%
Simplified99.9%
Taylor expanded in z around 0 98.7%
Taylor expanded in y around 0 60.2%
mul-1-neg60.2%
distribute-frac-neg60.2%
Simplified60.2%
Final simplification67.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 2.3))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 2.3)) {
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 <= 2.3d0))) 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 <= 2.3)) {
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 <= 2.3): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 2.3)) 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 <= 2.3))) 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, 2.3]], $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 2.3\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 2.2999999999999998 < 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 100.0%
neg-mul-1100.0%
distribute-neg-frac2100.0%
Simplified100.0%
if -1 < z < 2.2999999999999998Initial program 100.0%
div-sub94.7%
sub-neg94.7%
distribute-frac-neg94.7%
+-commutative94.7%
associate-+r+94.7%
distribute-frac-neg94.7%
sub-neg94.7%
associate--r-94.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.5%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.1e-7) (not (<= z 9.6e+18))) (- x (/ x z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.1e-7) || !(z <= 9.6e+18)) {
tmp = x - (x / 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.1d-7)) .or. (.not. (z <= 9.6d+18))) then
tmp = x - (x / 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.1e-7) || !(z <= 9.6e+18)) {
tmp = x - (x / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.1e-7) or not (z <= 9.6e+18): tmp = x - (x / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.1e-7) || !(z <= 9.6e+18)) tmp = Float64(x - Float64(x / 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.1e-7) || ~((z <= 9.6e+18))) tmp = x - (x / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.1e-7], N[Not[LessEqual[z, 9.6e+18]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{-7} \lor \neg \left(z \leq 9.6 \cdot 10^{+18}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1.1000000000000001e-7 or 9.6e18 < 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 inf 72.6%
if -1.1000000000000001e-7 < z < 9.6e18Initial 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 z around 0 99.5%
Final simplification86.2%
(FPCore (x y z) :precision binary64 (if (<= z -2.5e+21) x (if (<= z 4.45e+18) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.5e+21) {
tmp = x;
} else if (z <= 4.45e+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 <= (-2.5d+21)) then
tmp = x
else if (z <= 4.45d+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 <= -2.5e+21) {
tmp = x;
} else if (z <= 4.45e+18) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.5e+21: tmp = x elif z <= 4.45e+18: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.5e+21) tmp = x; elseif (z <= 4.45e+18) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.5e+21) tmp = x; elseif (z <= 4.45e+18) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.5e+21], x, If[LessEqual[z, 4.45e+18], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{+21}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.45 \cdot 10^{+18}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.5e21 or 4.45e18 < 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 72.7%
if -2.5e21 < z < 4.45e18Initial program 100.0%
div-sub94.7%
sub-neg94.7%
distribute-frac-neg94.7%
+-commutative94.7%
associate-+r+94.7%
distribute-frac-neg94.7%
sub-neg94.7%
associate--r-94.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 56.2%
(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.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-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 36.3%
herbie shell --seed 2024103
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))