
(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.6e-151) (not (<= y 1.4e+45))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.6e-151) || !(y <= 1.4e+45)) {
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.6d-151)) .or. (.not. (y <= 1.4d+45))) 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.6e-151) || !(y <= 1.4e+45)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.6e-151) or not (y <= 1.4e+45): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.6e-151) || !(y <= 1.4e+45)) 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.6e-151) || ~((y <= 1.4e+45))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.6e-151], N[Not[LessEqual[y, 1.4e+45]], $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.6 \cdot 10^{-151} \lor \neg \left(y \leq 1.4 \cdot 10^{+45}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.60000000000000011e-151 or 1.4e45 < y Initial program 100.0%
div-sub95.9%
sub-neg95.9%
distribute-frac-neg95.9%
+-commutative95.9%
associate-+r+95.9%
distribute-frac-neg95.9%
sub-neg95.9%
associate--r-95.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 86.1%
neg-mul-186.1%
distribute-neg-frac86.1%
Simplified86.1%
if -1.60000000000000011e-151 < y < 1.4e45Initial 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 87.6%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (<= z -380000.0) x (if (<= z 1.0) (/ x (- z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -380000.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 <= (-380000.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 <= -380000.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 <= -380000.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 <= -380000.0) tmp = x; elseif (z <= 1.0) tmp = Float64(x / Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -380000.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, -380000.0], x, If[LessEqual[z, 1.0], N[(x / (-z)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -380000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.8e5 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 inf 69.3%
Taylor expanded in z around inf 68.2%
if -3.8e5 < z < 1Initial 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 52.5%
Taylor expanded in z around 0 50.9%
associate-*r/50.9%
neg-mul-150.9%
Simplified50.9%
Final simplification58.6%
(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-sub97.7%
sub-neg97.7%
distribute-frac-neg97.7%
+-commutative97.7%
associate-+r+97.7%
distribute-frac-neg97.7%
sub-neg97.7%
associate--r-97.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 59.9%
Final simplification59.9%
(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.7%
sub-neg97.7%
distribute-frac-neg97.7%
+-commutative97.7%
associate-+r+97.7%
distribute-frac-neg97.7%
sub-neg97.7%
associate--r-97.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 59.9%
Taylor expanded in z around inf 31.8%
Final simplification31.8%
herbie shell --seed 2024053
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))