
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))
double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + 1.0d0)) - (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
def code(x): return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0))
function code(x) return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / Float64(x - 1.0))) end
function tmp = code(x) tmp = (1.0 / (x + 1.0)) - (1.0 / (x - 1.0)); end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 1} - \frac{1}{x - 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))
double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (x + 1.0d0)) - (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
def code(x): return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0))
function code(x) return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / Float64(x - 1.0))) end
function tmp = code(x) tmp = (1.0 / (x + 1.0)) - (1.0 / (x - 1.0)); end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 1} - \frac{1}{x - 1}
\end{array}
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ (/ -2.0 (- 1.0 x_m)) (- -1.0 x_m)))
x_m = fabs(x);
double code(double x_m) {
return (-2.0 / (1.0 - x_m)) / (-1.0 - x_m);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = ((-2.0d0) / (1.0d0 - x_m)) / ((-1.0d0) - x_m)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return (-2.0 / (1.0 - x_m)) / (-1.0 - x_m);
}
x_m = math.fabs(x) def code(x_m): return (-2.0 / (1.0 - x_m)) / (-1.0 - x_m)
x_m = abs(x) function code(x_m) return Float64(Float64(-2.0 / Float64(1.0 - x_m)) / Float64(-1.0 - x_m)) end
x_m = abs(x); function tmp = code(x_m) tmp = (-2.0 / (1.0 - x_m)) / (-1.0 - x_m); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(-2.0 / N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision] / N[(-1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{\frac{-2}{1 - x\_m}}{-1 - x\_m}
\end{array}
Initial program 76.8%
sub-neg76.8%
+-commutative76.8%
distribute-neg-frac276.8%
neg-sub076.8%
associate-+l-76.8%
neg-sub076.8%
remove-double-neg76.8%
distribute-neg-in76.8%
sub-neg76.8%
distribute-neg-frac276.8%
sub-neg76.8%
+-commutative76.8%
unsub-neg76.8%
sub-neg76.8%
+-commutative76.8%
unsub-neg76.8%
metadata-eval76.8%
Simplified76.8%
sub-neg76.8%
distribute-neg-frac76.8%
metadata-eval76.8%
Applied egg-rr76.8%
metadata-eval76.8%
distribute-neg-frac76.8%
unsub-neg76.8%
*-rgt-identity76.8%
*-inverses76.8%
associate-/r*54.1%
neg-mul-154.1%
times-frac76.8%
distribute-frac-neg276.8%
distribute-neg-frac76.8%
metadata-eval76.8%
distribute-lft-out--76.8%
*-inverses76.8%
div-sub77.4%
associate--r+80.6%
associate-*r/80.6%
associate-*l/80.6%
Simplified99.2%
associate-/r*99.9%
div-inv99.8%
Applied egg-rr99.8%
Applied egg-rr99.9%
Final simplification99.9%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.75) 2.0 (/ 2.0 (* x_m (- 1.0 x_m)))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.75) {
tmp = 2.0;
} else {
tmp = 2.0 / (x_m * (1.0 - x_m));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 0.75d0) then
tmp = 2.0d0
else
tmp = 2.0d0 / (x_m * (1.0d0 - x_m))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.75) {
tmp = 2.0;
} else {
tmp = 2.0 / (x_m * (1.0 - x_m));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.75: tmp = 2.0 else: tmp = 2.0 / (x_m * (1.0 - x_m)) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.75) tmp = 2.0; else tmp = Float64(2.0 / Float64(x_m * Float64(1.0 - x_m))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.75) tmp = 2.0; else tmp = 2.0 / (x_m * (1.0 - x_m)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.75], 2.0, N[(2.0 / N[(x$95$m * N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 0.75:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{x\_m \cdot \left(1 - x\_m\right)}\\
\end{array}
\end{array}
if x < 0.75Initial program 86.4%
sub-neg86.4%
+-commutative86.4%
distribute-neg-frac286.4%
neg-sub086.4%
associate-+l-86.4%
neg-sub086.4%
remove-double-neg86.4%
distribute-neg-in86.4%
sub-neg86.4%
distribute-neg-frac286.4%
sub-neg86.4%
+-commutative86.4%
unsub-neg86.4%
sub-neg86.4%
+-commutative86.4%
unsub-neg86.4%
metadata-eval86.4%
Simplified86.4%
Taylor expanded in x around 0 69.8%
if 0.75 < x Initial program 52.3%
sub-neg52.3%
+-commutative52.3%
distribute-neg-frac252.3%
neg-sub052.3%
associate-+l-52.3%
neg-sub052.3%
remove-double-neg52.3%
distribute-neg-in52.3%
sub-neg52.3%
distribute-neg-frac252.3%
sub-neg52.3%
+-commutative52.3%
unsub-neg52.3%
sub-neg52.3%
+-commutative52.3%
unsub-neg52.3%
metadata-eval52.3%
Simplified52.3%
flip--7.8%
associate-/r/7.7%
metadata-eval7.7%
pow27.7%
+-commutative7.7%
Applied egg-rr7.7%
associate-*l/7.6%
*-lft-identity7.6%
Simplified7.6%
clear-num7.8%
metadata-eval7.8%
unpow27.8%
+-commutative7.8%
flip--52.3%
frac-sub53.0%
*-un-lft-identity53.0%
*-commutative53.0%
*-un-lft-identity53.0%
associate--r+59.4%
*-commutative59.4%
associate-/r*59.6%
+-commutative59.6%
associate--r+53.0%
Applied egg-rr53.0%
Taylor expanded in x around inf 98.3%
*-un-lft-identity98.3%
Applied egg-rr98.3%
*-lft-identity98.3%
associate-/r*96.1%
Simplified96.1%
Final simplification77.2%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.75) 2.0 (/ (/ 2.0 x_m) (- 1.0 x_m))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.75) {
tmp = 2.0;
} else {
tmp = (2.0 / x_m) / (1.0 - x_m);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 0.75d0) then
tmp = 2.0d0
else
tmp = (2.0d0 / x_m) / (1.0d0 - x_m)
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.75) {
tmp = 2.0;
} else {
tmp = (2.0 / x_m) / (1.0 - x_m);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.75: tmp = 2.0 else: tmp = (2.0 / x_m) / (1.0 - x_m) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.75) tmp = 2.0; else tmp = Float64(Float64(2.0 / x_m) / Float64(1.0 - x_m)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.75) tmp = 2.0; else tmp = (2.0 / x_m) / (1.0 - x_m); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.75], 2.0, N[(N[(2.0 / x$95$m), $MachinePrecision] / N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 0.75:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x\_m}}{1 - x\_m}\\
\end{array}
\end{array}
if x < 0.75Initial program 86.4%
sub-neg86.4%
+-commutative86.4%
distribute-neg-frac286.4%
neg-sub086.4%
associate-+l-86.4%
neg-sub086.4%
remove-double-neg86.4%
distribute-neg-in86.4%
sub-neg86.4%
distribute-neg-frac286.4%
sub-neg86.4%
+-commutative86.4%
unsub-neg86.4%
sub-neg86.4%
+-commutative86.4%
unsub-neg86.4%
metadata-eval86.4%
Simplified86.4%
Taylor expanded in x around 0 69.8%
if 0.75 < x Initial program 52.3%
sub-neg52.3%
+-commutative52.3%
distribute-neg-frac252.3%
neg-sub052.3%
associate-+l-52.3%
neg-sub052.3%
remove-double-neg52.3%
distribute-neg-in52.3%
sub-neg52.3%
distribute-neg-frac252.3%
sub-neg52.3%
+-commutative52.3%
unsub-neg52.3%
sub-neg52.3%
+-commutative52.3%
unsub-neg52.3%
metadata-eval52.3%
Simplified52.3%
flip--7.8%
associate-/r/7.7%
metadata-eval7.7%
pow27.7%
+-commutative7.7%
Applied egg-rr7.7%
associate-*l/7.6%
*-lft-identity7.6%
Simplified7.6%
clear-num7.8%
metadata-eval7.8%
unpow27.8%
+-commutative7.8%
flip--52.3%
frac-sub53.0%
*-un-lft-identity53.0%
*-commutative53.0%
*-un-lft-identity53.0%
associate--r+59.4%
*-commutative59.4%
associate-/r*59.6%
+-commutative59.6%
associate--r+53.0%
Applied egg-rr53.0%
Taylor expanded in x around inf 98.3%
Final simplification77.8%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ -2.0 (* (- 1.0 x_m) (- -1.0 x_m))))
x_m = fabs(x);
double code(double x_m) {
return -2.0 / ((1.0 - x_m) * (-1.0 - x_m));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (-2.0d0) / ((1.0d0 - x_m) * ((-1.0d0) - x_m))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return -2.0 / ((1.0 - x_m) * (-1.0 - x_m));
}
x_m = math.fabs(x) def code(x_m): return -2.0 / ((1.0 - x_m) * (-1.0 - x_m))
x_m = abs(x) function code(x_m) return Float64(-2.0 / Float64(Float64(1.0 - x_m) * Float64(-1.0 - x_m))) end
x_m = abs(x); function tmp = code(x_m) tmp = -2.0 / ((1.0 - x_m) * (-1.0 - x_m)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(-2.0 / N[(N[(1.0 - x$95$m), $MachinePrecision] * N[(-1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{-2}{\left(1 - x\_m\right) \cdot \left(-1 - x\_m\right)}
\end{array}
Initial program 76.8%
sub-neg76.8%
+-commutative76.8%
distribute-neg-frac276.8%
neg-sub076.8%
associate-+l-76.8%
neg-sub076.8%
remove-double-neg76.8%
distribute-neg-in76.8%
sub-neg76.8%
distribute-neg-frac276.8%
sub-neg76.8%
+-commutative76.8%
unsub-neg76.8%
sub-neg76.8%
+-commutative76.8%
unsub-neg76.8%
metadata-eval76.8%
Simplified76.8%
sub-neg76.8%
distribute-neg-frac76.8%
metadata-eval76.8%
Applied egg-rr76.8%
metadata-eval76.8%
distribute-neg-frac76.8%
unsub-neg76.8%
*-rgt-identity76.8%
*-inverses76.8%
associate-/r*54.1%
neg-mul-154.1%
times-frac76.8%
distribute-frac-neg276.8%
distribute-neg-frac76.8%
metadata-eval76.8%
distribute-lft-out--76.8%
*-inverses76.8%
div-sub77.4%
associate--r+80.6%
associate-*r/80.6%
associate-*l/80.6%
Simplified99.2%
Final simplification99.2%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 1.0) 2.0 0.0))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 1.0) {
tmp = 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.0d0) then
tmp = 2.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 1.0) {
tmp = 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 1.0: tmp = 2.0 else: tmp = 0.0 return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 1.0) tmp = 2.0; else tmp = 0.0; end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 1.0) tmp = 2.0; else tmp = 0.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 1.0], 2.0, 0.0]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 1Initial program 86.4%
sub-neg86.4%
+-commutative86.4%
distribute-neg-frac286.4%
neg-sub086.4%
associate-+l-86.4%
neg-sub086.4%
remove-double-neg86.4%
distribute-neg-in86.4%
sub-neg86.4%
distribute-neg-frac286.4%
sub-neg86.4%
+-commutative86.4%
unsub-neg86.4%
sub-neg86.4%
+-commutative86.4%
unsub-neg86.4%
metadata-eval86.4%
Simplified86.4%
Taylor expanded in x around 0 69.8%
if 1 < x Initial program 52.3%
sub-neg52.3%
+-commutative52.3%
distribute-neg-frac252.3%
neg-sub052.3%
associate-+l-52.3%
neg-sub052.3%
remove-double-neg52.3%
distribute-neg-in52.3%
sub-neg52.3%
distribute-neg-frac252.3%
sub-neg52.3%
+-commutative52.3%
unsub-neg52.3%
sub-neg52.3%
+-commutative52.3%
unsub-neg52.3%
metadata-eval52.3%
Simplified52.3%
flip--7.8%
associate-/r/7.7%
metadata-eval7.7%
pow27.7%
+-commutative7.7%
Applied egg-rr7.7%
associate-*l/7.6%
*-lft-identity7.6%
Simplified7.6%
clear-num7.8%
metadata-eval7.8%
unpow27.8%
+-commutative7.8%
flip--52.3%
frac-sub53.0%
*-un-lft-identity53.0%
*-commutative53.0%
*-un-lft-identity53.0%
associate--r+59.4%
flip--56.7%
associate-/l/56.7%
metadata-eval56.7%
pow256.7%
Applied egg-rr56.7%
div-sub56.7%
unpow256.7%
+-commutative56.7%
associate--r-56.7%
+-inverses56.7%
metadata-eval56.7%
+-commutative56.7%
associate--r-50.2%
+-inverses50.2%
metadata-eval50.2%
metadata-eval50.2%
+-inverses50.3%
Simplified50.3%
Final simplification64.3%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 0.0)
x_m = fabs(x);
double code(double x_m) {
return 0.0;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = 0.0d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return 0.0;
}
x_m = math.fabs(x) def code(x_m): return 0.0
x_m = abs(x) function code(x_m) return 0.0 end
x_m = abs(x); function tmp = code(x_m) tmp = 0.0; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := 0.0
\begin{array}{l}
x_m = \left|x\right|
\\
0
\end{array}
Initial program 76.8%
sub-neg76.8%
+-commutative76.8%
distribute-neg-frac276.8%
neg-sub076.8%
associate-+l-76.8%
neg-sub076.8%
remove-double-neg76.8%
distribute-neg-in76.8%
sub-neg76.8%
distribute-neg-frac276.8%
sub-neg76.8%
+-commutative76.8%
unsub-neg76.8%
sub-neg76.8%
+-commutative76.8%
unsub-neg76.8%
metadata-eval76.8%
Simplified76.8%
flip--54.2%
associate-/r/54.1%
metadata-eval54.1%
pow254.1%
+-commutative54.1%
Applied egg-rr54.1%
associate-*l/54.1%
*-lft-identity54.1%
Simplified54.1%
clear-num54.2%
metadata-eval54.2%
unpow254.2%
+-commutative54.2%
flip--76.8%
frac-sub77.4%
*-un-lft-identity77.4%
*-commutative77.4%
*-un-lft-identity77.4%
associate--r+80.6%
flip--28.6%
associate-/l/28.6%
metadata-eval28.6%
pow228.6%
Applied egg-rr28.6%
div-sub28.6%
unpow228.6%
+-commutative28.6%
associate--r-28.6%
+-inverses28.6%
metadata-eval28.6%
+-commutative28.6%
associate--r-25.4%
+-inverses25.4%
metadata-eval25.4%
metadata-eval25.4%
+-inverses27.1%
Simplified27.1%
Final simplification27.1%
herbie shell --seed 2024112
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))