
(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 9 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
(let* ((t_0 (+ (/ x (+ x 1.0)) (/ (+ x 1.0) (- 1.0 x)))))
(if (<= t_0 5e-6)
(+ (- (/ -3.0 x) (pow x -2.0)) (/ -3.0 (pow x 3.0)))
t_0)))
double code(double x) {
double t_0 = (x / (x + 1.0)) + ((x + 1.0) / (1.0 - x));
double tmp;
if (t_0 <= 5e-6) {
tmp = ((-3.0 / x) - pow(x, -2.0)) + (-3.0 / pow(x, 3.0));
} 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 <= 5d-6) then
tmp = (((-3.0d0) / x) - (x ** (-2.0d0))) + ((-3.0d0) / (x ** 3.0d0))
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 <= 5e-6) {
tmp = ((-3.0 / x) - Math.pow(x, -2.0)) + (-3.0 / Math.pow(x, 3.0));
} 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 <= 5e-6: tmp = ((-3.0 / x) - math.pow(x, -2.0)) + (-3.0 / math.pow(x, 3.0)) 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 <= 5e-6) tmp = Float64(Float64(Float64(-3.0 / x) - (x ^ -2.0)) + Float64(-3.0 / (x ^ 3.0))); 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 <= 5e-6) tmp = ((-3.0 / x) - (x ^ -2.0)) + (-3.0 / (x ^ 3.0)); 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, 5e-6], N[(N[(N[(-3.0 / x), $MachinePrecision] - N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision] + N[(-3.0 / N[Power[x, 3.0], $MachinePrecision]), $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 5 \cdot 10^{-6}:\\
\;\;\;\;\left(\frac{-3}{x} - {x}^{-2}\right) + \frac{-3}{{x}^{3}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 5.00000000000000041e-6Initial 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.6%
frac-sub9.9%
+-commutative9.9%
distribute-neg-in9.9%
metadata-eval9.9%
sub-neg9.9%
*-commutative9.9%
*-un-lft-identity9.9%
+-commutative9.9%
distribute-neg-in9.9%
metadata-eval9.9%
sub-neg9.9%
Applied egg-rr9.9%
Taylor expanded in x around inf 99.6%
Taylor expanded in x around inf 99.2%
+-commutative99.2%
distribute-neg-in99.2%
distribute-neg-in99.2%
unsub-neg99.2%
associate-*r/99.7%
metadata-eval99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
unpow299.7%
associate-/r*99.7%
*-rgt-identity99.7%
associate-*r/99.7%
unpow-199.7%
unpow-199.7%
pow-sqr99.7%
metadata-eval99.7%
associate-*r/99.7%
metadata-eval99.7%
Simplified99.7%
if 5.00000000000000041e-6 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) Initial program 100.0%
Final simplification99.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (/ x (+ x 1.0)) (/ (+ x 1.0) (- 1.0 x)))))
(if (<= t_0 5e-6)
(/
(+ (+ 3.0 (* 2.0 (* (/ 1.0 x) (/ 1.0 x)))) (* 2.0 (/ -1.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 <= 5e-6) {
tmp = ((3.0 + (2.0 * ((1.0 / x) * (1.0 / x)))) + (2.0 * (-1.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 <= 5d-6) then
tmp = ((3.0d0 + (2.0d0 * ((1.0d0 / x) * (1.0d0 / x)))) + (2.0d0 * ((-1.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 <= 5e-6) {
tmp = ((3.0 + (2.0 * ((1.0 / x) * (1.0 / x)))) + (2.0 * (-1.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 <= 5e-6: tmp = ((3.0 + (2.0 * ((1.0 / x) * (1.0 / x)))) + (2.0 * (-1.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 <= 5e-6) tmp = Float64(Float64(Float64(3.0 + Float64(2.0 * Float64(Float64(1.0 / x) * Float64(1.0 / x)))) + Float64(2.0 * Float64(-1.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 <= 5e-6) tmp = ((3.0 + (2.0 * ((1.0 / x) * (1.0 / x)))) + (2.0 * (-1.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, 5e-6], N[(N[(N[(3.0 + N[(2.0 * N[(N[(1.0 / x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(-1.0 / x), $MachinePrecision]), $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 5 \cdot 10^{-6}:\\
\;\;\;\;\frac{\left(3 + 2 \cdot \left(\frac{1}{x} \cdot \frac{1}{x}\right)\right) + 2 \cdot \frac{-1}{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))) < 5.00000000000000041e-6Initial 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.6%
frac-sub9.9%
+-commutative9.9%
distribute-neg-in9.9%
metadata-eval9.9%
sub-neg9.9%
*-commutative9.9%
*-un-lft-identity9.9%
+-commutative9.9%
distribute-neg-in9.9%
metadata-eval9.9%
sub-neg9.9%
Applied egg-rr9.9%
Taylor expanded in x around inf 99.6%
metadata-eval99.6%
unpow299.6%
frac-times99.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 99.6%
mul-1-neg99.3%
sub-neg99.3%
Simplified99.6%
if 5.00000000000000041e-6 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) Initial program 100.0%
Final simplification99.8%
(FPCore (x) :precision binary64 (let* ((t_0 (+ (/ x (+ x 1.0)) (/ (+ x 1.0) (- 1.0 x))))) (if (<= t_0 5e-6) (/ (- 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 <= 5e-6) {
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 <= 5d-6) 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 <= 5e-6) {
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 <= 5e-6: 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 <= 5e-6) 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 <= 5e-6) 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, 5e-6], 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 5 \cdot 10^{-6}:\\
\;\;\;\;\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))) < 5.00000000000000041e-6Initial 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.6%
frac-sub9.9%
+-commutative9.9%
distribute-neg-in9.9%
metadata-eval9.9%
sub-neg9.9%
*-commutative9.9%
*-un-lft-identity9.9%
+-commutative9.9%
distribute-neg-in9.9%
metadata-eval9.9%
sub-neg9.9%
Applied egg-rr9.9%
Taylor expanded in x around inf 99.3%
associate-*r/99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in x around 0 99.3%
mul-1-neg99.3%
sub-neg99.3%
Simplified99.3%
if 5.00000000000000041e-6 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) Initial program 100.0%
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 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.6%
frac-sub9.9%
+-commutative9.9%
distribute-neg-in9.9%
metadata-eval9.9%
sub-neg9.9%
*-commutative9.9%
*-un-lft-identity9.9%
+-commutative9.9%
distribute-neg-in9.9%
metadata-eval9.9%
sub-neg9.9%
Applied egg-rr9.9%
Taylor expanded in x around inf 99.3%
associate-*r/99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in x around 0 99.3%
mul-1-neg99.3%
sub-neg99.3%
Simplified99.3%
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 98.5%
unpow298.5%
distribute-rgt-out98.5%
Simplified98.5%
Final simplification98.9%
(FPCore (x) :precision binary64 (if (<= x -1.0) (- (/ 3.0 (- 1.0 x)) (/ (/ 2.0 x) (- 1.0 x))) (if (<= x 0.85) (+ 1.0 (* x (+ x 3.0))) (/ (- 3.0 (/ 2.0 x)) (- 1.0 x)))))
double code(double x) {
double tmp;
if (x <= -1.0) {
tmp = (3.0 / (1.0 - x)) - ((2.0 / x) / (1.0 - x));
} else if (x <= 0.85) {
tmp = 1.0 + (x * (x + 3.0));
} else {
tmp = (3.0 - (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 = (3.0d0 / (1.0d0 - x)) - ((2.0d0 / x) / (1.0d0 - x))
else if (x <= 0.85d0) then
tmp = 1.0d0 + (x * (x + 3.0d0))
else
tmp = (3.0d0 - (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 = (3.0 / (1.0 - x)) - ((2.0 / x) / (1.0 - x));
} else if (x <= 0.85) {
tmp = 1.0 + (x * (x + 3.0));
} else {
tmp = (3.0 - (2.0 / x)) / (1.0 - x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -1.0: tmp = (3.0 / (1.0 - x)) - ((2.0 / x) / (1.0 - x)) elif x <= 0.85: tmp = 1.0 + (x * (x + 3.0)) else: tmp = (3.0 - (2.0 / x)) / (1.0 - x) return tmp
function code(x) tmp = 0.0 if (x <= -1.0) tmp = Float64(Float64(3.0 / Float64(1.0 - x)) - Float64(Float64(2.0 / x) / Float64(1.0 - x))); elseif (x <= 0.85) tmp = Float64(1.0 + Float64(x * Float64(x + 3.0))); else tmp = Float64(Float64(3.0 - 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 = (3.0 / (1.0 - x)) - ((2.0 / x) / (1.0 - x)); elseif (x <= 0.85) tmp = 1.0 + (x * (x + 3.0)); else tmp = (3.0 - (2.0 / x)) / (1.0 - x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -1.0], N[(N[(3.0 / N[(1.0 - x), $MachinePrecision]), $MachinePrecision] - N[(N[(2.0 / x), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.85], N[(1.0 + N[(x * N[(x + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(3.0 - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{3}{1 - x} - \frac{\frac{2}{x}}{1 - x}\\
\mathbf{elif}\;x \leq 0.85:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{3 - \frac{2}{x}}{1 - x}\\
\end{array}
\end{array}
if x < -1Initial program 8.3%
remove-double-neg8.3%
distribute-neg-frac8.3%
distribute-neg-in8.3%
sub-neg8.3%
distribute-frac-neg28.3%
sub-neg8.3%
+-commutative8.3%
unsub-neg8.3%
metadata-eval8.3%
neg-sub08.3%
associate-+l-8.3%
neg-sub08.3%
+-commutative8.3%
unsub-neg8.3%
Simplified8.3%
frac-2neg8.3%
clear-num8.4%
frac-sub9.4%
+-commutative9.4%
distribute-neg-in9.4%
metadata-eval9.4%
sub-neg9.4%
*-commutative9.4%
*-un-lft-identity9.4%
+-commutative9.4%
distribute-neg-in9.4%
metadata-eval9.4%
sub-neg9.4%
Applied egg-rr9.4%
Taylor expanded in x around inf 99.5%
associate-*r/99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in x around 0 99.5%
mul-1-neg99.5%
sub-neg99.5%
Simplified99.5%
div-sub99.5%
Applied egg-rr99.5%
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 98.5%
unpow298.5%
distribute-rgt-out98.5%
Simplified98.5%
if 0.849999999999999978 < x Initial program 8.7%
remove-double-neg8.7%
distribute-neg-frac8.7%
distribute-neg-in8.7%
sub-neg8.7%
distribute-frac-neg28.7%
sub-neg8.7%
+-commutative8.7%
unsub-neg8.7%
metadata-eval8.7%
neg-sub08.7%
associate-+l-8.7%
neg-sub08.7%
+-commutative8.7%
unsub-neg8.7%
Simplified8.7%
frac-2neg8.7%
clear-num8.7%
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 inf 99.0%
associate-*r/99.0%
metadata-eval99.0%
Simplified99.0%
Taylor expanded in x around 0 99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
Final simplification98.9%
(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.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%
Taylor expanded in x around inf 98.1%
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.5%
unpow298.5%
distribute-rgt-out98.5%
Simplified98.5%
Final simplification98.3%
(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.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%
Taylor expanded in x around inf 98.1%
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.1%
Final simplification98.1%
(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.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%
Taylor expanded in x around inf 98.1%
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 96.6%
Final simplification97.4%
(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 52.8%
remove-double-neg52.8%
distribute-neg-frac52.8%
distribute-neg-in52.8%
sub-neg52.8%
distribute-frac-neg252.8%
sub-neg52.8%
+-commutative52.8%
unsub-neg52.8%
metadata-eval52.8%
neg-sub052.8%
associate-+l-52.8%
neg-sub052.8%
+-commutative52.8%
unsub-neg52.8%
Simplified52.8%
Taylor expanded in x around 0 48.8%
Final simplification48.8%
herbie shell --seed 2024040
(FPCore (x)
:name "Asymptote C"
:precision binary64
(- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))