
(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 8 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 (if (<= (+ (/ x (+ x 1.0)) (/ (+ x 1.0) (- 1.0 x))) 4e-12) (/ (- (+ 3.0 (/ 2.0 (pow x 2.0))) (/ 2.0 x)) (- 1.0 x)) (/ (- (/ (+ x -1.0) (+ x 1.0)) (/ (+ x 1.0) x)) (+ 1.0 (/ -1.0 x)))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) + ((x + 1.0) / (1.0 - x))) <= 4e-12) {
tmp = ((3.0 + (2.0 / pow(x, 2.0))) - (2.0 / x)) / (1.0 - x);
} else {
tmp = (((x + -1.0) / (x + 1.0)) - ((x + 1.0) / x)) / (1.0 + (-1.0 / x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((x / (x + 1.0d0)) + ((x + 1.0d0) / (1.0d0 - x))) <= 4d-12) then
tmp = ((3.0d0 + (2.0d0 / (x ** 2.0d0))) - (2.0d0 / x)) / (1.0d0 - x)
else
tmp = (((x + (-1.0d0)) / (x + 1.0d0)) - ((x + 1.0d0) / x)) / (1.0d0 + ((-1.0d0) / x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((x / (x + 1.0)) + ((x + 1.0) / (1.0 - x))) <= 4e-12) {
tmp = ((3.0 + (2.0 / Math.pow(x, 2.0))) - (2.0 / x)) / (1.0 - x);
} else {
tmp = (((x + -1.0) / (x + 1.0)) - ((x + 1.0) / x)) / (1.0 + (-1.0 / x));
}
return tmp;
}
def code(x): tmp = 0 if ((x / (x + 1.0)) + ((x + 1.0) / (1.0 - x))) <= 4e-12: tmp = ((3.0 + (2.0 / math.pow(x, 2.0))) - (2.0 / x)) / (1.0 - x) else: tmp = (((x + -1.0) / (x + 1.0)) - ((x + 1.0) / x)) / (1.0 + (-1.0 / x)) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) + Float64(Float64(x + 1.0) / Float64(1.0 - x))) <= 4e-12) tmp = Float64(Float64(Float64(3.0 + Float64(2.0 / (x ^ 2.0))) - Float64(2.0 / x)) / Float64(1.0 - x)); else tmp = Float64(Float64(Float64(Float64(x + -1.0) / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / x)) / Float64(1.0 + Float64(-1.0 / x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((x / (x + 1.0)) + ((x + 1.0) / (1.0 - x))) <= 4e-12) tmp = ((3.0 + (2.0 / (x ^ 2.0))) - (2.0 / x)) / (1.0 - x); else tmp = (((x + -1.0) / (x + 1.0)) - ((x + 1.0) / x)) / (1.0 + (-1.0 / x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(x + 1.0), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4e-12], N[(N[(N[(3.0 + N[(2.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x + -1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} + \frac{x + 1}{1 - x} \leq 4 \cdot 10^{-12}:\\
\;\;\;\;\frac{\left(3 + \frac{2}{{x}^{2}}\right) - \frac{2}{x}}{1 - x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x + -1}{x + 1} - \frac{x + 1}{x}}{1 + \frac{-1}{x}}\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 3.99999999999999992e-12Initial program 8.5%
remove-double-neg8.5%
distribute-neg-frac8.5%
distribute-neg-in8.5%
sub-neg8.5%
distribute-frac-neg28.5%
sub-neg8.5%
+-commutative8.5%
unsub-neg8.5%
metadata-eval8.5%
neg-sub08.5%
associate-+l-8.5%
neg-sub08.5%
+-commutative8.5%
unsub-neg8.5%
Simplified8.5%
frac-2neg8.5%
clear-num8.5%
frac-sub9.7%
+-commutative9.7%
distribute-neg-in9.7%
metadata-eval9.7%
sub-neg9.7%
*-commutative9.7%
*-un-lft-identity9.7%
+-commutative9.7%
distribute-neg-in9.7%
metadata-eval9.7%
sub-neg9.7%
Applied egg-rr9.7%
Taylor expanded in x around 0 9.7%
mul-1-neg9.7%
sub-neg9.7%
Simplified9.7%
Taylor expanded in x around inf 99.3%
associate-*r/99.3%
metadata-eval99.3%
associate-*r/99.3%
metadata-eval99.3%
Simplified99.3%
if 3.99999999999999992e-12 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) Initial 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%
clear-num99.9%
clear-num99.9%
frac-sub99.9%
*-un-lft-identity99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 100.0%
div-sub99.9%
sub-neg99.9%
sub-neg99.9%
distribute-neg-frac99.9%
metadata-eval99.9%
*-rgt-identity99.9%
+-commutative99.9%
sub-neg99.9%
distribute-neg-frac99.9%
metadata-eval99.9%
Applied egg-rr99.9%
sub-neg99.9%
div-sub100.0%
Simplified100.0%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= (+ (/ x (+ x 1.0)) (/ (+ x 1.0) (- 1.0 x))) 4e-12) (/ (- 3.0 (/ 2.0 x)) (- 1.0 x)) (/ (- (/ (+ x -1.0) (+ x 1.0)) (/ (+ x 1.0) x)) (+ 1.0 (/ -1.0 x)))))
double code(double x) {
double tmp;
if (((x / (x + 1.0)) + ((x + 1.0) / (1.0 - x))) <= 4e-12) {
tmp = (3.0 - (2.0 / x)) / (1.0 - x);
} else {
tmp = (((x + -1.0) / (x + 1.0)) - ((x + 1.0) / x)) / (1.0 + (-1.0 / x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((x / (x + 1.0d0)) + ((x + 1.0d0) / (1.0d0 - x))) <= 4d-12) then
tmp = (3.0d0 - (2.0d0 / x)) / (1.0d0 - x)
else
tmp = (((x + (-1.0d0)) / (x + 1.0d0)) - ((x + 1.0d0) / x)) / (1.0d0 + ((-1.0d0) / x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((x / (x + 1.0)) + ((x + 1.0) / (1.0 - x))) <= 4e-12) {
tmp = (3.0 - (2.0 / x)) / (1.0 - x);
} else {
tmp = (((x + -1.0) / (x + 1.0)) - ((x + 1.0) / x)) / (1.0 + (-1.0 / x));
}
return tmp;
}
def code(x): tmp = 0 if ((x / (x + 1.0)) + ((x + 1.0) / (1.0 - x))) <= 4e-12: tmp = (3.0 - (2.0 / x)) / (1.0 - x) else: tmp = (((x + -1.0) / (x + 1.0)) - ((x + 1.0) / x)) / (1.0 + (-1.0 / x)) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(x / Float64(x + 1.0)) + Float64(Float64(x + 1.0) / Float64(1.0 - x))) <= 4e-12) tmp = Float64(Float64(3.0 - Float64(2.0 / x)) / Float64(1.0 - x)); else tmp = Float64(Float64(Float64(Float64(x + -1.0) / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / x)) / Float64(1.0 + Float64(-1.0 / x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((x / (x + 1.0)) + ((x + 1.0) / (1.0 - x))) <= 4e-12) tmp = (3.0 - (2.0 / x)) / (1.0 - x); else tmp = (((x + -1.0) / (x + 1.0)) - ((x + 1.0) / x)) / (1.0 + (-1.0 / x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(x + 1.0), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4e-12], N[(N[(3.0 - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x + -1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} + \frac{x + 1}{1 - x} \leq 4 \cdot 10^{-12}:\\
\;\;\;\;\frac{3 - \frac{2}{x}}{1 - x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x + -1}{x + 1} - \frac{x + 1}{x}}{1 + \frac{-1}{x}}\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 3.99999999999999992e-12Initial program 8.5%
remove-double-neg8.5%
distribute-neg-frac8.5%
distribute-neg-in8.5%
sub-neg8.5%
distribute-frac-neg28.5%
sub-neg8.5%
+-commutative8.5%
unsub-neg8.5%
metadata-eval8.5%
neg-sub08.5%
associate-+l-8.5%
neg-sub08.5%
+-commutative8.5%
unsub-neg8.5%
Simplified8.5%
frac-2neg8.5%
clear-num8.5%
frac-sub9.7%
+-commutative9.7%
distribute-neg-in9.7%
metadata-eval9.7%
sub-neg9.7%
*-commutative9.7%
*-un-lft-identity9.7%
+-commutative9.7%
distribute-neg-in9.7%
metadata-eval9.7%
sub-neg9.7%
Applied egg-rr9.7%
Taylor expanded in x around 0 9.7%
mul-1-neg9.7%
sub-neg9.7%
Simplified9.7%
Taylor expanded in x around inf 99.3%
associate-*r/99.3%
metadata-eval99.3%
Simplified99.3%
if 3.99999999999999992e-12 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) Initial 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%
clear-num99.9%
clear-num99.9%
frac-sub99.9%
*-un-lft-identity99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 100.0%
div-sub99.9%
sub-neg99.9%
sub-neg99.9%
distribute-neg-frac99.9%
metadata-eval99.9%
*-rgt-identity99.9%
+-commutative99.9%
sub-neg99.9%
distribute-neg-frac99.9%
metadata-eval99.9%
Applied egg-rr99.9%
sub-neg99.9%
div-sub100.0%
Simplified100.0%
Final simplification99.6%
(FPCore (x) :precision binary64 (let* ((t_0 (+ (/ x (+ x 1.0)) (/ (+ x 1.0) (- 1.0 x))))) (if (<= t_0 4e-12) (/ (- 3.0 (/ 2.0 x)) (- 1.0 x)) t_0)))
double code(double x) {
double t_0 = (x / (x + 1.0)) + ((x + 1.0) / (1.0 - x));
double tmp;
if (t_0 <= 4e-12) {
tmp = (3.0 - (2.0 / x)) / (1.0 - x);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (x / (x + 1.0d0)) + ((x + 1.0d0) / (1.0d0 - x))
if (t_0 <= 4d-12) then
tmp = (3.0d0 - (2.0d0 / x)) / (1.0d0 - x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (x / (x + 1.0)) + ((x + 1.0) / (1.0 - x));
double tmp;
if (t_0 <= 4e-12) {
tmp = (3.0 - (2.0 / x)) / (1.0 - x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = (x / (x + 1.0)) + ((x + 1.0) / (1.0 - x)) tmp = 0 if t_0 <= 4e-12: tmp = (3.0 - (2.0 / x)) / (1.0 - x) else: tmp = t_0 return tmp
function code(x) t_0 = Float64(Float64(x / Float64(x + 1.0)) + Float64(Float64(x + 1.0) / Float64(1.0 - x))) tmp = 0.0 if (t_0 <= 4e-12) tmp = Float64(Float64(3.0 - Float64(2.0 / x)) / Float64(1.0 - x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = (x / (x + 1.0)) + ((x + 1.0) / (1.0 - x)); tmp = 0.0; if (t_0 <= 4e-12) tmp = (3.0 - (2.0 / x)) / (1.0 - x); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(x + 1.0), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 4e-12], N[(N[(3.0 - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{x + 1} + \frac{x + 1}{1 - x}\\
\mathbf{if}\;t\_0 \leq 4 \cdot 10^{-12}:\\
\;\;\;\;\frac{3 - \frac{2}{x}}{1 - x}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 3.99999999999999992e-12Initial program 8.5%
remove-double-neg8.5%
distribute-neg-frac8.5%
distribute-neg-in8.5%
sub-neg8.5%
distribute-frac-neg28.5%
sub-neg8.5%
+-commutative8.5%
unsub-neg8.5%
metadata-eval8.5%
neg-sub08.5%
associate-+l-8.5%
neg-sub08.5%
+-commutative8.5%
unsub-neg8.5%
Simplified8.5%
frac-2neg8.5%
clear-num8.5%
frac-sub9.7%
+-commutative9.7%
distribute-neg-in9.7%
metadata-eval9.7%
sub-neg9.7%
*-commutative9.7%
*-un-lft-identity9.7%
+-commutative9.7%
distribute-neg-in9.7%
metadata-eval9.7%
sub-neg9.7%
Applied egg-rr9.7%
Taylor expanded in x around 0 9.7%
mul-1-neg9.7%
sub-neg9.7%
Simplified9.7%
Taylor expanded in x around inf 99.3%
associate-*r/99.3%
metadata-eval99.3%
Simplified99.3%
if 3.99999999999999992e-12 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) Initial program 99.9%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.85))) (/ (- 3.0 (/ 2.0 x)) (- 1.0 x)) (+ 1.0 (* x (+ x 3.0)))))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 0.85)) {
tmp = (3.0 - (2.0 / x)) / (1.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 <= 0.85d0))) then
tmp = (3.0d0 - (2.0d0 / x)) / (1.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 <= 0.85)) {
tmp = (3.0 - (2.0 / x)) / (1.0 - x);
} else {
tmp = 1.0 + (x * (x + 3.0));
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 0.85): tmp = (3.0 - (2.0 / x)) / (1.0 - x) else: tmp = 1.0 + (x * (x + 3.0)) return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.85)) tmp = Float64(Float64(3.0 - Float64(2.0 / x)) / Float64(1.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 <= 0.85))) tmp = (3.0 - (2.0 / x)) / (1.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, 0.85]], $MachinePrecision]], N[(N[(3.0 - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $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 0.85\right):\\
\;\;\;\;\frac{3 - \frac{2}{x}}{1 - x}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\
\end{array}
\end{array}
if x < -1 or 0.849999999999999978 < x Initial program 9.2%
remove-double-neg9.2%
distribute-neg-frac9.2%
distribute-neg-in9.2%
sub-neg9.2%
distribute-frac-neg29.2%
sub-neg9.2%
+-commutative9.2%
unsub-neg9.2%
metadata-eval9.2%
neg-sub09.2%
associate-+l-9.2%
neg-sub09.2%
+-commutative9.2%
unsub-neg9.2%
Simplified9.2%
frac-2neg9.2%
clear-num9.2%
frac-sub10.4%
+-commutative10.4%
distribute-neg-in10.4%
metadata-eval10.4%
sub-neg10.4%
*-commutative10.4%
*-un-lft-identity10.4%
+-commutative10.4%
distribute-neg-in10.4%
metadata-eval10.4%
sub-neg10.4%
Applied egg-rr10.4%
Taylor expanded in x around 0 10.4%
mul-1-neg10.4%
sub-neg10.4%
Simplified10.4%
Taylor expanded in x around inf 98.8%
associate-*r/98.8%
metadata-eval98.8%
Simplified98.8%
if -1 < x < 0.849999999999999978Initial program 100.0%
remove-double-neg100.0%
distribute-neg-frac100.0%
distribute-neg-in100.0%
sub-neg100.0%
distribute-frac-neg2100.0%
sub-neg100.0%
+-commutative100.0%
unsub-neg100.0%
metadata-eval100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 99.1%
unpow299.1%
distribute-rgt-out99.1%
Simplified99.1%
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 9.2%
remove-double-neg9.2%
distribute-neg-frac9.2%
distribute-neg-in9.2%
sub-neg9.2%
distribute-frac-neg29.2%
sub-neg9.2%
+-commutative9.2%
unsub-neg9.2%
metadata-eval9.2%
neg-sub09.2%
associate-+l-9.2%
neg-sub09.2%
+-commutative9.2%
unsub-neg9.2%
Simplified9.2%
Taylor expanded in x around inf 97.7%
if -1 < x < 1Initial program 100.0%
remove-double-neg100.0%
distribute-neg-frac100.0%
distribute-neg-in100.0%
sub-neg100.0%
distribute-frac-neg2100.0%
sub-neg100.0%
+-commutative100.0%
unsub-neg100.0%
metadata-eval100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 99.1%
unpow299.1%
distribute-rgt-out99.1%
Simplified99.1%
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 9.2%
remove-double-neg9.2%
distribute-neg-frac9.2%
distribute-neg-in9.2%
sub-neg9.2%
distribute-frac-neg29.2%
sub-neg9.2%
+-commutative9.2%
unsub-neg9.2%
metadata-eval9.2%
neg-sub09.2%
associate-+l-9.2%
neg-sub09.2%
+-commutative9.2%
unsub-neg9.2%
Simplified9.2%
Taylor expanded in x around inf 97.7%
if -1 < x < 1Initial program 100.0%
remove-double-neg100.0%
distribute-neg-frac100.0%
distribute-neg-in100.0%
sub-neg100.0%
distribute-frac-neg2100.0%
sub-neg100.0%
+-commutative100.0%
unsub-neg100.0%
metadata-eval100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
Final simplification98.3%
(FPCore (x) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (/ -3.0 x) (+ x 1.0)))
double code(double x) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -3.0 / x;
} else {
tmp = x + 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 = x + 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 = x + 1.0;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -3.0 / x else: tmp = x + 1.0 return tmp
function code(x) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(-3.0 / x); else tmp = Float64(x + 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 = x + 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], N[(x + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-3}{x}\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 9.2%
remove-double-neg9.2%
distribute-neg-frac9.2%
distribute-neg-in9.2%
sub-neg9.2%
distribute-frac-neg29.2%
sub-neg9.2%
+-commutative9.2%
unsub-neg9.2%
metadata-eval9.2%
neg-sub09.2%
associate-+l-9.2%
neg-sub09.2%
+-commutative9.2%
unsub-neg9.2%
Simplified9.2%
Taylor expanded in x around inf 97.7%
if -1 < x < 1Initial program 100.0%
remove-double-neg100.0%
distribute-neg-frac100.0%
distribute-neg-in100.0%
sub-neg100.0%
distribute-frac-neg2100.0%
sub-neg100.0%
+-commutative100.0%
unsub-neg100.0%
metadata-eval100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
Taylor expanded in x around 0 98.5%
Final simplification98.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 58.9%
remove-double-neg58.9%
distribute-neg-frac58.9%
distribute-neg-in58.9%
sub-neg58.9%
distribute-frac-neg258.9%
sub-neg58.9%
+-commutative58.9%
unsub-neg58.9%
metadata-eval58.9%
neg-sub058.9%
associate-+l-58.9%
neg-sub058.9%
+-commutative58.9%
unsub-neg58.9%
Simplified58.9%
Taylor expanded in x around 0 55.4%
Final simplification55.4%
herbie shell --seed 2024039
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))