
(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 9 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 80.1%
sub-neg80.1%
+-commutative80.1%
distribute-neg-frac280.1%
neg-sub080.1%
associate-+l-80.1%
neg-sub080.1%
remove-double-neg80.1%
distribute-neg-in80.1%
sub-neg80.1%
distribute-neg-frac280.1%
sub-neg80.1%
+-commutative80.1%
unsub-neg80.1%
sub-neg80.1%
+-commutative80.1%
unsub-neg80.1%
metadata-eval80.1%
Simplified80.1%
sub-neg80.1%
distribute-neg-frac80.1%
metadata-eval80.1%
Applied egg-rr80.1%
Simplified99.5%
associate-/r*99.9%
div-inv99.8%
metadata-eval99.8%
+-commutative99.8%
flip-+99.4%
sub-neg99.4%
metadata-eval99.4%
neg-mul-199.4%
distribute-lft-in99.4%
+-commutative99.4%
mul-1-neg99.4%
distribute-neg-frac299.4%
metadata-eval99.4%
metadata-eval99.4%
+-commutative99.4%
flip--99.8%
frac-2neg99.8%
Applied egg-rr99.8%
clear-num99.8%
un-div-inv99.9%
flip--99.5%
metadata-eval99.5%
metadata-eval99.5%
+-commutative99.5%
associate-/l/99.5%
neg-mul-199.5%
+-commutative99.5%
distribute-neg-in99.5%
metadata-eval99.5%
sub-neg99.5%
flip-+99.9%
+-commutative99.9%
Applied egg-rr99.9%
(FPCore (x) :precision binary64 (if (<= x 0.75) 2.0 (/ (/ -2.0 x) (+ x -1.0))))
double code(double x) {
double tmp;
if (x <= 0.75) {
tmp = 2.0;
} 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.75d0) then
tmp = 2.0d0
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.75) {
tmp = 2.0;
} else {
tmp = (-2.0 / x) / (x + -1.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.75: tmp = 2.0 else: tmp = (-2.0 / x) / (x + -1.0) return tmp
function code(x) tmp = 0.0 if (x <= 0.75) tmp = 2.0; else tmp = Float64(Float64(-2.0 / x) / Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.75) tmp = 2.0; else tmp = (-2.0 / x) / (x + -1.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.75], 2.0, N[(N[(-2.0 / x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.75:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-2}{x}}{x + -1}\\
\end{array}
\end{array}
if x < 0.75Initial program 89.4%
sub-neg89.4%
+-commutative89.4%
distribute-neg-frac289.4%
neg-sub089.4%
associate-+l-89.4%
neg-sub089.4%
remove-double-neg89.4%
distribute-neg-in89.4%
sub-neg89.4%
distribute-neg-frac289.4%
sub-neg89.4%
+-commutative89.4%
unsub-neg89.4%
sub-neg89.4%
+-commutative89.4%
unsub-neg89.4%
metadata-eval89.4%
Simplified89.4%
Taylor expanded in x around 0 69.4%
if 0.75 < x Initial program 51.8%
sub-neg51.8%
+-commutative51.8%
distribute-neg-frac251.8%
neg-sub051.8%
associate-+l-51.8%
neg-sub051.8%
remove-double-neg51.8%
distribute-neg-in51.8%
sub-neg51.8%
distribute-neg-frac251.8%
sub-neg51.8%
+-commutative51.8%
unsub-neg51.8%
sub-neg51.8%
+-commutative51.8%
unsub-neg51.8%
metadata-eval51.8%
Simplified51.8%
sub-neg51.8%
distribute-neg-frac51.8%
metadata-eval51.8%
Applied egg-rr51.8%
Simplified99.0%
Taylor expanded in x around inf 96.4%
div-inv96.4%
associate-/r*97.1%
Applied egg-rr97.1%
associate-/r*96.4%
associate-*r/96.4%
metadata-eval96.4%
associate-/r*97.1%
Simplified97.1%
(FPCore (x) :precision binary64 (if (<= x 0.75) 2.0 (/ -2.0 (* x (+ x -1.0)))))
double code(double x) {
double tmp;
if (x <= 0.75) {
tmp = 2.0;
} 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.75d0) then
tmp = 2.0d0
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.75) {
tmp = 2.0;
} else {
tmp = -2.0 / (x * (x + -1.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.75: tmp = 2.0 else: tmp = -2.0 / (x * (x + -1.0)) return tmp
function code(x) tmp = 0.0 if (x <= 0.75) tmp = 2.0; 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.75) tmp = 2.0; else tmp = -2.0 / (x * (x + -1.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.75], 2.0, N[(-2.0 / N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.75:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x \cdot \left(x + -1\right)}\\
\end{array}
\end{array}
if x < 0.75Initial program 89.4%
sub-neg89.4%
+-commutative89.4%
distribute-neg-frac289.4%
neg-sub089.4%
associate-+l-89.4%
neg-sub089.4%
remove-double-neg89.4%
distribute-neg-in89.4%
sub-neg89.4%
distribute-neg-frac289.4%
sub-neg89.4%
+-commutative89.4%
unsub-neg89.4%
sub-neg89.4%
+-commutative89.4%
unsub-neg89.4%
metadata-eval89.4%
Simplified89.4%
Taylor expanded in x around 0 69.4%
if 0.75 < x Initial program 51.8%
sub-neg51.8%
+-commutative51.8%
distribute-neg-frac251.8%
neg-sub051.8%
associate-+l-51.8%
neg-sub051.8%
remove-double-neg51.8%
distribute-neg-in51.8%
sub-neg51.8%
distribute-neg-frac251.8%
sub-neg51.8%
+-commutative51.8%
unsub-neg51.8%
sub-neg51.8%
+-commutative51.8%
unsub-neg51.8%
metadata-eval51.8%
Simplified51.8%
sub-neg51.8%
distribute-neg-frac51.8%
metadata-eval51.8%
Applied egg-rr51.8%
Simplified99.0%
Taylor expanded in x around inf 96.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(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 80.1%
sub-neg80.1%
+-commutative80.1%
distribute-neg-frac280.1%
neg-sub080.1%
associate-+l-80.1%
neg-sub080.1%
remove-double-neg80.1%
distribute-neg-in80.1%
sub-neg80.1%
distribute-neg-frac280.1%
sub-neg80.1%
+-commutative80.1%
unsub-neg80.1%
sub-neg80.1%
+-commutative80.1%
unsub-neg80.1%
metadata-eval80.1%
Simplified80.1%
sub-neg80.1%
distribute-neg-frac80.1%
metadata-eval80.1%
Applied egg-rr80.1%
Simplified99.5%
associate-/r*99.9%
div-inv99.8%
metadata-eval99.8%
+-commutative99.8%
flip-+99.4%
sub-neg99.4%
metadata-eval99.4%
neg-mul-199.4%
distribute-lft-in99.4%
+-commutative99.4%
mul-1-neg99.4%
distribute-neg-frac299.4%
metadata-eval99.4%
metadata-eval99.4%
+-commutative99.4%
flip--99.8%
frac-2neg99.8%
Applied egg-rr99.8%
associate-*l/99.9%
clear-num99.9%
un-div-inv99.9%
flip--99.5%
metadata-eval99.5%
metadata-eval99.5%
+-commutative99.5%
associate-/l/99.5%
neg-mul-199.5%
+-commutative99.5%
distribute-neg-in99.5%
metadata-eval99.5%
sub-neg99.5%
flip-+99.9%
+-commutative99.9%
Applied egg-rr99.9%
(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 80.1%
sub-neg80.1%
+-commutative80.1%
distribute-neg-frac280.1%
neg-sub080.1%
associate-+l-80.1%
neg-sub080.1%
remove-double-neg80.1%
distribute-neg-in80.1%
sub-neg80.1%
distribute-neg-frac280.1%
sub-neg80.1%
+-commutative80.1%
unsub-neg80.1%
sub-neg80.1%
+-commutative80.1%
unsub-neg80.1%
metadata-eval80.1%
Simplified80.1%
sub-neg80.1%
distribute-neg-frac80.1%
metadata-eval80.1%
Applied egg-rr80.1%
Simplified99.5%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ -1.0 x)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = -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
else
tmp = (-1.0d0) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = -1.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = -1.0 / x return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(-1.0 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = -1.0 / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(-1.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{x}\\
\end{array}
\end{array}
if x < 1Initial program 89.4%
sub-neg89.4%
+-commutative89.4%
distribute-neg-frac289.4%
neg-sub089.4%
associate-+l-89.4%
neg-sub089.4%
remove-double-neg89.4%
distribute-neg-in89.4%
sub-neg89.4%
distribute-neg-frac289.4%
sub-neg89.4%
+-commutative89.4%
unsub-neg89.4%
sub-neg89.4%
+-commutative89.4%
unsub-neg89.4%
metadata-eval89.4%
Simplified89.4%
Taylor expanded in x around 0 69.4%
if 1 < x Initial program 51.8%
sub-neg51.8%
+-commutative51.8%
distribute-neg-frac251.8%
neg-sub051.8%
associate-+l-51.8%
neg-sub051.8%
remove-double-neg51.8%
distribute-neg-in51.8%
sub-neg51.8%
distribute-neg-frac251.8%
sub-neg51.8%
+-commutative51.8%
unsub-neg51.8%
sub-neg51.8%
+-commutative51.8%
unsub-neg51.8%
metadata-eval51.8%
Simplified51.8%
Taylor expanded in x around 0 2.7%
Taylor expanded in x around inf 2.7%
Taylor expanded in x around 0 6.7%
(FPCore (x) :precision binary64 (/ -2.0 (+ x -1.0)))
double code(double x) {
return -2.0 / (x + -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / (x + (-1.0d0))
end function
public static double code(double x) {
return -2.0 / (x + -1.0);
}
def code(x): return -2.0 / (x + -1.0)
function code(x) return Float64(-2.0 / Float64(x + -1.0)) end
function tmp = code(x) tmp = -2.0 / (x + -1.0); end
code[x_] := N[(-2.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{x + -1}
\end{array}
Initial program 80.1%
sub-neg80.1%
+-commutative80.1%
distribute-neg-frac280.1%
neg-sub080.1%
associate-+l-80.1%
neg-sub080.1%
remove-double-neg80.1%
distribute-neg-in80.1%
sub-neg80.1%
distribute-neg-frac280.1%
sub-neg80.1%
+-commutative80.1%
unsub-neg80.1%
sub-neg80.1%
+-commutative80.1%
unsub-neg80.1%
metadata-eval80.1%
Simplified80.1%
sub-neg80.1%
distribute-neg-frac80.1%
metadata-eval80.1%
Applied egg-rr80.1%
Simplified99.5%
associate-/r*99.9%
div-inv99.8%
metadata-eval99.8%
+-commutative99.8%
flip-+99.4%
sub-neg99.4%
metadata-eval99.4%
neg-mul-199.4%
distribute-lft-in99.4%
+-commutative99.4%
mul-1-neg99.4%
distribute-neg-frac299.4%
metadata-eval99.4%
metadata-eval99.4%
+-commutative99.4%
flip--99.8%
frac-2neg99.8%
Applied egg-rr99.8%
clear-num99.8%
un-div-inv99.9%
flip--99.5%
metadata-eval99.5%
metadata-eval99.5%
+-commutative99.5%
associate-/l/99.5%
neg-mul-199.5%
+-commutative99.5%
distribute-neg-in99.5%
metadata-eval99.5%
sub-neg99.5%
flip-+99.9%
+-commutative99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 53.9%
(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 80.1%
sub-neg80.1%
+-commutative80.1%
distribute-neg-frac280.1%
neg-sub080.1%
associate-+l-80.1%
neg-sub080.1%
remove-double-neg80.1%
distribute-neg-in80.1%
sub-neg80.1%
distribute-neg-frac280.1%
sub-neg80.1%
+-commutative80.1%
unsub-neg80.1%
sub-neg80.1%
+-commutative80.1%
unsub-neg80.1%
metadata-eval80.1%
Simplified80.1%
Taylor expanded in x around 0 53.0%
(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 80.1%
sub-neg80.1%
+-commutative80.1%
distribute-neg-frac280.1%
neg-sub080.1%
associate-+l-80.1%
neg-sub080.1%
remove-double-neg80.1%
distribute-neg-in80.1%
sub-neg80.1%
distribute-neg-frac280.1%
sub-neg80.1%
+-commutative80.1%
unsub-neg80.1%
sub-neg80.1%
+-commutative80.1%
unsub-neg80.1%
metadata-eval80.1%
Simplified80.1%
Taylor expanded in x around 0 52.3%
Taylor expanded in x around inf 3.0%
Taylor expanded in x around inf 11.0%
herbie shell --seed 2024163
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))