
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))
end function
public static double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
def code(x): return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
function code(x) return Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) end
function tmp = code(x) tmp = (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0)); end
code[x_] := N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))
end function
public static double code(double x) {
return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
def code(x): return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
function code(x) return Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) end
function tmp = code(x) tmp = (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0)); end
code[x_] := N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\end{array}
(FPCore (x) :precision binary64 (/ (+ (/ 1.0 x) 3.0) (- (/ 1.0 x) x)))
double code(double x) {
return ((1.0 / x) + 3.0) / ((1.0 / x) - x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.0d0 / x) + 3.0d0) / ((1.0d0 / x) - x)
end function
public static double code(double x) {
return ((1.0 / x) + 3.0) / ((1.0 / x) - x);
}
def code(x): return ((1.0 / x) + 3.0) / ((1.0 / x) - x)
function code(x) return Float64(Float64(Float64(1.0 / x) + 3.0) / Float64(Float64(1.0 / x) - x)) end
function tmp = code(x) tmp = ((1.0 / x) + 3.0) / ((1.0 / x) - x); end
code[x_] := N[(N[(N[(1.0 / x), $MachinePrecision] + 3.0), $MachinePrecision] / N[(N[(1.0 / x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x} + 3}{\frac{1}{x} - x}
\end{array}
Initial program 54.7%
remove-double-neg54.7%
distribute-neg-frac54.7%
distribute-neg-in54.7%
sub-neg54.7%
distribute-frac-neg254.7%
sub-neg54.7%
+-commutative54.7%
unsub-neg54.7%
metadata-eval54.7%
neg-sub054.7%
associate-+l-54.7%
neg-sub054.7%
+-commutative54.7%
unsub-neg54.7%
Simplified54.7%
clear-num54.7%
frac-sub54.8%
*-un-lft-identity54.8%
Applied egg-rr54.8%
Taylor expanded in x around inf 99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in x around 0 75.5%
mul-1-neg75.5%
sub-neg75.5%
div-sub75.5%
*-rgt-identity75.5%
associate-*r/75.4%
unpow275.4%
associate-*l*99.9%
rgt-mult-inverse100.0%
*-rgt-identity100.0%
Simplified100.0%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ (+ -3.0 (/ -1.0 x)) x) (+ 1.0 (* x (+ x 3.0)))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = 1.0 + (x * (x + 3.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = ((-3.0d0) + ((-1.0d0) / x)) / x
else
tmp = 1.0d0 + (x * (x + 3.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = (-3.0 + (-1.0 / x)) / x;
} else {
tmp = 1.0 + (x * (x + 3.0));
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = (-3.0 + (-1.0 / x)) / x else: tmp = 1.0 + (x * (x + 3.0)) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(Float64(-3.0 + Float64(-1.0 / x)) / x); else tmp = Float64(1.0 + Float64(x * Float64(x + 3.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = (-3.0 + (-1.0 / x)) / x; else tmp = 1.0 + (x * (x + 3.0)); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(1.0 + N[(x * N[(x + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 8.0%
remove-double-neg8.0%
distribute-neg-frac8.0%
distribute-neg-in8.0%
sub-neg8.0%
distribute-frac-neg28.0%
sub-neg8.0%
+-commutative8.0%
unsub-neg8.0%
metadata-eval8.0%
neg-sub08.0%
associate-+l-8.0%
neg-sub08.0%
+-commutative8.0%
unsub-neg8.0%
Simplified8.0%
Taylor expanded in x around inf 99.2%
associate-*r/99.2%
neg-mul-199.2%
distribute-neg-in99.2%
metadata-eval99.2%
distribute-neg-frac99.2%
metadata-eval99.2%
Simplified99.2%
if -1 < x < 1Initial program 99.9%
remove-double-neg99.9%
distribute-neg-frac99.9%
distribute-neg-in99.9%
sub-neg99.9%
distribute-frac-neg299.9%
sub-neg99.9%
+-commutative99.9%
unsub-neg99.9%
metadata-eval99.9%
neg-sub099.9%
associate-+l-99.9%
neg-sub099.9%
+-commutative99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in x around 0 98.8%
Final simplification99.0%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ -3.0 x) (+ 1.0 (* x (+ x 3.0)))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0 + (x * (x + 3.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (-3.0d0) / x
else
tmp = 1.0d0 + (x * (x + 3.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0 + (x * (x + 3.0));
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -3.0 / x else: tmp = 1.0 + (x * (x + 3.0)) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(-3.0 / x); else tmp = Float64(1.0 + Float64(x * Float64(x + 3.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -3.0 / x; else tmp = 1.0 + (x * (x + 3.0)); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-3.0 / x), $MachinePrecision], N[(1.0 + N[(x * N[(x + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 8.0%
remove-double-neg8.0%
distribute-neg-frac8.0%
distribute-neg-in8.0%
sub-neg8.0%
distribute-frac-neg28.0%
sub-neg8.0%
+-commutative8.0%
unsub-neg8.0%
metadata-eval8.0%
neg-sub08.0%
associate-+l-8.0%
neg-sub08.0%
+-commutative8.0%
unsub-neg8.0%
Simplified8.0%
Taylor expanded in x around inf 98.3%
if -1 < x < 1Initial program 99.9%
remove-double-neg99.9%
distribute-neg-frac99.9%
distribute-neg-in99.9%
sub-neg99.9%
distribute-frac-neg299.9%
sub-neg99.9%
+-commutative99.9%
unsub-neg99.9%
metadata-eval99.9%
neg-sub099.9%
associate-+l-99.9%
neg-sub099.9%
+-commutative99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in x around 0 98.8%
Final simplification98.5%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ -3.0 x) (+ 1.0 (* x 3.0))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0 + (x * 3.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (-3.0d0) / x
else
tmp = 1.0d0 + (x * 3.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0 + (x * 3.0);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -3.0 / x else: tmp = 1.0 + (x * 3.0) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(-3.0 / x); else tmp = Float64(1.0 + Float64(x * 3.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -3.0 / x; else tmp = 1.0 + (x * 3.0); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-3.0 / x), $MachinePrecision], N[(1.0 + N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot 3\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 8.0%
remove-double-neg8.0%
distribute-neg-frac8.0%
distribute-neg-in8.0%
sub-neg8.0%
distribute-frac-neg28.0%
sub-neg8.0%
+-commutative8.0%
unsub-neg8.0%
metadata-eval8.0%
neg-sub08.0%
associate-+l-8.0%
neg-sub08.0%
+-commutative8.0%
unsub-neg8.0%
Simplified8.0%
Taylor expanded in x around inf 98.3%
if -1 < x < 1Initial program 99.9%
remove-double-neg99.9%
distribute-neg-frac99.9%
distribute-neg-in99.9%
sub-neg99.9%
distribute-frac-neg299.9%
sub-neg99.9%
+-commutative99.9%
unsub-neg99.9%
metadata-eval99.9%
neg-sub099.9%
associate-+l-99.9%
neg-sub099.9%
+-commutative99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in x around 0 98.4%
Final simplification98.3%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ -3.0 x) 1.0))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (-3.0d0) / x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -3.0 / x else: tmp = 1.0 return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(-3.0 / x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -3.0 / x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-3.0 / x), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 8.0%
remove-double-neg8.0%
distribute-neg-frac8.0%
distribute-neg-in8.0%
sub-neg8.0%
distribute-frac-neg28.0%
sub-neg8.0%
+-commutative8.0%
unsub-neg8.0%
metadata-eval8.0%
neg-sub08.0%
associate-+l-8.0%
neg-sub08.0%
+-commutative8.0%
unsub-neg8.0%
Simplified8.0%
Taylor expanded in x around inf 98.3%
if -1 < x < 1Initial program 99.9%
remove-double-neg99.9%
distribute-neg-frac99.9%
distribute-neg-in99.9%
sub-neg99.9%
distribute-frac-neg299.9%
sub-neg99.9%
+-commutative99.9%
unsub-neg99.9%
metadata-eval99.9%
neg-sub099.9%
associate-+l-99.9%
neg-sub099.9%
+-commutative99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in x around 0 96.9%
Final simplification97.5%
(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 54.7%
remove-double-neg54.7%
distribute-neg-frac54.7%
distribute-neg-in54.7%
sub-neg54.7%
distribute-frac-neg254.7%
sub-neg54.7%
+-commutative54.7%
unsub-neg54.7%
metadata-eval54.7%
neg-sub054.7%
associate-+l-54.7%
neg-sub054.7%
+-commutative54.7%
unsub-neg54.7%
Simplified54.7%
Taylor expanded in x around 0 51.0%
herbie shell --seed 2024106
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))