
(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}
(FPCore (x) :precision binary64 (/ (/ -2.0 (- -1.0 x)) (- 1.0 x)))
double code(double x) {
return (-2.0 / (-1.0 - x)) / (1.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-2.0d0) / ((-1.0d0) - x)) / (1.0d0 - x)
end function
public static double code(double x) {
return (-2.0 / (-1.0 - x)) / (1.0 - x);
}
def code(x): return (-2.0 / (-1.0 - x)) / (1.0 - x)
function code(x) return Float64(Float64(-2.0 / Float64(-1.0 - x)) / Float64(1.0 - x)) end
function tmp = code(x) tmp = (-2.0 / (-1.0 - x)) / (1.0 - x); end
code[x_] := N[(N[(-2.0 / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-2}{-1 - x}}{1 - x}
\end{array}
Initial program 74.8%
sub-neg74.8%
+-commutative74.8%
distribute-neg-frac274.8%
neg-sub074.8%
associate-+l-74.8%
neg-sub074.8%
remove-double-neg74.8%
distribute-neg-in74.8%
sub-neg74.8%
distribute-neg-frac274.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
metadata-eval74.8%
Simplified74.8%
sub-neg74.8%
distribute-neg-frac74.8%
metadata-eval74.8%
Applied egg-rr74.8%
metadata-eval74.8%
distribute-neg-frac74.8%
unsub-neg74.8%
*-rgt-identity74.8%
*-inverses74.8%
associate-/r*50.9%
*-commutative50.9%
*-lft-identity50.9%
associate-/r*74.8%
associate-*r/74.8%
associate-*l/74.8%
distribute-lft-out--74.8%
*-inverses74.8%
div-sub75.3%
associate--r+78.6%
*-commutative78.6%
times-frac78.5%
Simplified99.4%
expm1-log1p-u98.3%
expm1-undefine73.3%
Applied egg-rr73.3%
sub-neg73.3%
metadata-eval73.3%
metadata-eval73.3%
+-inverses73.3%
associate--l+73.3%
associate-+l-73.3%
metadata-eval73.3%
+-commutative73.3%
log1p-undefine73.7%
rem-exp-log74.5%
associate-+r+75.3%
metadata-eval75.3%
+-lft-identity75.3%
Simplified99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x 0.76) 2.0 (/ 2.0 (* x (- 1.0 x)))))
double code(double x) {
double tmp;
if (x <= 0.76) {
tmp = 2.0;
} else {
tmp = 2.0 / (x * (1.0 - x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.76d0) then
tmp = 2.0d0
else
tmp = 2.0d0 / (x * (1.0d0 - x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.76) {
tmp = 2.0;
} else {
tmp = 2.0 / (x * (1.0 - x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.76: tmp = 2.0 else: tmp = 2.0 / (x * (1.0 - x)) return tmp
function code(x) tmp = 0.0 if (x <= 0.76) tmp = 2.0; else tmp = Float64(2.0 / Float64(x * Float64(1.0 - x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.76) tmp = 2.0; else tmp = 2.0 / (x * (1.0 - x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.76], 2.0, N[(2.0 / N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.76:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{x \cdot \left(1 - x\right)}\\
\end{array}
\end{array}
if x < 0.76000000000000001Initial program 88.2%
sub-neg88.2%
+-commutative88.2%
distribute-neg-frac288.2%
neg-sub088.2%
associate-+l-88.2%
neg-sub088.2%
remove-double-neg88.2%
distribute-neg-in88.2%
sub-neg88.2%
distribute-neg-frac288.2%
sub-neg88.2%
+-commutative88.2%
unsub-neg88.2%
sub-neg88.2%
+-commutative88.2%
unsub-neg88.2%
metadata-eval88.2%
Simplified88.2%
Taylor expanded in x around 0 67.2%
if 0.76000000000000001 < x Initial program 44.1%
sub-neg44.1%
+-commutative44.1%
distribute-neg-frac244.1%
neg-sub044.1%
associate-+l-44.1%
neg-sub044.1%
remove-double-neg44.1%
distribute-neg-in44.1%
sub-neg44.1%
distribute-neg-frac244.1%
sub-neg44.1%
+-commutative44.1%
unsub-neg44.1%
sub-neg44.1%
+-commutative44.1%
unsub-neg44.1%
metadata-eval44.1%
Simplified44.1%
sub-neg44.1%
distribute-neg-frac44.1%
metadata-eval44.1%
Applied egg-rr44.1%
metadata-eval44.1%
distribute-neg-frac44.1%
unsub-neg44.1%
*-rgt-identity44.1%
*-inverses44.1%
associate-/r*7.2%
*-commutative7.2%
*-lft-identity7.2%
associate-/r*44.1%
associate-*r/44.1%
associate-*l/44.1%
distribute-lft-out--44.1%
*-inverses44.1%
div-sub44.6%
associate--r+51.9%
*-commutative51.9%
times-frac51.9%
Simplified98.6%
expm1-log1p-u98.6%
expm1-undefine43.6%
Applied egg-rr43.6%
sub-neg43.6%
metadata-eval43.6%
metadata-eval43.6%
+-inverses43.6%
associate--l+43.6%
associate-+l-43.6%
metadata-eval43.6%
+-commutative43.6%
log1p-undefine43.6%
rem-exp-log43.6%
associate-+r+44.6%
metadata-eval44.6%
+-lft-identity44.6%
Simplified99.7%
Taylor expanded in x around inf 99.2%
div-inv99.2%
*-un-lft-identity99.2%
times-frac99.2%
metadata-eval99.2%
Applied egg-rr99.2%
associate-/l/98.0%
associate-*r/98.0%
metadata-eval98.0%
*-commutative98.0%
Simplified98.0%
Final simplification76.6%
(FPCore (x) :precision binary64 (if (<= x 0.76) 2.0 (/ (/ 2.0 x) (- 1.0 x))))
double code(double x) {
double tmp;
if (x <= 0.76) {
tmp = 2.0;
} else {
tmp = (2.0 / x) / (1.0 - x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.76d0) then
tmp = 2.0d0
else
tmp = (2.0d0 / x) / (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.76) {
tmp = 2.0;
} else {
tmp = (2.0 / x) / (1.0 - x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.76: tmp = 2.0 else: tmp = (2.0 / x) / (1.0 - x) return tmp
function code(x) tmp = 0.0 if (x <= 0.76) tmp = 2.0; else tmp = Float64(Float64(2.0 / x) / Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.76) tmp = 2.0; else tmp = (2.0 / x) / (1.0 - x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.76], 2.0, N[(N[(2.0 / x), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.76:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{1 - x}\\
\end{array}
\end{array}
if x < 0.76000000000000001Initial program 88.2%
sub-neg88.2%
+-commutative88.2%
distribute-neg-frac288.2%
neg-sub088.2%
associate-+l-88.2%
neg-sub088.2%
remove-double-neg88.2%
distribute-neg-in88.2%
sub-neg88.2%
distribute-neg-frac288.2%
sub-neg88.2%
+-commutative88.2%
unsub-neg88.2%
sub-neg88.2%
+-commutative88.2%
unsub-neg88.2%
metadata-eval88.2%
Simplified88.2%
Taylor expanded in x around 0 67.2%
if 0.76000000000000001 < x Initial program 44.1%
sub-neg44.1%
+-commutative44.1%
distribute-neg-frac244.1%
neg-sub044.1%
associate-+l-44.1%
neg-sub044.1%
remove-double-neg44.1%
distribute-neg-in44.1%
sub-neg44.1%
distribute-neg-frac244.1%
sub-neg44.1%
+-commutative44.1%
unsub-neg44.1%
sub-neg44.1%
+-commutative44.1%
unsub-neg44.1%
metadata-eval44.1%
Simplified44.1%
sub-neg44.1%
distribute-neg-frac44.1%
metadata-eval44.1%
Applied egg-rr44.1%
metadata-eval44.1%
distribute-neg-frac44.1%
unsub-neg44.1%
*-rgt-identity44.1%
*-inverses44.1%
associate-/r*7.2%
*-commutative7.2%
*-lft-identity7.2%
associate-/r*44.1%
associate-*r/44.1%
associate-*l/44.1%
distribute-lft-out--44.1%
*-inverses44.1%
div-sub44.6%
associate--r+51.9%
*-commutative51.9%
times-frac51.9%
Simplified98.6%
expm1-log1p-u98.6%
expm1-undefine43.6%
Applied egg-rr43.6%
sub-neg43.6%
metadata-eval43.6%
metadata-eval43.6%
+-inverses43.6%
associate--l+43.6%
associate-+l-43.6%
metadata-eval43.6%
+-commutative43.6%
log1p-undefine43.6%
rem-exp-log43.6%
associate-+r+44.6%
metadata-eval44.6%
+-lft-identity44.6%
Simplified99.7%
Taylor expanded in x around inf 99.2%
Final simplification76.9%
(FPCore (x) :precision binary64 (/ -2.0 (* (- -1.0 x) (- 1.0 x))))
double code(double x) {
return -2.0 / ((-1.0 - x) * (1.0 - x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / (((-1.0d0) - x) * (1.0d0 - x))
end function
public static double code(double x) {
return -2.0 / ((-1.0 - x) * (1.0 - x));
}
def code(x): return -2.0 / ((-1.0 - x) * (1.0 - x))
function code(x) return Float64(-2.0 / Float64(Float64(-1.0 - x) * Float64(1.0 - x))) end
function tmp = code(x) tmp = -2.0 / ((-1.0 - x) * (1.0 - x)); end
code[x_] := N[(-2.0 / N[(N[(-1.0 - x), $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{\left(-1 - x\right) \cdot \left(1 - x\right)}
\end{array}
Initial program 74.8%
sub-neg74.8%
+-commutative74.8%
distribute-neg-frac274.8%
neg-sub074.8%
associate-+l-74.8%
neg-sub074.8%
remove-double-neg74.8%
distribute-neg-in74.8%
sub-neg74.8%
distribute-neg-frac274.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
metadata-eval74.8%
Simplified74.8%
sub-neg74.8%
distribute-neg-frac74.8%
metadata-eval74.8%
Applied egg-rr74.8%
metadata-eval74.8%
distribute-neg-frac74.8%
unsub-neg74.8%
*-rgt-identity74.8%
*-inverses74.8%
associate-/r*50.9%
*-commutative50.9%
*-lft-identity50.9%
associate-/r*74.8%
associate-*r/74.8%
associate-*l/74.8%
distribute-lft-out--74.8%
*-inverses74.8%
div-sub75.3%
associate--r+78.6%
*-commutative78.6%
times-frac78.5%
Simplified99.4%
Final simplification99.4%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 74.8%
sub-neg74.8%
+-commutative74.8%
distribute-neg-frac274.8%
neg-sub074.8%
associate-+l-74.8%
neg-sub074.8%
remove-double-neg74.8%
distribute-neg-in74.8%
sub-neg74.8%
distribute-neg-frac274.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
metadata-eval74.8%
Simplified74.8%
Taylor expanded in x around 0 47.3%
Taylor expanded in x around inf 10.2%
Final simplification10.2%
(FPCore (x) :precision binary64 2.0)
double code(double x) {
return 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0
end function
public static double code(double x) {
return 2.0;
}
def code(x): return 2.0
function code(x) return 2.0 end
function tmp = code(x) tmp = 2.0; end
code[x_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 74.8%
sub-neg74.8%
+-commutative74.8%
distribute-neg-frac274.8%
neg-sub074.8%
associate-+l-74.8%
neg-sub074.8%
remove-double-neg74.8%
distribute-neg-in74.8%
sub-neg74.8%
distribute-neg-frac274.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
sub-neg74.8%
+-commutative74.8%
unsub-neg74.8%
metadata-eval74.8%
Simplified74.8%
Taylor expanded in x around 0 47.5%
Final simplification47.5%
herbie shell --seed 2024077
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))