Average Error: 10.0 → 0.3
Time: 2.9s
Precision: binary64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{1}{x + -1}\\ t_1 := \left(\frac{1}{1 + x} + \frac{-2}{x}\right) + t_0\\ t_2 := t_0 + \left(e^{-\mathsf{log1p}\left(x\right)} + \frac{-2}{x}\right)\\ \mathbf{if}\;t_1 \leq -7.970778004113545:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 9.46923542724 \cdot 10^{-17}:\\ \;\;\;\;2 \cdot {x}^{-3}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
(FPCore (x)
 :precision binary64
 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ 1.0 (+ x -1.0)))
        (t_1 (+ (+ (/ 1.0 (+ 1.0 x)) (/ -2.0 x)) t_0))
        (t_2 (+ t_0 (+ (exp (- (log1p x))) (/ -2.0 x)))))
   (if (<= t_1 -7.970778004113545)
     t_2
     (if (<= t_1 9.46923542724e-17) (* 2.0 (pow x -3.0)) t_2))))
double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
double code(double x) {
	double t_0 = 1.0 / (x + -1.0);
	double t_1 = ((1.0 / (1.0 + x)) + (-2.0 / x)) + t_0;
	double t_2 = t_0 + (exp(-log1p(x)) + (-2.0 / x));
	double tmp;
	if (t_1 <= -7.970778004113545) {
		tmp = t_2;
	} else if (t_1 <= 9.46923542724e-17) {
		tmp = 2.0 * pow(x, -3.0);
	} else {
		tmp = t_2;
	}
	return tmp;
}
public static double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
public static double code(double x) {
	double t_0 = 1.0 / (x + -1.0);
	double t_1 = ((1.0 / (1.0 + x)) + (-2.0 / x)) + t_0;
	double t_2 = t_0 + (Math.exp(-Math.log1p(x)) + (-2.0 / x));
	double tmp;
	if (t_1 <= -7.970778004113545) {
		tmp = t_2;
	} else if (t_1 <= 9.46923542724e-17) {
		tmp = 2.0 * Math.pow(x, -3.0);
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x):
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
def code(x):
	t_0 = 1.0 / (x + -1.0)
	t_1 = ((1.0 / (1.0 + x)) + (-2.0 / x)) + t_0
	t_2 = t_0 + (math.exp(-math.log1p(x)) + (-2.0 / x))
	tmp = 0
	if t_1 <= -7.970778004113545:
		tmp = t_2
	elif t_1 <= 9.46923542724e-17:
		tmp = 2.0 * math.pow(x, -3.0)
	else:
		tmp = t_2
	return tmp
function code(x)
	return Float64(Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x - 1.0)))
end
function code(x)
	t_0 = Float64(1.0 / Float64(x + -1.0))
	t_1 = Float64(Float64(Float64(1.0 / Float64(1.0 + x)) + Float64(-2.0 / x)) + t_0)
	t_2 = Float64(t_0 + Float64(exp(Float64(-log1p(x))) + Float64(-2.0 / x)))
	tmp = 0.0
	if (t_1 <= -7.970778004113545)
		tmp = t_2;
	elseif (t_1 <= 9.46923542724e-17)
		tmp = Float64(2.0 * (x ^ -3.0));
	else
		tmp = t_2;
	end
	return tmp
end
code[x_] := N[(N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + N[(-2.0 / x), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 + N[(N[Exp[(-N[Log[1 + x], $MachinePrecision])], $MachinePrecision] + N[(-2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -7.970778004113545], t$95$2, If[LessEqual[t$95$1, 9.46923542724e-17], N[(2.0 * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
t_0 := \frac{1}{x + -1}\\
t_1 := \left(\frac{1}{1 + x} + \frac{-2}{x}\right) + t_0\\
t_2 := t_0 + \left(e^{-\mathsf{log1p}\left(x\right)} + \frac{-2}{x}\right)\\
\mathbf{if}\;t_1 \leq -7.970778004113545:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 9.46923542724 \cdot 10^{-17}:\\
\;\;\;\;2 \cdot {x}^{-3}\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.0
Target0.3
Herbie0.3
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)} \]

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -7.9707780041135452 or 9.4692354e-17 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1)))

    1. Initial program 0.1

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Applied egg-rr0.1

      \[\leadsto \left(\color{blue}{e^{-\mathsf{log1p}\left(x\right)}} - \frac{2}{x}\right) + \frac{1}{x - 1} \]

    if -7.9707780041135452 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 9.4692354e-17

    1. Initial program 19.9

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Applied egg-rr19.9

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + -1}\right)}\right)}^{3}} \]
    3. Taylor expanded in x around inf 1.1

      \[\leadsto {\color{blue}{\left(\frac{\sqrt[3]{2}}{x}\right)}}^{3} \]
    4. Applied egg-rr0.6

      \[\leadsto \color{blue}{2 \cdot {\left(\frac{1}{x}\right)}^{3}} \]
    5. Applied egg-rr0.4

      \[\leadsto 2 \cdot \color{blue}{\left(0 + {x}^{-3}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\frac{1}{1 + x} + \frac{-2}{x}\right) + \frac{1}{x + -1} \leq -7.970778004113545:\\ \;\;\;\;\frac{1}{x + -1} + \left(e^{-\mathsf{log1p}\left(x\right)} + \frac{-2}{x}\right)\\ \mathbf{elif}\;\left(\frac{1}{1 + x} + \frac{-2}{x}\right) + \frac{1}{x + -1} \leq 9.46923542724 \cdot 10^{-17}:\\ \;\;\;\;2 \cdot {x}^{-3}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x + -1} + \left(e^{-\mathsf{log1p}\left(x\right)} + \frac{-2}{x}\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022153 
(FPCore (x)
  :name "3frac (problem 3.3.3)"
  :precision binary64

  :herbie-target
  (/ 2.0 (* x (- (* x x) 1.0)))

  (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))