
(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 5 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%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.9e+93) (not (<= x 8e-28))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.9e+93) || !(x <= 8e-28)) {
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 <= (-5.9d+93)) .or. (.not. (x <= 8d-28))) 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 <= -5.9e+93) || !(x <= 8e-28)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.9e+93) or not (x <= 8e-28): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.9e+93) || !(x <= 8e-28)) 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 <= -5.9e+93) || ~((x <= 8e-28))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.9e+93], N[Not[LessEqual[x, 8e-28]], $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 -5.9 \cdot 10^{+93} \lor \neg \left(x \leq 8 \cdot 10^{-28}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -5.90000000000000008e93 or 7.99999999999999977e-28 < x Initial program 100.0%
div-sub95.6%
associate-+r-95.6%
remove-double-neg95.6%
distribute-frac-neg95.6%
unsub-neg95.6%
associate--r+95.6%
+-commutative95.6%
distribute-frac-neg95.6%
sub-neg95.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 89.2%
if -5.90000000000000008e93 < x < 7.99999999999999977e-28Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 86.2%
neg-mul-186.2%
distribute-neg-frac86.2%
Simplified86.2%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) x (if (<= z 1.0) (/ (- x) z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x;
} 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 <= (-1.0d0)) then
tmp = x
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 <= -1.0) {
tmp = x;
} else if (z <= 1.0) {
tmp = -x / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x elif z <= 1.0: tmp = -x / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = x; 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 <= -1.0) tmp = x; elseif (z <= 1.0) tmp = -x / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], x, If[LessEqual[z, 1.0], N[((-x) / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 65.6%
Taylor expanded in z around inf 64.8%
if -1 < z < 1Initial program 100.0%
div-sub96.3%
associate-+r-96.3%
remove-double-neg96.3%
distribute-frac-neg96.3%
unsub-neg96.3%
associate--r+96.3%
+-commutative96.3%
distribute-frac-neg96.3%
sub-neg96.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 52.2%
Taylor expanded in z around 0 50.9%
mul-1-neg50.9%
distribute-frac-neg50.9%
Simplified50.9%
Final simplification57.3%
(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.0%
associate-+r-98.0%
remove-double-neg98.0%
distribute-frac-neg98.0%
unsub-neg98.0%
associate--r+98.0%
+-commutative98.0%
distribute-frac-neg98.0%
sub-neg98.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 58.4%
Final simplification58.4%
(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.0%
associate-+r-98.0%
remove-double-neg98.0%
distribute-frac-neg98.0%
unsub-neg98.0%
associate--r+98.0%
+-commutative98.0%
distribute-frac-neg98.0%
sub-neg98.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 58.4%
Taylor expanded in z around inf 31.7%
Final simplification31.7%
herbie shell --seed 2024024
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))