
(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}
(FPCore (x) :precision binary64 (/ (/ 2.0 (+ x -1.0)) (- -1.0 x)))
double code(double x) {
return (2.0 / (x + -1.0)) / (-1.0 - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (2.0d0 / (x + (-1.0d0))) / ((-1.0d0) - x)
end function
public static double code(double x) {
return (2.0 / (x + -1.0)) / (-1.0 - x);
}
def code(x): return (2.0 / (x + -1.0)) / (-1.0 - x)
function code(x) return Float64(Float64(2.0 / Float64(x + -1.0)) / Float64(-1.0 - x)) end
function tmp = code(x) tmp = (2.0 / (x + -1.0)) / (-1.0 - x); end
code[x_] := N[(N[(2.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{x + -1}}{-1 - x}
\end{array}
Initial program 79.9%
sub-neg79.9%
+-commutative79.9%
distribute-neg-frac279.9%
neg-sub079.9%
associate-+l-79.9%
neg-sub079.9%
remove-double-neg79.9%
distribute-neg-in79.9%
sub-neg79.9%
distribute-neg-frac279.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
metadata-eval79.9%
Simplified79.9%
frac-sub80.5%
*-rgt-identity80.5%
metadata-eval80.5%
div-inv80.5%
associate-/r*80.5%
metadata-eval80.5%
div-inv80.5%
*-un-lft-identity80.5%
associate--l-83.0%
div-inv83.0%
metadata-eval83.0%
*-rgt-identity83.0%
div-inv83.0%
metadata-eval83.0%
*-rgt-identity83.0%
Applied egg-rr83.0%
*-un-lft-identity83.0%
associate--r+80.5%
sub-neg80.5%
flip--60.0%
+-commutative60.0%
distribute-neg-frac260.0%
metadata-eval60.0%
metadata-eval60.0%
mul-1-neg60.0%
+-commutative60.0%
distribute-lft-in60.0%
metadata-eval60.0%
neg-mul-160.0%
sub-neg60.0%
flip-+80.5%
+-commutative80.5%
Applied egg-rr80.5%
*-lft-identity80.5%
sub-neg80.5%
+-commutative80.5%
metadata-eval80.5%
distribute-neg-in80.5%
distribute-neg-frac280.5%
distribute-neg-frac80.5%
associate-+l-83.0%
sub-neg83.0%
distribute-neg-in83.0%
metadata-eval83.0%
+-commutative83.0%
sub-neg83.0%
+-commutative83.0%
associate--r-99.9%
+-inverses99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
Simplified99.9%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ (/ (- 2.0) x) x)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = (-2.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 / 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 / x) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = (-2.0 / x) / x return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = 2.0; else tmp = Float64(Float64(Float64(-2.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 / x) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(N[((-2.0) / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-2}{x}}{x}\\
\end{array}
\end{array}
if x < 1Initial program 87.3%
sub-neg87.3%
+-commutative87.3%
distribute-neg-frac287.3%
neg-sub087.3%
associate-+l-87.3%
neg-sub087.3%
remove-double-neg87.3%
distribute-neg-in87.3%
sub-neg87.3%
distribute-neg-frac287.3%
sub-neg87.3%
+-commutative87.3%
unsub-neg87.3%
sub-neg87.3%
+-commutative87.3%
unsub-neg87.3%
metadata-eval87.3%
Simplified87.3%
Taylor expanded in x around 0 72.5%
if 1 < x Initial program 55.7%
sub-neg55.7%
+-commutative55.7%
distribute-neg-frac255.7%
neg-sub055.7%
associate-+l-55.7%
neg-sub055.7%
remove-double-neg55.7%
distribute-neg-in55.7%
sub-neg55.7%
distribute-neg-frac255.7%
sub-neg55.7%
+-commutative55.7%
unsub-neg55.7%
sub-neg55.7%
+-commutative55.7%
unsub-neg55.7%
metadata-eval55.7%
Simplified55.7%
frac-sub56.2%
*-rgt-identity56.2%
metadata-eval56.2%
div-inv56.2%
associate-/r*56.2%
metadata-eval56.2%
div-inv56.2%
*-un-lft-identity56.2%
associate--l-61.7%
div-inv61.7%
metadata-eval61.7%
*-rgt-identity61.7%
div-inv61.7%
metadata-eval61.7%
*-rgt-identity61.7%
Applied egg-rr61.7%
Taylor expanded in x around inf 97.6%
Taylor expanded in x around inf 98.2%
neg-mul-198.2%
Simplified98.2%
Final simplification78.5%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ (- 2.0) (* x x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 2.0;
} else {
tmp = -2.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 / (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 / (x * x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = -2.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(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 / (x * x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], 2.0, N[((-2.0) / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\
\mathbf{else}:\\
\;\;\;\;\frac{-2}{x \cdot x}\\
\end{array}
\end{array}
if x < 1Initial program 87.3%
sub-neg87.3%
+-commutative87.3%
distribute-neg-frac287.3%
neg-sub087.3%
associate-+l-87.3%
neg-sub087.3%
remove-double-neg87.3%
distribute-neg-in87.3%
sub-neg87.3%
distribute-neg-frac287.3%
sub-neg87.3%
+-commutative87.3%
unsub-neg87.3%
sub-neg87.3%
+-commutative87.3%
unsub-neg87.3%
metadata-eval87.3%
Simplified87.3%
Taylor expanded in x around 0 72.5%
if 1 < x Initial program 55.7%
sub-neg55.7%
+-commutative55.7%
distribute-neg-frac255.7%
neg-sub055.7%
associate-+l-55.7%
neg-sub055.7%
remove-double-neg55.7%
distribute-neg-in55.7%
sub-neg55.7%
distribute-neg-frac255.7%
sub-neg55.7%
+-commutative55.7%
unsub-neg55.7%
sub-neg55.7%
+-commutative55.7%
unsub-neg55.7%
metadata-eval55.7%
Simplified55.7%
frac-sub56.2%
*-rgt-identity56.2%
metadata-eval56.2%
div-inv56.2%
associate-/r*56.2%
metadata-eval56.2%
div-inv56.2%
*-un-lft-identity56.2%
associate--l-61.7%
div-inv61.7%
metadata-eval61.7%
*-rgt-identity61.7%
div-inv61.7%
metadata-eval61.7%
*-rgt-identity61.7%
Applied egg-rr61.7%
Taylor expanded in x around inf 97.6%
div-inv97.6%
associate-/l*97.5%
Applied egg-rr97.5%
associate-/r*94.5%
associate-*r/94.5%
metadata-eval94.5%
Simplified94.5%
Taylor expanded in x around inf 95.1%
neg-mul-198.2%
Simplified95.1%
Final simplification77.8%
(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 79.9%
sub-neg79.9%
+-commutative79.9%
distribute-neg-frac279.9%
neg-sub079.9%
associate-+l-79.9%
neg-sub079.9%
remove-double-neg79.9%
distribute-neg-in79.9%
sub-neg79.9%
distribute-neg-frac279.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
metadata-eval79.9%
Simplified79.9%
sub-neg79.9%
distribute-neg-frac79.9%
metadata-eval79.9%
Applied egg-rr79.9%
Simplified98.8%
Final simplification98.8%
(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 87.3%
sub-neg87.3%
+-commutative87.3%
distribute-neg-frac287.3%
neg-sub087.3%
associate-+l-87.3%
neg-sub087.3%
remove-double-neg87.3%
distribute-neg-in87.3%
sub-neg87.3%
distribute-neg-frac287.3%
sub-neg87.3%
+-commutative87.3%
unsub-neg87.3%
sub-neg87.3%
+-commutative87.3%
unsub-neg87.3%
metadata-eval87.3%
Simplified87.3%
Taylor expanded in x around 0 72.5%
if 1 < x Initial program 55.7%
sub-neg55.7%
+-commutative55.7%
distribute-neg-frac255.7%
neg-sub055.7%
associate-+l-55.7%
neg-sub055.7%
remove-double-neg55.7%
distribute-neg-in55.7%
sub-neg55.7%
distribute-neg-frac255.7%
sub-neg55.7%
+-commutative55.7%
unsub-neg55.7%
sub-neg55.7%
+-commutative55.7%
unsub-neg55.7%
metadata-eval55.7%
Simplified55.7%
frac-sub56.2%
*-rgt-identity56.2%
metadata-eval56.2%
div-inv56.2%
associate-/r*56.2%
metadata-eval56.2%
div-inv56.2%
*-un-lft-identity56.2%
associate--l-61.7%
div-inv61.7%
metadata-eval61.7%
*-rgt-identity61.7%
div-inv61.7%
metadata-eval61.7%
*-rgt-identity61.7%
Applied egg-rr61.7%
Taylor expanded in x around inf 97.6%
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 79.9%
sub-neg79.9%
+-commutative79.9%
distribute-neg-frac279.9%
neg-sub079.9%
associate-+l-79.9%
neg-sub079.9%
remove-double-neg79.9%
distribute-neg-in79.9%
sub-neg79.9%
distribute-neg-frac279.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
metadata-eval79.9%
Simplified79.9%
Taylor expanded in x around 0 56.2%
(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 79.9%
sub-neg79.9%
+-commutative79.9%
distribute-neg-frac279.9%
neg-sub079.9%
associate-+l-79.9%
neg-sub079.9%
remove-double-neg79.9%
distribute-neg-in79.9%
sub-neg79.9%
distribute-neg-frac279.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
sub-neg79.9%
+-commutative79.9%
unsub-neg79.9%
metadata-eval79.9%
Simplified79.9%
Taylor expanded in x around 0 55.5%
Taylor expanded in x around inf 2.9%
Taylor expanded in x around inf 11.7%
herbie shell --seed 2024121
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))