
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -2.1e-75)
(and (not (<= x 1.18e-163))
(or (<= x 1.7e-119) (not (<= x 8.5e-50)))))
(- x (/ x z))
(/ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1e-75) || (!(x <= 1.18e-163) && ((x <= 1.7e-119) || !(x <= 8.5e-50)))) {
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 <= (-2.1d-75)) .or. (.not. (x <= 1.18d-163)) .and. (x <= 1.7d-119) .or. (.not. (x <= 8.5d-50))) 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 <= -2.1e-75) || (!(x <= 1.18e-163) && ((x <= 1.7e-119) || !(x <= 8.5e-50)))) {
tmp = x - (x / z);
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.1e-75) or (not (x <= 1.18e-163) and ((x <= 1.7e-119) or not (x <= 8.5e-50))): tmp = x - (x / z) else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.1e-75) || (!(x <= 1.18e-163) && ((x <= 1.7e-119) || !(x <= 8.5e-50)))) 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 <= -2.1e-75) || (~((x <= 1.18e-163)) && ((x <= 1.7e-119) || ~((x <= 8.5e-50))))) tmp = x - (x / z); else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.1e-75], And[N[Not[LessEqual[x, 1.18e-163]], $MachinePrecision], Or[LessEqual[x, 1.7e-119], N[Not[LessEqual[x, 8.5e-50]], $MachinePrecision]]]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{-75} \lor \neg \left(x \leq 1.18 \cdot 10^{-163}\right) \land \left(x \leq 1.7 \cdot 10^{-119} \lor \neg \left(x \leq 8.5 \cdot 10^{-50}\right)\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if x < -2.1000000000000001e-75 or 1.18000000000000004e-163 < x < 1.70000000000000012e-119 or 8.50000000000000012e-50 < x Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 83.8%
if -2.1000000000000001e-75 < x < 1.18000000000000004e-163 or 1.70000000000000012e-119 < x < 8.50000000000000012e-50Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 75.6%
Final simplification81.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- x (/ x z))))
(if (<= z -0.000136)
t_0
(if (<= z 0.065)
(/ (- y x) z)
(if (or (<= z 5.2e+82) (not (<= z 9e+119))) t_0 (/ y z))))))
double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (z <= -0.000136) {
tmp = t_0;
} else if (z <= 0.065) {
tmp = (y - x) / z;
} else if ((z <= 5.2e+82) || !(z <= 9e+119)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x - (x / z)
if (z <= (-0.000136d0)) then
tmp = t_0
else if (z <= 0.065d0) then
tmp = (y - x) / z
else if ((z <= 5.2d+82) .or. (.not. (z <= 9d+119))) then
tmp = t_0
else
tmp = y / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (z <= -0.000136) {
tmp = t_0;
} else if (z <= 0.065) {
tmp = (y - x) / z;
} else if ((z <= 5.2e+82) || !(z <= 9e+119)) {
tmp = t_0;
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x / z) tmp = 0 if z <= -0.000136: tmp = t_0 elif z <= 0.065: tmp = (y - x) / z elif (z <= 5.2e+82) or not (z <= 9e+119): tmp = t_0 else: tmp = y / z return tmp
function code(x, y, z) t_0 = Float64(x - Float64(x / z)) tmp = 0.0 if (z <= -0.000136) tmp = t_0; elseif (z <= 0.065) tmp = Float64(Float64(y - x) / z); elseif ((z <= 5.2e+82) || !(z <= 9e+119)) tmp = t_0; else tmp = Float64(y / z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x - (x / z); tmp = 0.0; if (z <= -0.000136) tmp = t_0; elseif (z <= 0.065) tmp = (y - x) / z; elseif ((z <= 5.2e+82) || ~((z <= 9e+119))) tmp = t_0; else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -0.000136], t$95$0, If[LessEqual[z, 0.065], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], If[Or[LessEqual[z, 5.2e+82], N[Not[LessEqual[z, 9e+119]], $MachinePrecision]], t$95$0, N[(y / z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \frac{x}{z}\\
\mathbf{if}\;z \leq -0.000136:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.065:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{+82} \lor \neg \left(z \leq 9 \cdot 10^{+119}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if z < -1.36e-4 or 0.065000000000000002 < z < 5.1999999999999997e82 or 9.00000000000000039e119 < z Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 71.7%
if -1.36e-4 < z < 0.065000000000000002Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in z around 0 98.3%
if 5.1999999999999997e82 < z < 9.00000000000000039e119Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification85.3%
(FPCore (x y z)
:precision binary64
(if (<= z -0.000136)
x
(if (or (<= z 190.0) (and (not (<= z 2.3e+91)) (<= z 1.35e+121)))
(/ y z)
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.000136) {
tmp = x;
} else if ((z <= 190.0) || (!(z <= 2.3e+91) && (z <= 1.35e+121))) {
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 <= (-0.000136d0)) then
tmp = x
else if ((z <= 190.0d0) .or. (.not. (z <= 2.3d+91)) .and. (z <= 1.35d+121)) 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 <= -0.000136) {
tmp = x;
} else if ((z <= 190.0) || (!(z <= 2.3e+91) && (z <= 1.35e+121))) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.000136: tmp = x elif (z <= 190.0) or (not (z <= 2.3e+91) and (z <= 1.35e+121)): tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.000136) tmp = x; elseif ((z <= 190.0) || (!(z <= 2.3e+91) && (z <= 1.35e+121))) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.000136) tmp = x; elseif ((z <= 190.0) || (~((z <= 2.3e+91)) && (z <= 1.35e+121))) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.000136], x, If[Or[LessEqual[z, 190.0], And[N[Not[LessEqual[z, 2.3e+91]], $MachinePrecision], LessEqual[z, 1.35e+121]]], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.000136:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 190 \lor \neg \left(z \leq 2.3 \cdot 10^{+91}\right) \land z \leq 1.35 \cdot 10^{+121}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.36e-4 or 190 < z < 2.29999999999999991e91 or 1.3500000000000001e121 < z Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 69.8%
if -1.36e-4 < z < 190 or 2.29999999999999991e91 < z < 1.3500000000000001e121Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 50.0%
Final simplification59.8%
(FPCore (x y z) :precision binary64 (if (<= z -0.000136) x (if (<= z -3.4e-191) (/ y z) (if (<= z 0.06) (/ (- x) z) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.000136) {
tmp = x;
} else if (z <= -3.4e-191) {
tmp = y / z;
} else if (z <= 0.06) {
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 <= (-0.000136d0)) then
tmp = x
else if (z <= (-3.4d-191)) then
tmp = y / z
else if (z <= 0.06d0) 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 <= -0.000136) {
tmp = x;
} else if (z <= -3.4e-191) {
tmp = y / z;
} else if (z <= 0.06) {
tmp = -x / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.000136: tmp = x elif z <= -3.4e-191: tmp = y / z elif z <= 0.06: tmp = -x / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.000136) tmp = x; elseif (z <= -3.4e-191) tmp = Float64(y / z); elseif (z <= 0.06) tmp = Float64(Float64(-x) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.000136) tmp = x; elseif (z <= -3.4e-191) tmp = y / z; elseif (z <= 0.06) tmp = -x / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.000136], x, If[LessEqual[z, -3.4e-191], N[(y / z), $MachinePrecision], If[LessEqual[z, 0.06], N[((-x) / z), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.000136:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -3.4 \cdot 10^{-191}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 0.06:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.36e-4 or 0.059999999999999998 < z Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 65.9%
if -1.36e-4 < z < -3.39999999999999994e-191Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 59.7%
if -3.39999999999999994e-191 < z < 0.059999999999999998Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 65.4%
Taylor expanded in z around 0 63.5%
mul-1-neg63.5%
Simplified63.5%
Final simplification64.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 0.06))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 0.06)) {
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 <= 0.06d0))) 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 <= 0.06)) {
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 <= 0.06): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 0.06)) 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 <= 0.06))) 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, 0.06]], $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 0.06\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 0.059999999999999998 < z Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 98.8%
neg-mul-198.8%
distribute-neg-frac98.8%
Simplified98.8%
if -1 < z < 0.059999999999999998Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in z around 0 97.8%
Final simplification98.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%
remove-double-neg100.0%
neg-mul-1100.0%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
distribute-frac-neg100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 35.6%
Final simplification35.6%
herbie shell --seed 2024034
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))