
(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 8 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 78.4%
sub-neg78.4%
+-commutative78.4%
distribute-neg-frac278.4%
neg-sub078.4%
associate-+l-78.4%
neg-sub078.4%
remove-double-neg78.4%
distribute-neg-in78.4%
sub-neg78.4%
distribute-neg-frac278.4%
sub-neg78.4%
+-commutative78.4%
unsub-neg78.4%
sub-neg78.4%
+-commutative78.4%
unsub-neg78.4%
metadata-eval78.4%
Simplified78.4%
sub-neg78.4%
distribute-neg-frac78.4%
metadata-eval78.4%
Applied egg-rr78.4%
Simplified99.0%
associate-/r*99.9%
metadata-eval99.9%
sub-neg99.9%
flip--99.0%
metadata-eval99.0%
difference-of-sqr-199.0%
sub-neg99.0%
metadata-eval99.0%
associate-/r/95.3%
+-commutative95.3%
metadata-eval95.3%
sub-neg95.3%
difference-of-sqr-195.3%
fmm-def95.3%
metadata-eval95.3%
+-commutative95.3%
Applied egg-rr95.3%
associate-/r/99.0%
metadata-eval99.0%
fmm-def99.0%
metadata-eval99.0%
+-commutative99.0%
metadata-eval99.0%
sub-neg99.0%
flip-+99.9%
frac-2neg99.9%
distribute-neg-frac99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 99.9%
neg-mul-199.9%
sub-neg99.9%
Simplified99.9%
(FPCore (x) :precision binary64 (if (<= x 0.75) 2.0 (/ (/ 2.0 x) (- 1.0 x))))
double code(double x) {
double tmp;
if (x <= 0.75) {
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.75d0) 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.75) {
tmp = 2.0;
} else {
tmp = (2.0 / x) / (1.0 - x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.75: tmp = 2.0 else: tmp = (2.0 / x) / (1.0 - x) return tmp
function code(x) tmp = 0.0 if (x <= 0.75) 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.75) tmp = 2.0; else tmp = (2.0 / x) / (1.0 - x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.75], 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.75:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{1 - x}\\
\end{array}
\end{array}
if x < 0.75Initial program 88.7%
sub-neg88.7%
+-commutative88.7%
distribute-neg-frac288.7%
neg-sub088.7%
associate-+l-88.7%
neg-sub088.7%
remove-double-neg88.7%
distribute-neg-in88.7%
sub-neg88.7%
distribute-neg-frac288.7%
sub-neg88.7%
+-commutative88.7%
unsub-neg88.7%
sub-neg88.7%
+-commutative88.7%
unsub-neg88.7%
metadata-eval88.7%
Simplified88.7%
Taylor expanded in x around 0 67.2%
if 0.75 < x Initial program 44.7%
sub-neg44.7%
+-commutative44.7%
distribute-neg-frac244.7%
neg-sub044.7%
associate-+l-44.7%
neg-sub044.7%
remove-double-neg44.7%
distribute-neg-in44.7%
sub-neg44.7%
distribute-neg-frac244.7%
sub-neg44.7%
+-commutative44.7%
unsub-neg44.7%
sub-neg44.7%
+-commutative44.7%
unsub-neg44.7%
metadata-eval44.7%
Simplified44.7%
sub-neg44.7%
distribute-neg-frac44.7%
metadata-eval44.7%
Applied egg-rr44.7%
Simplified97.4%
add-sqr-sqrt97.0%
pow297.0%
+-commutative97.0%
Applied egg-rr97.0%
Taylor expanded in x around inf 96.4%
frac-2neg96.4%
metadata-eval96.4%
div-inv96.4%
unpow296.4%
add-sqr-sqrt96.7%
distribute-rgt-neg-in96.7%
add-sqr-sqrt96.4%
add-sqr-sqrt0.0%
sqrt-unprod42.9%
sqr-neg42.9%
sqrt-unprod42.9%
add-sqr-sqrt42.9%
unpow242.9%
frac-2neg42.9%
metadata-eval42.9%
unpow242.9%
add-sqr-sqrt42.9%
distribute-rgt-neg-in42.9%
Applied egg-rr96.7%
associate-*r/96.7%
metadata-eval96.7%
sub-neg96.7%
unpow296.7%
sqr-neg96.7%
distribute-lft1-in96.7%
metadata-eval96.7%
distribute-neg-in96.7%
associate-/l/99.0%
distribute-neg-frac299.0%
distribute-neg-frac99.0%
metadata-eval99.0%
sub0-neg99.0%
+-commutative99.0%
associate--r+99.0%
metadata-eval99.0%
Simplified99.0%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ (/ -2.0 (+ 1.0 x)) x)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = (-2.0 / (1.0 + x)) / 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 = ((-2.0d0) / (1.0d0 + x)) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = (-2.0 / (1.0 + x)) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = (-2.0 / (1.0 + x)) / x return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(Float64(-2.0 / Float64(1.0 + x)) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = (-2.0 / (1.0 + x)) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(N[(-2.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-2}{1 + x}}{x}\\
\end{array}
\end{array}
if x < 1Initial program 88.7%
sub-neg88.7%
+-commutative88.7%
distribute-neg-frac288.7%
neg-sub088.7%
associate-+l-88.7%
neg-sub088.7%
remove-double-neg88.7%
distribute-neg-in88.7%
sub-neg88.7%
distribute-neg-frac288.7%
sub-neg88.7%
+-commutative88.7%
unsub-neg88.7%
sub-neg88.7%
+-commutative88.7%
unsub-neg88.7%
metadata-eval88.7%
Simplified88.7%
Taylor expanded in x around 0 67.2%
if 1 < x Initial program 44.7%
sub-neg44.7%
+-commutative44.7%
distribute-neg-frac244.7%
neg-sub044.7%
associate-+l-44.7%
neg-sub044.7%
remove-double-neg44.7%
distribute-neg-in44.7%
sub-neg44.7%
distribute-neg-frac244.7%
sub-neg44.7%
+-commutative44.7%
unsub-neg44.7%
sub-neg44.7%
+-commutative44.7%
unsub-neg44.7%
metadata-eval44.7%
Simplified44.7%
frac-sub45.4%
*-rgt-identity45.4%
metadata-eval45.4%
div-inv45.4%
associate-/r*45.3%
metadata-eval45.3%
div-inv45.3%
*-un-lft-identity45.3%
associate--l-53.0%
div-inv53.0%
metadata-eval53.0%
*-rgt-identity53.0%
div-inv53.0%
metadata-eval53.0%
*-rgt-identity53.0%
Applied egg-rr53.0%
Taylor expanded in x around inf 99.0%
div-inv98.7%
div-inv98.7%
associate-*l*98.7%
frac-2neg98.7%
metadata-eval98.7%
flip--96.3%
metadata-eval96.3%
metadata-eval96.3%
+-commutative96.3%
distribute-neg-frac296.3%
+-commutative96.3%
distribute-neg-in96.3%
metadata-eval96.3%
sub-neg96.3%
flip-+98.7%
+-commutative98.7%
Applied egg-rr98.7%
associate-*r*98.7%
associate-*r/98.7%
metadata-eval98.7%
associate-*l/99.0%
associate-*r/99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
(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 88.7%
sub-neg88.7%
+-commutative88.7%
distribute-neg-frac288.7%
neg-sub088.7%
associate-+l-88.7%
neg-sub088.7%
remove-double-neg88.7%
distribute-neg-in88.7%
sub-neg88.7%
distribute-neg-frac288.7%
sub-neg88.7%
+-commutative88.7%
unsub-neg88.7%
sub-neg88.7%
+-commutative88.7%
unsub-neg88.7%
metadata-eval88.7%
Simplified88.7%
Taylor expanded in x around 0 67.2%
if 0.75 < x Initial program 44.7%
sub-neg44.7%
+-commutative44.7%
distribute-neg-frac244.7%
neg-sub044.7%
associate-+l-44.7%
neg-sub044.7%
remove-double-neg44.7%
distribute-neg-in44.7%
sub-neg44.7%
distribute-neg-frac244.7%
sub-neg44.7%
+-commutative44.7%
unsub-neg44.7%
sub-neg44.7%
+-commutative44.7%
unsub-neg44.7%
metadata-eval44.7%
Simplified44.7%
sub-neg44.7%
distribute-neg-frac44.7%
metadata-eval44.7%
Applied egg-rr44.7%
Simplified97.4%
Taylor expanded in x around inf 96.7%
(FPCore (x) :precision binary64 (/ -2.0 (* (+ 1.0 x) (+ x -1.0))))
double code(double x) {
return -2.0 / ((1.0 + x) * (x + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-2.0d0) / ((1.0d0 + x) * (x + (-1.0d0)))
end function
public static double code(double x) {
return -2.0 / ((1.0 + x) * (x + -1.0));
}
def code(x): return -2.0 / ((1.0 + x) * (x + -1.0))
function code(x) return Float64(-2.0 / Float64(Float64(1.0 + x) * Float64(x + -1.0))) end
function tmp = code(x) tmp = -2.0 / ((1.0 + x) * (x + -1.0)); end
code[x_] := N[(-2.0 / N[(N[(1.0 + x), $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{\left(1 + x\right) \cdot \left(x + -1\right)}
\end{array}
Initial program 78.4%
sub-neg78.4%
+-commutative78.4%
distribute-neg-frac278.4%
neg-sub078.4%
associate-+l-78.4%
neg-sub078.4%
remove-double-neg78.4%
distribute-neg-in78.4%
sub-neg78.4%
distribute-neg-frac278.4%
sub-neg78.4%
+-commutative78.4%
unsub-neg78.4%
sub-neg78.4%
+-commutative78.4%
unsub-neg78.4%
metadata-eval78.4%
Simplified78.4%
sub-neg78.4%
distribute-neg-frac78.4%
metadata-eval78.4%
Applied egg-rr78.4%
Simplified99.0%
Final simplification99.0%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ -2.0 x)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.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 = (-2.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 = -2.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = -2.0 / x return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(-2.0 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = -2.0 / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(-2.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x}\\
\end{array}
\end{array}
if x < 1Initial program 88.7%
sub-neg88.7%
+-commutative88.7%
distribute-neg-frac288.7%
neg-sub088.7%
associate-+l-88.7%
neg-sub088.7%
remove-double-neg88.7%
distribute-neg-in88.7%
sub-neg88.7%
distribute-neg-frac288.7%
sub-neg88.7%
+-commutative88.7%
unsub-neg88.7%
sub-neg88.7%
+-commutative88.7%
unsub-neg88.7%
metadata-eval88.7%
Simplified88.7%
Taylor expanded in x around 0 67.2%
if 1 < x Initial program 44.7%
sub-neg44.7%
+-commutative44.7%
distribute-neg-frac244.7%
neg-sub044.7%
associate-+l-44.7%
neg-sub044.7%
remove-double-neg44.7%
distribute-neg-in44.7%
sub-neg44.7%
distribute-neg-frac244.7%
sub-neg44.7%
+-commutative44.7%
unsub-neg44.7%
sub-neg44.7%
+-commutative44.7%
unsub-neg44.7%
metadata-eval44.7%
Simplified44.7%
frac-sub45.4%
*-rgt-identity45.4%
metadata-eval45.4%
div-inv45.4%
associate-/r*45.3%
metadata-eval45.3%
div-inv45.3%
*-un-lft-identity45.3%
associate--l-53.0%
div-inv53.0%
metadata-eval53.0%
*-rgt-identity53.0%
div-inv53.0%
metadata-eval53.0%
*-rgt-identity53.0%
Applied egg-rr53.0%
Taylor expanded in x around inf 99.0%
Taylor expanded in x around 0 6.8%
(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 78.4%
sub-neg78.4%
+-commutative78.4%
distribute-neg-frac278.4%
neg-sub078.4%
associate-+l-78.4%
neg-sub078.4%
remove-double-neg78.4%
distribute-neg-in78.4%
sub-neg78.4%
distribute-neg-frac278.4%
sub-neg78.4%
+-commutative78.4%
unsub-neg78.4%
sub-neg78.4%
+-commutative78.4%
unsub-neg78.4%
metadata-eval78.4%
Simplified78.4%
Taylor expanded in x around 0 52.1%
(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 78.4%
sub-neg78.4%
+-commutative78.4%
distribute-neg-frac278.4%
neg-sub078.4%
associate-+l-78.4%
neg-sub078.4%
remove-double-neg78.4%
distribute-neg-in78.4%
sub-neg78.4%
distribute-neg-frac278.4%
sub-neg78.4%
+-commutative78.4%
unsub-neg78.4%
sub-neg78.4%
+-commutative78.4%
unsub-neg78.4%
metadata-eval78.4%
Simplified78.4%
Taylor expanded in x around 0 51.5%
Taylor expanded in x around inf 11.0%
herbie shell --seed 2024165
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))