
(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 (<= y -1.05e-56) (not (<= y 8e-107))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.05e-56) || !(y <= 8e-107)) {
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 <= (-1.05d-56)) .or. (.not. (y <= 8d-107))) 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 <= -1.05e-56) || !(y <= 8e-107)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.05e-56) or not (y <= 8e-107): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.05e-56) || !(y <= 8e-107)) 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 <= -1.05e-56) || ~((y <= 8e-107))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.05e-56], N[Not[LessEqual[y, 8e-107]], $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 -1.05 \cdot 10^{-56} \lor \neg \left(y \leq 8 \cdot 10^{-107}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.05000000000000003e-56 or 8e-107 < y Initial program 100.0%
div-sub99.3%
sub-neg99.3%
distribute-frac-neg99.3%
+-commutative99.3%
associate-+r+99.3%
distribute-frac-neg99.3%
sub-neg99.3%
associate--r-99.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 93.3%
neg-mul-193.3%
distribute-neg-frac293.3%
Simplified93.3%
if -1.05000000000000003e-56 < y < 8e-107Initial 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 89.2%
Final simplification91.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) x (if (<= z 0.07) (/ x (- z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x;
} else if (z <= 0.07) {
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 <= 0.07d0) 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 <= 0.07) {
tmp = x / -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x elif z <= 0.07: tmp = x / -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = x; elseif (z <= 0.07) tmp = Float64(x / Float64(-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 <= 0.07) tmp = x / -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], x, If[LessEqual[z, 0.07], N[(x / (-z)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 0.07:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 0.070000000000000007 < 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 69.3%
Taylor expanded in z around inf 67.8%
if -1 < z < 0.070000000000000007Initial 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 inf 47.9%
Taylor expanded in z around 0 46.9%
mul-1-neg46.9%
distribute-frac-neg246.9%
Simplified46.9%
Final simplification58.2%
(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-sub99.6%
sub-neg99.6%
distribute-frac-neg99.6%
+-commutative99.6%
associate-+r+99.6%
distribute-frac-neg99.6%
sub-neg99.6%
associate--r-99.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 59.5%
Final simplification59.5%
(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-sub99.6%
sub-neg99.6%
distribute-frac-neg99.6%
+-commutative99.6%
associate-+r+99.6%
distribute-frac-neg99.6%
sub-neg99.6%
associate--r-99.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 59.5%
Taylor expanded in z around inf 37.7%
Final simplification37.7%
herbie shell --seed 2024044
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))