
(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 3 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 (/ (- x y) z)))
double code(double x, double y, double z) {
return x - ((x - y) / 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 - ((x - y) / z)
end function
public static double code(double x, double y, double z) {
return x - ((x - y) / z);
}
def code(x, y, z): return x - ((x - y) / z)
function code(x, y, z) return Float64(x - Float64(Float64(x - y) / z)) end
function tmp = code(x, y, z) tmp = x - ((x - y) / z); end
code[x_, y_, z_] := N[(x - N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{x - y}{z}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -7200.0) (not (<= x 2.45e+39))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7200.0) || !(x <= 2.45e+39)) {
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 <= (-7200.0d0)) .or. (.not. (x <= 2.45d+39))) 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 <= -7200.0) || !(x <= 2.45e+39)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7200.0) or not (x <= 2.45e+39): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7200.0) || !(x <= 2.45e+39)) 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 <= -7200.0) || ~((x <= 2.45e+39))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7200.0], N[Not[LessEqual[x, 2.45e+39]], $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 -7200 \lor \neg \left(x \leq 2.45 \cdot 10^{+39}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -7200 or 2.44999999999999994e39 < x 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 x around inf 90.7%
if -7200 < x < 2.44999999999999994e39Initial 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 89.5%
neg-mul-189.5%
distribute-neg-frac89.5%
Simplified89.5%
Final simplification90.0%
(FPCore (x y z) :precision binary64 (- x (/ x z)))
double code(double x, double y, double z) {
return x - (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 - (x / z)
end function
public static double code(double x, double y, double z) {
return x - (x / z);
}
def code(x, y, z): return x - (x / z)
function code(x, y, z) return Float64(x - Float64(x / z)) end
function tmp = code(x, y, z) tmp = x - (x / z); end
code[x_, y_, z_] := N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{x}{z}
\end{array}
Initial program 100.0%
div-sub98.4%
sub-neg98.4%
distribute-frac-neg98.4%
+-commutative98.4%
associate-+r+98.4%
distribute-frac-neg98.4%
sub-neg98.4%
associate--r-98.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 62.2%
Final simplification62.2%
herbie shell --seed 2024059
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))