
(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 (* (- 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(-2.0 / Float64(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[(-2.0 / N[(N[(1.0 - x), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-2}{\left(1 - x\right) \cdot \left(-1 - x\right)}
\end{array}
Initial program 77.4%
sub-neg77.4%
+-commutative77.4%
distribute-neg-frac277.4%
neg-sub077.4%
associate-+l-77.4%
neg-sub077.4%
remove-double-neg77.4%
distribute-neg-in77.4%
sub-neg77.4%
distribute-neg-frac277.4%
sub-neg77.4%
+-commutative77.4%
unsub-neg77.4%
sub-neg77.4%
+-commutative77.4%
unsub-neg77.4%
metadata-eval77.4%
Simplified77.4%
sub-neg77.4%
distribute-neg-frac77.4%
metadata-eval77.4%
Applied egg-rr77.4%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ 2.0 (* x (- -1.0 x)))))
double code(double x) {
double tmp;
if (x <= 1.0) {
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 <= 1.0d0) 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 <= 1.0) {
tmp = 2.0;
} else {
tmp = 2.0 / (x * (-1.0 - x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = 2.0 / (x * (-1.0 - x)) return tmp
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
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
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(2.0 / N[(x * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\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 83.1%
sub-neg83.1%
+-commutative83.1%
distribute-neg-frac283.1%
neg-sub083.1%
associate-+l-83.1%
neg-sub083.1%
remove-double-neg83.1%
distribute-neg-in83.1%
sub-neg83.1%
distribute-neg-frac283.1%
sub-neg83.1%
+-commutative83.1%
unsub-neg83.1%
sub-neg83.1%
+-commutative83.1%
unsub-neg83.1%
metadata-eval83.1%
Simplified83.1%
Taylor expanded in x around 0 66.7%
if 1 < x Initial program 56.0%
sub-neg56.0%
+-commutative56.0%
distribute-neg-frac256.0%
neg-sub056.0%
associate-+l-56.0%
neg-sub056.0%
remove-double-neg56.0%
distribute-neg-in56.0%
sub-neg56.0%
distribute-neg-frac256.0%
sub-neg56.0%
+-commutative56.0%
unsub-neg56.0%
sub-neg56.0%
+-commutative56.0%
unsub-neg56.0%
metadata-eval56.0%
Simplified56.0%
frac-sub57.5%
*-rgt-identity57.5%
metadata-eval57.5%
div-inv57.5%
associate-/r*57.5%
metadata-eval57.5%
div-inv57.5%
*-un-lft-identity57.5%
associate--l-63.4%
div-inv63.4%
metadata-eval63.4%
*-rgt-identity63.4%
div-inv63.4%
metadata-eval63.4%
*-rgt-identity63.4%
Applied egg-rr63.4%
Taylor expanded in x around inf 98.5%
*-un-lft-identity98.5%
associate-/l/97.9%
*-commutative97.9%
Applied egg-rr97.9%
*-lft-identity97.9%
Simplified97.9%
Final simplification73.3%
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ (/ 2.0 x) (- -1.0 x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
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 <= 1.0d0) 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 <= 1.0) {
tmp = 2.0;
} else {
tmp = (2.0 / x) / (-1.0 - x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 2.0 else: tmp = (2.0 / x) / (-1.0 - x) return tmp
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
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
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(N[(2.0 / x), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\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 83.1%
sub-neg83.1%
+-commutative83.1%
distribute-neg-frac283.1%
neg-sub083.1%
associate-+l-83.1%
neg-sub083.1%
remove-double-neg83.1%
distribute-neg-in83.1%
sub-neg83.1%
distribute-neg-frac283.1%
sub-neg83.1%
+-commutative83.1%
unsub-neg83.1%
sub-neg83.1%
+-commutative83.1%
unsub-neg83.1%
metadata-eval83.1%
Simplified83.1%
Taylor expanded in x around 0 66.7%
if 1 < x Initial program 56.0%
sub-neg56.0%
+-commutative56.0%
distribute-neg-frac256.0%
neg-sub056.0%
associate-+l-56.0%
neg-sub056.0%
remove-double-neg56.0%
distribute-neg-in56.0%
sub-neg56.0%
distribute-neg-frac256.0%
sub-neg56.0%
+-commutative56.0%
unsub-neg56.0%
sub-neg56.0%
+-commutative56.0%
unsub-neg56.0%
metadata-eval56.0%
Simplified56.0%
frac-sub57.5%
*-rgt-identity57.5%
metadata-eval57.5%
div-inv57.5%
associate-/r*57.5%
metadata-eval57.5%
div-inv57.5%
*-un-lft-identity57.5%
associate--l-63.4%
div-inv63.4%
metadata-eval63.4%
*-rgt-identity63.4%
div-inv63.4%
metadata-eval63.4%
*-rgt-identity63.4%
Applied egg-rr63.4%
Taylor expanded in x around inf 98.5%
Final simplification73.4%
(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 83.1%
sub-neg83.1%
+-commutative83.1%
distribute-neg-frac283.1%
neg-sub083.1%
associate-+l-83.1%
neg-sub083.1%
remove-double-neg83.1%
distribute-neg-in83.1%
sub-neg83.1%
distribute-neg-frac283.1%
sub-neg83.1%
+-commutative83.1%
unsub-neg83.1%
sub-neg83.1%
+-commutative83.1%
unsub-neg83.1%
metadata-eval83.1%
Simplified83.1%
Taylor expanded in x around 0 66.7%
if 1 < x Initial program 56.0%
sub-neg56.0%
+-commutative56.0%
distribute-neg-frac256.0%
neg-sub056.0%
associate-+l-56.0%
neg-sub056.0%
remove-double-neg56.0%
distribute-neg-in56.0%
sub-neg56.0%
distribute-neg-frac256.0%
sub-neg56.0%
+-commutative56.0%
unsub-neg56.0%
sub-neg56.0%
+-commutative56.0%
unsub-neg56.0%
metadata-eval56.0%
Simplified56.0%
frac-sub57.5%
*-rgt-identity57.5%
metadata-eval57.5%
div-inv57.5%
associate-/r*57.5%
metadata-eval57.5%
div-inv57.5%
*-un-lft-identity57.5%
associate--l-63.4%
div-inv63.4%
metadata-eval63.4%
*-rgt-identity63.4%
div-inv63.4%
metadata-eval63.4%
*-rgt-identity63.4%
Applied egg-rr63.4%
Taylor expanded in x around inf 98.5%
Taylor expanded in x around 0 6.7%
Final simplification54.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 77.4%
sub-neg77.4%
+-commutative77.4%
distribute-neg-frac277.4%
neg-sub077.4%
associate-+l-77.4%
neg-sub077.4%
remove-double-neg77.4%
distribute-neg-in77.4%
sub-neg77.4%
distribute-neg-frac277.4%
sub-neg77.4%
+-commutative77.4%
unsub-neg77.4%
sub-neg77.4%
+-commutative77.4%
unsub-neg77.4%
metadata-eval77.4%
Simplified77.4%
frac-sub78.1%
*-rgt-identity78.1%
metadata-eval78.1%
div-inv78.1%
associate-/r*78.1%
metadata-eval78.1%
div-inv78.1%
*-un-lft-identity78.1%
associate--l-81.1%
div-inv81.1%
metadata-eval81.1%
*-rgt-identity81.1%
div-inv81.1%
metadata-eval81.1%
*-rgt-identity81.1%
Applied egg-rr81.1%
Taylor expanded in x around 0 54.1%
Final simplification54.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 77.4%
sub-neg77.4%
+-commutative77.4%
distribute-neg-frac277.4%
neg-sub077.4%
associate-+l-77.4%
neg-sub077.4%
remove-double-neg77.4%
distribute-neg-in77.4%
sub-neg77.4%
distribute-neg-frac277.4%
sub-neg77.4%
+-commutative77.4%
unsub-neg77.4%
sub-neg77.4%
+-commutative77.4%
unsub-neg77.4%
metadata-eval77.4%
Simplified77.4%
Taylor expanded in x around 0 52.5%
Taylor expanded in x around inf 11.1%
Final simplification11.1%
(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 77.4%
sub-neg77.4%
+-commutative77.4%
distribute-neg-frac277.4%
neg-sub077.4%
associate-+l-77.4%
neg-sub077.4%
remove-double-neg77.4%
distribute-neg-in77.4%
sub-neg77.4%
distribute-neg-frac277.4%
sub-neg77.4%
+-commutative77.4%
unsub-neg77.4%
sub-neg77.4%
+-commutative77.4%
unsub-neg77.4%
metadata-eval77.4%
Simplified77.4%
Taylor expanded in x around 0 53.2%
Final simplification53.2%
herbie shell --seed 2024066
(FPCore (x)
:name "Asymptote A"
:precision binary64
(- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))