
(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 (+ x -1.0)) (+ x 1.0)))
double code(double x) {
return (-2.0 / (x + -1.0)) / (x + 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-2.0d0) / (x + (-1.0d0))) / (x + 1.0d0)
end function
public static double code(double x) {
return (-2.0 / (x + -1.0)) / (x + 1.0);
}
def code(x): return (-2.0 / (x + -1.0)) / (x + 1.0)
function code(x) return Float64(Float64(-2.0 / Float64(x + -1.0)) / Float64(x + 1.0)) end
function tmp = code(x) tmp = (-2.0 / (x + -1.0)) / (x + 1.0); end
code[x_] := N[(N[(-2.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-2}{x + -1}}{x + 1}
\end{array}
Initial program 74.0%
sub-neg74.0%
+-commutative74.0%
distribute-neg-frac274.0%
neg-sub074.0%
associate-+l-74.0%
neg-sub074.0%
remove-double-neg74.0%
distribute-neg-in74.0%
sub-neg74.0%
distribute-neg-frac274.0%
sub-neg74.0%
+-commutative74.0%
unsub-neg74.0%
sub-neg74.0%
+-commutative74.0%
unsub-neg74.0%
metadata-eval74.0%
Simplified74.0%
sub-neg74.0%
distribute-neg-frac74.0%
metadata-eval74.0%
Applied egg-rr74.0%
Simplified99.0%
associate-/r*99.9%
div-inv99.8%
metadata-eval99.8%
+-commutative99.8%
flip-+99.0%
metadata-eval99.0%
metadata-eval99.0%
sub-neg99.0%
metadata-eval99.0%
neg-mul-199.0%
distribute-lft-in99.0%
+-commutative99.0%
mul-1-neg99.0%
distribute-neg-frac299.0%
+-commutative99.0%
flip--99.8%
frac-2neg99.8%
Applied egg-rr99.8%
associate-*l/99.9%
frac-2neg99.9%
metadata-eval99.9%
un-div-inv99.9%
flip--99.1%
metadata-eval99.1%
metadata-eval99.1%
+-commutative99.1%
distribute-neg-frac299.1%
+-commutative99.1%
distribute-neg-in99.1%
metadata-eval99.1%
sub-neg99.1%
flip-+99.9%
+-commutative99.9%
Applied egg-rr99.9%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ 2.0 (* 2.0 (* x x))) (/ (/ 2.0 x) (- -1.0 x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0 + (2.0 * (x * x));
} 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 <= 1.0d0) then
tmp = 2.0d0 + (2.0d0 * (x * x))
else
tmp = (2.0d0 / x) / ((-1.0d0) - x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0 + (2.0 * (x * x));
} else {
tmp = (2.0 / x) / (-1.0 - x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 + (2.0 * (x * x)) else: tmp = (2.0 / x) / (-1.0 - x) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(2.0 + Float64(2.0 * Float64(x * x))); 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 <= 1.0) tmp = 2.0 + (2.0 * (x * x)); else tmp = (2.0 / x) / (-1.0 - x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(2.0 + N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 / x), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2 + 2 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{-1 - x}\\
\end{array}
\end{array}
if x < 1Initial program 81.2%
sub-neg81.2%
+-commutative81.2%
distribute-neg-frac281.2%
neg-sub081.2%
associate-+l-81.2%
neg-sub081.2%
remove-double-neg81.2%
distribute-neg-in81.2%
sub-neg81.2%
distribute-neg-frac281.2%
sub-neg81.2%
+-commutative81.2%
unsub-neg81.2%
sub-neg81.2%
+-commutative81.2%
unsub-neg81.2%
metadata-eval81.2%
Simplified81.2%
Taylor expanded in x around 0 63.0%
unpow263.0%
Applied egg-rr63.0%
if 1 < x Initial program 55.0%
sub-neg55.0%
+-commutative55.0%
distribute-neg-frac255.0%
neg-sub055.0%
associate-+l-55.0%
neg-sub055.0%
remove-double-neg55.0%
distribute-neg-in55.0%
sub-neg55.0%
distribute-neg-frac255.0%
sub-neg55.0%
+-commutative55.0%
unsub-neg55.0%
sub-neg55.0%
+-commutative55.0%
unsub-neg55.0%
metadata-eval55.0%
Simplified55.0%
frac-sub57.5%
*-rgt-identity57.5%
metadata-eval57.5%
div-inv57.5%
associate-/r*57.6%
metadata-eval57.6%
div-inv57.6%
*-un-lft-identity57.6%
associate--l-63.1%
div-inv63.1%
metadata-eval63.1%
*-rgt-identity63.1%
div-inv63.1%
metadata-eval63.1%
*-rgt-identity63.1%
Applied egg-rr63.1%
Taylor expanded in x around inf 95.6%
(FPCore (x) :precision binary64 (if (<= x 0.85) (+ 2.0 (* 2.0 (* x x))) (/ -2.0 (* x (+ x -1.0)))))
double code(double x) {
double tmp;
if (x <= 0.85) {
tmp = 2.0 + (2.0 * (x * x));
} else {
tmp = -2.0 / (x * (x + -1.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.85d0) then
tmp = 2.0d0 + (2.0d0 * (x * x))
else
tmp = (-2.0d0) / (x * (x + (-1.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.85) {
tmp = 2.0 + (2.0 * (x * x));
} else {
tmp = -2.0 / (x * (x + -1.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.85: tmp = 2.0 + (2.0 * (x * x)) else: tmp = -2.0 / (x * (x + -1.0)) return tmp
function code(x) tmp = 0.0 if (x <= 0.85) tmp = Float64(2.0 + Float64(2.0 * Float64(x * x))); else tmp = Float64(-2.0 / Float64(x * Float64(x + -1.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.85) tmp = 2.0 + (2.0 * (x * x)); else tmp = -2.0 / (x * (x + -1.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.85], N[(2.0 + N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 / N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.85:\\
\;\;\;\;2 + 2 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x \cdot \left(x + -1\right)}\\
\end{array}
\end{array}
if x < 0.849999999999999978Initial program 81.2%
sub-neg81.2%
+-commutative81.2%
distribute-neg-frac281.2%
neg-sub081.2%
associate-+l-81.2%
neg-sub081.2%
remove-double-neg81.2%
distribute-neg-in81.2%
sub-neg81.2%
distribute-neg-frac281.2%
sub-neg81.2%
+-commutative81.2%
unsub-neg81.2%
sub-neg81.2%
+-commutative81.2%
unsub-neg81.2%
metadata-eval81.2%
Simplified81.2%
Taylor expanded in x around 0 63.0%
unpow263.0%
Applied egg-rr63.0%
if 0.849999999999999978 < x Initial program 55.0%
sub-neg55.0%
+-commutative55.0%
distribute-neg-frac255.0%
neg-sub055.0%
associate-+l-55.0%
neg-sub055.0%
remove-double-neg55.0%
distribute-neg-in55.0%
sub-neg55.0%
distribute-neg-frac255.0%
sub-neg55.0%
+-commutative55.0%
unsub-neg55.0%
sub-neg55.0%
+-commutative55.0%
unsub-neg55.0%
metadata-eval55.0%
Simplified55.0%
sub-neg55.0%
distribute-neg-frac55.0%
metadata-eval55.0%
Applied egg-rr55.0%
Simplified97.5%
Taylor expanded in x around inf 93.4%
(FPCore (x) :precision binary64 (/ -2.0 (* (+ x -1.0) (+ x 1.0))))
double code(double x) {
return -2.0 / ((x + -1.0) * (x + 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / ((x + (-1.0d0)) * (x + 1.0d0))
end function
public static double code(double x) {
return -2.0 / ((x + -1.0) * (x + 1.0));
}
def code(x): return -2.0 / ((x + -1.0) * (x + 1.0))
function code(x) return Float64(-2.0 / Float64(Float64(x + -1.0) * Float64(x + 1.0))) end
function tmp = code(x) tmp = -2.0 / ((x + -1.0) * (x + 1.0)); end
code[x_] := N[(-2.0 / N[(N[(x + -1.0), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{\left(x + -1\right) \cdot \left(x + 1\right)}
\end{array}
Initial program 74.0%
sub-neg74.0%
+-commutative74.0%
distribute-neg-frac274.0%
neg-sub074.0%
associate-+l-74.0%
neg-sub074.0%
remove-double-neg74.0%
distribute-neg-in74.0%
sub-neg74.0%
distribute-neg-frac274.0%
sub-neg74.0%
+-commutative74.0%
unsub-neg74.0%
sub-neg74.0%
+-commutative74.0%
unsub-neg74.0%
metadata-eval74.0%
Simplified74.0%
sub-neg74.0%
distribute-neg-frac74.0%
metadata-eval74.0%
Applied egg-rr74.0%
Simplified99.0%
Final simplification99.0%
(FPCore (x) :precision binary64 (/ -2.0 (- -1.0 x)))
double code(double x) {
return -2.0 / (-1.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / ((-1.0d0) - x)
end function
public static double code(double x) {
return -2.0 / (-1.0 - x);
}
def code(x): return -2.0 / (-1.0 - x)
function code(x) return Float64(-2.0 / Float64(-1.0 - x)) end
function tmp = code(x) tmp = -2.0 / (-1.0 - x); end
code[x_] := N[(-2.0 / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{-1 - x}
\end{array}
Initial program 74.0%
sub-neg74.0%
+-commutative74.0%
distribute-neg-frac274.0%
neg-sub074.0%
associate-+l-74.0%
neg-sub074.0%
remove-double-neg74.0%
distribute-neg-in74.0%
sub-neg74.0%
distribute-neg-frac274.0%
sub-neg74.0%
+-commutative74.0%
unsub-neg74.0%
sub-neg74.0%
+-commutative74.0%
unsub-neg74.0%
metadata-eval74.0%
Simplified74.0%
frac-sub75.0%
*-rgt-identity75.0%
metadata-eval75.0%
div-inv75.0%
associate-/r*75.0%
metadata-eval75.0%
div-inv75.0%
*-un-lft-identity75.0%
associate--l-78.3%
div-inv78.3%
metadata-eval78.3%
*-rgt-identity78.3%
div-inv78.3%
metadata-eval78.3%
*-rgt-identity78.3%
Applied egg-rr78.3%
Taylor expanded in x around 0 47.5%
(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.0%
sub-neg74.0%
+-commutative74.0%
distribute-neg-frac274.0%
neg-sub074.0%
associate-+l-74.0%
neg-sub074.0%
remove-double-neg74.0%
distribute-neg-in74.0%
sub-neg74.0%
distribute-neg-frac274.0%
sub-neg74.0%
+-commutative74.0%
unsub-neg74.0%
sub-neg74.0%
+-commutative74.0%
unsub-neg74.0%
metadata-eval74.0%
Simplified74.0%
Taylor expanded in x around 0 46.5%
herbie shell --seed 2024182
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))