
(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 7 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}
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (/ (/ 2.0 (+ x -1.0)) (- -1.0 x)))
x = abs(x);
double code(double x) {
return (2.0 / (x + -1.0)) / (-1.0 - x);
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / (x + (-1.0d0))) / ((-1.0d0) - x)
end function
x = Math.abs(x);
public static double code(double x) {
return (2.0 / (x + -1.0)) / (-1.0 - x);
}
x = abs(x) def code(x): return (2.0 / (x + -1.0)) / (-1.0 - x)
x = abs(x) function code(x) return Float64(Float64(2.0 / Float64(x + -1.0)) / Float64(-1.0 - x)) end
x = abs(x) function tmp = code(x) tmp = (2.0 / (x + -1.0)) / (-1.0 - x); end
NOTE: x should be positive before calling this function code[x_] := N[(N[(2.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
\frac{\frac{2}{x + -1}}{-1 - x}
\end{array}
Initial program 70.2%
sub-neg70.2%
+-commutative70.2%
neg-sub070.2%
associate-+l-70.2%
sub-neg70.2%
associate--r+70.2%
neg-sub070.2%
distribute-neg-frac70.2%
metadata-eval70.2%
metadata-eval70.2%
metadata-eval70.2%
associate-/r*70.2%
metadata-eval70.2%
neg-mul-170.2%
sub0-neg70.2%
associate-+l-70.2%
neg-sub070.2%
+-commutative70.2%
unsub-neg70.2%
distribute-neg-frac70.2%
metadata-eval70.2%
metadata-eval70.2%
metadata-eval70.2%
associate-/r*70.2%
metadata-eval70.2%
neg-mul-170.2%
Simplified70.2%
frac-sub71.1%
*-rgt-identity71.1%
metadata-eval71.1%
div-inv71.1%
associate-/r*71.1%
*-un-lft-identity71.1%
metadata-eval71.1%
div-inv71.1%
associate--l-75.1%
div-inv75.1%
metadata-eval75.1%
*-rgt-identity75.1%
div-inv75.1%
metadata-eval75.1%
*-rgt-identity75.1%
Applied egg-rr75.1%
div-sub75.1%
sub-neg75.1%
Applied egg-rr75.1%
metadata-eval75.1%
associate-*r/75.1%
neg-mul-175.1%
+-commutative75.1%
associate--r-99.9%
+-inverses99.9%
metadata-eval99.9%
distribute-rgt-out99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
+-inverses99.9%
associate--l+75.1%
associate-+l-71.1%
+-commutative71.1%
associate--l-71.1%
associate-*l/71.1%
associate-*r/71.1%
metadata-eval71.1%
times-frac71.1%
neg-mul-171.1%
neg-mul-171.1%
Simplified99.9%
Final simplification99.9%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ 2.0 (* x (- -1.0 x)))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = 2.0 / (x * (-1.0 - x));
}
return tmp;
}
NOTE: x should be positive before calling this function
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 * ((-1.0d0) - x))
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = 2.0 / (x * (-1.0 - x));
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = 2.0 / (x * (-1.0 - x)) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(2.0 / Float64(x * Float64(-1.0 - x))); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = 2.0 / (x * (-1.0 - x)); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 1.0], 2.0, N[(2.0 / N[(x * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{x \cdot \left(-1 - x\right)}\\
\end{array}
\end{array}
if x < 1Initial program 76.5%
sub-neg76.5%
+-commutative76.5%
neg-sub076.5%
associate-+l-76.5%
sub-neg76.5%
associate--r+76.5%
neg-sub076.5%
distribute-neg-frac76.5%
metadata-eval76.5%
metadata-eval76.5%
metadata-eval76.5%
associate-/r*76.5%
metadata-eval76.5%
neg-mul-176.5%
sub0-neg76.5%
associate-+l-76.5%
neg-sub076.5%
+-commutative76.5%
unsub-neg76.5%
distribute-neg-frac76.5%
metadata-eval76.5%
metadata-eval76.5%
metadata-eval76.5%
associate-/r*76.5%
metadata-eval76.5%
neg-mul-176.5%
Simplified76.5%
Taylor expanded in x around 0 59.8%
if 1 < x Initial program 47.0%
sub-neg47.0%
+-commutative47.0%
neg-sub047.0%
associate-+l-47.0%
sub-neg47.0%
associate--r+47.0%
neg-sub047.0%
distribute-neg-frac47.0%
metadata-eval47.0%
metadata-eval47.0%
metadata-eval47.0%
associate-/r*47.0%
metadata-eval47.0%
neg-mul-147.0%
sub0-neg47.0%
associate-+l-47.0%
neg-sub047.0%
+-commutative47.0%
unsub-neg47.0%
distribute-neg-frac47.0%
metadata-eval47.0%
metadata-eval47.0%
metadata-eval47.0%
associate-/r*47.0%
metadata-eval47.0%
neg-mul-147.0%
Simplified47.0%
frac-sub48.7%
*-rgt-identity48.7%
metadata-eval48.7%
div-inv48.7%
associate-/r*48.8%
*-un-lft-identity48.8%
metadata-eval48.8%
div-inv48.8%
associate--l-55.8%
div-inv55.8%
metadata-eval55.8%
*-rgt-identity55.8%
div-inv55.8%
metadata-eval55.8%
*-rgt-identity55.8%
Applied egg-rr55.8%
Taylor expanded in x around inf 97.3%
expm1-log1p-u97.3%
expm1-udef44.6%
associate-/l/44.6%
*-commutative44.6%
Applied egg-rr44.6%
expm1-def95.9%
expm1-log1p95.9%
Simplified95.9%
Final simplification67.6%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ (/ 2.0 x) (- -1.0 x))))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = (2.0 / x) / (-1.0 - x);
}
return tmp;
}
NOTE: x should be positive before calling this function
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) / ((-1.0d0) - x)
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = (2.0 / x) / (-1.0 - x);
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = (2.0 / x) / (-1.0 - x) return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(Float64(2.0 / x) / Float64(-1.0 - x)); end return tmp end
x = abs(x) function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 2.0; else tmp = (2.0 / x) / (-1.0 - x); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 1.0], 2.0, N[(N[(2.0 / x), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{-1 - x}\\
\end{array}
\end{array}
if x < 1Initial program 76.5%
sub-neg76.5%
+-commutative76.5%
neg-sub076.5%
associate-+l-76.5%
sub-neg76.5%
associate--r+76.5%
neg-sub076.5%
distribute-neg-frac76.5%
metadata-eval76.5%
metadata-eval76.5%
metadata-eval76.5%
associate-/r*76.5%
metadata-eval76.5%
neg-mul-176.5%
sub0-neg76.5%
associate-+l-76.5%
neg-sub076.5%
+-commutative76.5%
unsub-neg76.5%
distribute-neg-frac76.5%
metadata-eval76.5%
metadata-eval76.5%
metadata-eval76.5%
associate-/r*76.5%
metadata-eval76.5%
neg-mul-176.5%
Simplified76.5%
Taylor expanded in x around 0 59.8%
if 1 < x Initial program 47.0%
sub-neg47.0%
+-commutative47.0%
neg-sub047.0%
associate-+l-47.0%
sub-neg47.0%
associate--r+47.0%
neg-sub047.0%
distribute-neg-frac47.0%
metadata-eval47.0%
metadata-eval47.0%
metadata-eval47.0%
associate-/r*47.0%
metadata-eval47.0%
neg-mul-147.0%
sub0-neg47.0%
associate-+l-47.0%
neg-sub047.0%
+-commutative47.0%
unsub-neg47.0%
distribute-neg-frac47.0%
metadata-eval47.0%
metadata-eval47.0%
metadata-eval47.0%
associate-/r*47.0%
metadata-eval47.0%
neg-mul-147.0%
Simplified47.0%
frac-sub48.7%
*-rgt-identity48.7%
metadata-eval48.7%
div-inv48.7%
associate-/r*48.8%
*-un-lft-identity48.8%
metadata-eval48.8%
div-inv48.8%
associate--l-55.8%
div-inv55.8%
metadata-eval55.8%
*-rgt-identity55.8%
div-inv55.8%
metadata-eval55.8%
*-rgt-identity55.8%
Applied egg-rr55.8%
Taylor expanded in x around inf 97.3%
Final simplification67.9%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (/ 2.0 (* (+ x -1.0) (- -1.0 x))))
x = abs(x);
double code(double x) {
return 2.0 / ((x + -1.0) * (-1.0 - x));
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / ((x + (-1.0d0)) * ((-1.0d0) - x))
end function
x = Math.abs(x);
public static double code(double x) {
return 2.0 / ((x + -1.0) * (-1.0 - x));
}
x = abs(x) def code(x): return 2.0 / ((x + -1.0) * (-1.0 - x))
x = abs(x) function code(x) return Float64(2.0 / Float64(Float64(x + -1.0) * Float64(-1.0 - x))) end
x = abs(x) function tmp = code(x) tmp = 2.0 / ((x + -1.0) * (-1.0 - x)); end
NOTE: x should be positive before calling this function code[x_] := N[(2.0 / N[(N[(x + -1.0), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
\frac{2}{\left(x + -1\right) \cdot \left(-1 - x\right)}
\end{array}
Initial program 70.2%
sub-neg70.2%
+-commutative70.2%
neg-sub070.2%
associate-+l-70.2%
sub-neg70.2%
associate--r+70.2%
neg-sub070.2%
distribute-neg-frac70.2%
metadata-eval70.2%
metadata-eval70.2%
metadata-eval70.2%
associate-/r*70.2%
metadata-eval70.2%
neg-mul-170.2%
sub0-neg70.2%
associate-+l-70.2%
neg-sub070.2%
+-commutative70.2%
unsub-neg70.2%
distribute-neg-frac70.2%
metadata-eval70.2%
metadata-eval70.2%
metadata-eval70.2%
associate-/r*70.2%
metadata-eval70.2%
neg-mul-170.2%
Simplified70.2%
sub-neg70.2%
distribute-neg-frac70.2%
metadata-eval70.2%
Applied egg-rr70.2%
*-rgt-identity70.2%
cancel-sign-sub70.2%
distribute-neg-frac70.2%
metadata-eval70.2%
*-rgt-identity70.2%
*-inverses70.2%
associate-/r*51.6%
distribute-lft-neg-in51.6%
distribute-rgt-neg-in51.6%
*-commutative51.6%
*-lft-identity51.6%
*-inverses51.6%
times-frac70.1%
div-sub71.1%
Simplified99.4%
Final simplification99.4%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ -2.0 x)))
x = abs(x);
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 / x;
}
return tmp;
}
NOTE: x should be positive before calling this function
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
x = Math.abs(x);
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.0 / x;
}
return tmp;
}
x = abs(x) def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = -2.0 / x return tmp
x = abs(x) function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(-2.0 / x); end return tmp end
x = abs(x) 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
NOTE: x should be positive before calling this function code[x_] := If[LessEqual[x, 1.0], 2.0, N[(-2.0 / x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x}\\
\end{array}
\end{array}
if x < 1Initial program 76.5%
sub-neg76.5%
+-commutative76.5%
neg-sub076.5%
associate-+l-76.5%
sub-neg76.5%
associate--r+76.5%
neg-sub076.5%
distribute-neg-frac76.5%
metadata-eval76.5%
metadata-eval76.5%
metadata-eval76.5%
associate-/r*76.5%
metadata-eval76.5%
neg-mul-176.5%
sub0-neg76.5%
associate-+l-76.5%
neg-sub076.5%
+-commutative76.5%
unsub-neg76.5%
distribute-neg-frac76.5%
metadata-eval76.5%
metadata-eval76.5%
metadata-eval76.5%
associate-/r*76.5%
metadata-eval76.5%
neg-mul-176.5%
Simplified76.5%
Taylor expanded in x around 0 59.8%
if 1 < x Initial program 47.0%
sub-neg47.0%
+-commutative47.0%
neg-sub047.0%
associate-+l-47.0%
sub-neg47.0%
associate--r+47.0%
neg-sub047.0%
distribute-neg-frac47.0%
metadata-eval47.0%
metadata-eval47.0%
metadata-eval47.0%
associate-/r*47.0%
metadata-eval47.0%
neg-mul-147.0%
sub0-neg47.0%
associate-+l-47.0%
neg-sub047.0%
+-commutative47.0%
unsub-neg47.0%
distribute-neg-frac47.0%
metadata-eval47.0%
metadata-eval47.0%
metadata-eval47.0%
associate-/r*47.0%
metadata-eval47.0%
neg-mul-147.0%
Simplified47.0%
frac-sub48.7%
*-rgt-identity48.7%
metadata-eval48.7%
div-inv48.7%
associate-/r*48.8%
*-un-lft-identity48.8%
metadata-eval48.8%
div-inv48.8%
associate--l-55.8%
div-inv55.8%
metadata-eval55.8%
*-rgt-identity55.8%
div-inv55.8%
metadata-eval55.8%
*-rgt-identity55.8%
Applied egg-rr55.8%
Taylor expanded in x around inf 97.3%
Taylor expanded in x around 0 7.1%
Final simplification48.5%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 1.0)
x = abs(x);
double code(double x) {
return 1.0;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
x = Math.abs(x);
public static double code(double x) {
return 1.0;
}
x = abs(x) def code(x): return 1.0
x = abs(x) function code(x) return 1.0 end
x = abs(x) function tmp = code(x) tmp = 1.0; end
NOTE: x should be positive before calling this function code[x_] := 1.0
\begin{array}{l}
x = |x|\\
\\
1
\end{array}
Initial program 70.2%
sub-neg70.2%
+-commutative70.2%
neg-sub070.2%
associate-+l-70.2%
sub-neg70.2%
associate--r+70.2%
neg-sub070.2%
distribute-neg-frac70.2%
metadata-eval70.2%
metadata-eval70.2%
metadata-eval70.2%
associate-/r*70.2%
metadata-eval70.2%
neg-mul-170.2%
sub0-neg70.2%
associate-+l-70.2%
neg-sub070.2%
+-commutative70.2%
unsub-neg70.2%
distribute-neg-frac70.2%
metadata-eval70.2%
metadata-eval70.2%
metadata-eval70.2%
associate-/r*70.2%
metadata-eval70.2%
neg-mul-170.2%
Simplified70.2%
Taylor expanded in x around 0 47.3%
Taylor expanded in x around inf 10.2%
Final simplification10.2%
NOTE: x should be positive before calling this function (FPCore (x) :precision binary64 2.0)
x = abs(x);
double code(double x) {
return 2.0;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0
end function
x = Math.abs(x);
public static double code(double x) {
return 2.0;
}
x = abs(x) def code(x): return 2.0
x = abs(x) function code(x) return 2.0 end
x = abs(x) function tmp = code(x) tmp = 2.0; end
NOTE: x should be positive before calling this function code[x_] := 2.0
\begin{array}{l}
x = |x|\\
\\
2
\end{array}
Initial program 70.2%
sub-neg70.2%
+-commutative70.2%
neg-sub070.2%
associate-+l-70.2%
sub-neg70.2%
associate--r+70.2%
neg-sub070.2%
distribute-neg-frac70.2%
metadata-eval70.2%
metadata-eval70.2%
metadata-eval70.2%
associate-/r*70.2%
metadata-eval70.2%
neg-mul-170.2%
sub0-neg70.2%
associate-+l-70.2%
neg-sub070.2%
+-commutative70.2%
unsub-neg70.2%
distribute-neg-frac70.2%
metadata-eval70.2%
metadata-eval70.2%
metadata-eval70.2%
associate-/r*70.2%
metadata-eval70.2%
neg-mul-170.2%
Simplified70.2%
Taylor expanded in x around 0 47.5%
Final simplification47.5%
herbie shell --seed 2023308
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))