Average Error: 9.7 → 0.3
Time: 11.6s
Precision: binary64
Cost: 16392
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{1}{1 + x}\\ t_1 := \left(t_0 + \frac{-2}{x}\right) + \frac{1}{x + -1}\\ \mathbf{if}\;t_1 \leq -20:\\ \;\;\;\;t_0 + \frac{x + -2}{x - x \cdot x}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{-30}:\\ \;\;\;\;2 \cdot {x}^{-3}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(x + -1\right) \cdot \left(\mathsf{fma}\left(x, x, -1\right) - x \cdot x\right)}{{\left(x + -1\right)}^{2}}}{\left(1 + x\right) \cdot \left(x \cdot -0.5\right)}\\ \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 (+ 1.0 x)))
        (t_1 (+ (+ t_0 (/ -2.0 x)) (/ 1.0 (+ x -1.0)))))
   (if (<= t_1 -20.0)
     (+ t_0 (/ (+ x -2.0) (- x (* x x))))
     (if (<= t_1 2e-30)
       (* 2.0 (pow x -3.0))
       (/
        (/ (* (+ x -1.0) (- (fma x x -1.0) (* x x))) (pow (+ x -1.0) 2.0))
        (* (+ 1.0 x) (* x -0.5)))))))
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 / (1.0 + x);
	double t_1 = (t_0 + (-2.0 / x)) + (1.0 / (x + -1.0));
	double tmp;
	if (t_1 <= -20.0) {
		tmp = t_0 + ((x + -2.0) / (x - (x * x)));
	} else if (t_1 <= 2e-30) {
		tmp = 2.0 * pow(x, -3.0);
	} else {
		tmp = (((x + -1.0) * (fma(x, x, -1.0) - (x * x))) / pow((x + -1.0), 2.0)) / ((1.0 + x) * (x * -0.5));
	}
	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(1.0 + x))
	t_1 = Float64(Float64(t_0 + Float64(-2.0 / x)) + Float64(1.0 / Float64(x + -1.0)))
	tmp = 0.0
	if (t_1 <= -20.0)
		tmp = Float64(t_0 + Float64(Float64(x + -2.0) / Float64(x - Float64(x * x))));
	elseif (t_1 <= 2e-30)
		tmp = Float64(2.0 * (x ^ -3.0));
	else
		tmp = Float64(Float64(Float64(Float64(x + -1.0) * Float64(fma(x, x, -1.0) - Float64(x * x))) / (Float64(x + -1.0) ^ 2.0)) / Float64(Float64(1.0 + x) * Float64(x * -0.5)));
	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[(1.0 + x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 + N[(-2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -20.0], N[(t$95$0 + N[(N[(x + -2.0), $MachinePrecision] / N[(x - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e-30], N[(2.0 * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x + -1.0), $MachinePrecision] * N[(N[(x * x + -1.0), $MachinePrecision] - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[N[(x + -1.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + x), $MachinePrecision] * N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
t_0 := \frac{1}{1 + x}\\
t_1 := \left(t_0 + \frac{-2}{x}\right) + \frac{1}{x + -1}\\
\mathbf{if}\;t_1 \leq -20:\\
\;\;\;\;t_0 + \frac{x + -2}{x - x \cdot x}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(x + -1\right) \cdot \left(\mathsf{fma}\left(x, x, -1\right) - x \cdot x\right)}{{\left(x + -1\right)}^{2}}}{\left(1 + x\right) \cdot \left(x \cdot -0.5\right)}\\


\end{array}

Error

Target

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

Derivation

  1. Split input into 3 regimes
  2. if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -20

    1. Initial program 0.0

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Simplified0.0

      \[\leadsto \color{blue}{\frac{1}{1 + x} + \left(\frac{1}{x + -1} + \frac{-2}{x}\right)} \]
      Proof
      (+.f64 (/.f64 1 (+.f64 1 x)) (+.f64 (/.f64 1 (+.f64 x -1)) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (Rewrite<= +-commutative_binary64 (+.f64 x 1))) (+.f64 (/.f64 1 (+.f64 x -1)) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (+.f64 x (Rewrite<= metadata-eval (neg.f64 1)))) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (Rewrite<= sub-neg_binary64 (-.f64 x 1))) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (-.f64 x 1)) (/.f64 (Rewrite<= metadata-eval (neg.f64 2)) x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (-.f64 x 1)) (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 2 x))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (Rewrite<= +-commutative_binary64 (+.f64 (neg.f64 (/.f64 2 x)) (/.f64 1 (-.f64 x 1))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (/.f64 1 (+.f64 x 1)) (neg.f64 (/.f64 2 x))) (/.f64 1 (-.f64 x 1)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= sub-neg_binary64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x))) (/.f64 1 (-.f64 x 1))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr0.0

      \[\leadsto \frac{1}{1 + x} + \color{blue}{\frac{\mathsf{fma}\left(x, -1, \left(x + -1\right) \cdot 2\right)}{\left(x + -1\right) \cdot \left(-x\right)}} \]
    4. Simplified0.0

      \[\leadsto \frac{1}{1 + x} + \color{blue}{\frac{\left(-2 + x \cdot 2\right) - x}{x - x \cdot x}} \]
      Proof
      (/.f64 (-.f64 (+.f64 -2 (*.f64 x 2)) x) (-.f64 x (*.f64 x x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (+.f64 (Rewrite<= metadata-eval (*.f64 -1 2)) (*.f64 x 2)) x) (-.f64 x (*.f64 x x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (Rewrite<= distribute-rgt-in_binary64 (*.f64 2 (+.f64 -1 x))) x) (-.f64 x (*.f64 x x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (*.f64 2 (Rewrite<= +-commutative_binary64 (+.f64 x -1))) x) (-.f64 x (*.f64 x x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 x -1) 2)) x) (-.f64 x (*.f64 x x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (Rewrite<= +-rgt-identity_binary64 (+.f64 (*.f64 (+.f64 x -1) 2) 0)) x) (-.f64 x (*.f64 x x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x -1) 2) 0) x) (-.f64 x (Rewrite<= unpow2_binary64 (pow.f64 x 2)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x -1) 2) 0) x) (Rewrite<= unsub-neg_binary64 (+.f64 x (neg.f64 (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x -1) 2) 0) x) (+.f64 (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 x))) (neg.f64 (pow.f64 x 2)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x -1) 2) 0) x) (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 (neg.f64 x) (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x -1) 2) 0) x) (neg.f64 (Rewrite=> +-commutative_binary64 (+.f64 (pow.f64 x 2) (neg.f64 x))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x -1) 2) 0) x) (neg.f64 (+.f64 (Rewrite=> unpow2_binary64 (*.f64 x x)) (neg.f64 x)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x -1) 2) 0) x) (neg.f64 (+.f64 (*.f64 x x) (Rewrite=> neg-mul-1_binary64 (*.f64 -1 x))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x -1) 2) 0) x) (neg.f64 (Rewrite<= distribute-rgt-in_binary64 (*.f64 x (+.f64 x -1))))): 1 points increase in error, 1 points decrease in error
      (Rewrite=> div-sub_binary64 (-.f64 (/.f64 (+.f64 (*.f64 (+.f64 x -1) 2) 0) (neg.f64 (*.f64 x (+.f64 x -1)))) (/.f64 x (neg.f64 (*.f64 x (+.f64 x -1)))))): 2 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 (Rewrite=> +-rgt-identity_binary64 (*.f64 (+.f64 x -1) 2)) (neg.f64 (*.f64 x (+.f64 x -1)))) (/.f64 x (neg.f64 (*.f64 x (+.f64 x -1))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= div-sub_binary64 (/.f64 (-.f64 (*.f64 (+.f64 x -1) 2) x) (neg.f64 (*.f64 x (+.f64 x -1))))): 0 points increase in error, 2 points decrease in error
      (/.f64 (Rewrite<= unsub-neg_binary64 (+.f64 (*.f64 (+.f64 x -1) 2) (neg.f64 x))) (neg.f64 (*.f64 x (+.f64 x -1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 (neg.f64 x) (*.f64 (+.f64 x -1) 2))) (neg.f64 (*.f64 x (+.f64 x -1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 x)) (*.f64 (+.f64 x -1) 2)) (neg.f64 (*.f64 x (+.f64 x -1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (Rewrite=> *-commutative_binary64 (*.f64 x -1)) (*.f64 (+.f64 x -1) 2)) (neg.f64 (*.f64 x (+.f64 x -1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= fma-udef_binary64 (fma.f64 x -1 (*.f64 (+.f64 x -1) 2))) (neg.f64 (*.f64 x (+.f64 x -1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (fma.f64 x -1 (*.f64 (+.f64 x -1) 2)) (Rewrite<= distribute-lft-neg-out_binary64 (*.f64 (neg.f64 x) (+.f64 x -1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (fma.f64 x -1 (*.f64 (+.f64 x -1) 2)) (Rewrite=> *-commutative_binary64 (*.f64 (+.f64 x -1) (neg.f64 x)))): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr64.0

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

      \[\leadsto \color{blue}{\frac{-2 + x}{x - x \cdot x} + \frac{1}{x + 1}} \]
      Proof
      (+.f64 (/.f64 (+.f64 -2 x) (-.f64 x (*.f64 x x))) (/.f64 1 (+.f64 x 1))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= expm1-log1p_binary64 (expm1.f64 (log1p.f64 (+.f64 (/.f64 (+.f64 -2 x) (-.f64 x (*.f64 x x))) (/.f64 1 (+.f64 x 1)))))): 124 points increase in error, 0 points decrease in error
      (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 (log1p.f64 (+.f64 (/.f64 (+.f64 -2 x) (-.f64 x (*.f64 x x))) (/.f64 1 (+.f64 x 1))))) 1)): 6 points increase in error, 71 points decrease in error

    if -20 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 2e-30

    1. Initial program 19.3

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Simplified19.3

      \[\leadsto \color{blue}{\frac{1}{1 + x} + \left(\frac{1}{x + -1} + \frac{-2}{x}\right)} \]
      Proof
      (+.f64 (/.f64 1 (+.f64 1 x)) (+.f64 (/.f64 1 (+.f64 x -1)) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (Rewrite<= +-commutative_binary64 (+.f64 x 1))) (+.f64 (/.f64 1 (+.f64 x -1)) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (+.f64 x (Rewrite<= metadata-eval (neg.f64 1)))) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (Rewrite<= sub-neg_binary64 (-.f64 x 1))) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (-.f64 x 1)) (/.f64 (Rewrite<= metadata-eval (neg.f64 2)) x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (-.f64 x 1)) (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 2 x))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (Rewrite<= +-commutative_binary64 (+.f64 (neg.f64 (/.f64 2 x)) (/.f64 1 (-.f64 x 1))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (/.f64 1 (+.f64 x 1)) (neg.f64 (/.f64 2 x))) (/.f64 1 (-.f64 x 1)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= sub-neg_binary64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x))) (/.f64 1 (-.f64 x 1))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in x around inf 0.9

      \[\leadsto \color{blue}{\frac{2}{{x}^{3}}} \]
    4. Applied egg-rr0.4

      \[\leadsto \color{blue}{{x}^{-3} \cdot 2} \]

    if 2e-30 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1)))

    1. Initial program 1.1

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

      \[\leadsto \color{blue}{\frac{1}{1 + x} + \left(\frac{1}{x + -1} + \frac{-2}{x}\right)} \]
      Proof
      (+.f64 (/.f64 1 (+.f64 1 x)) (+.f64 (/.f64 1 (+.f64 x -1)) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (Rewrite<= +-commutative_binary64 (+.f64 x 1))) (+.f64 (/.f64 1 (+.f64 x -1)) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (+.f64 x (Rewrite<= metadata-eval (neg.f64 1)))) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (Rewrite<= sub-neg_binary64 (-.f64 x 1))) (/.f64 -2 x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (-.f64 x 1)) (/.f64 (Rewrite<= metadata-eval (neg.f64 2)) x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (+.f64 (/.f64 1 (-.f64 x 1)) (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 2 x))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 1 (+.f64 x 1)) (Rewrite<= +-commutative_binary64 (+.f64 (neg.f64 (/.f64 2 x)) (/.f64 1 (-.f64 x 1))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (/.f64 1 (+.f64 x 1)) (neg.f64 (/.f64 2 x))) (/.f64 1 (-.f64 x 1)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= sub-neg_binary64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x))) (/.f64 1 (-.f64 x 1))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr7.0

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

      \[\leadsto \color{blue}{\frac{-2}{x} + \left(\frac{1}{x + -1} + \frac{1}{x - -1}\right)} \]
      Proof
      (+.f64 (/.f64 -2 x) (+.f64 (/.f64 1 (+.f64 x -1)) (/.f64 1 (-.f64 x -1)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 -2 x) (+.f64 (/.f64 1 (+.f64 x -1)) (/.f64 1 (Rewrite=> sub-neg_binary64 (+.f64 x (neg.f64 -1)))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 -2 x) (+.f64 (/.f64 1 (+.f64 x -1)) (/.f64 1 (+.f64 x (Rewrite=> metadata-eval 1))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 -2 x) (+.f64 (/.f64 1 (+.f64 x -1)) (/.f64 1 (Rewrite<= +-commutative_binary64 (+.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (/.f64 -2 x) (/.f64 1 (+.f64 x -1))) (/.f64 1 (+.f64 1 x)))): 1 points increase in error, 4 points decrease in error
      (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 1 (+.f64 x -1)) (/.f64 -2 x))) (/.f64 1 (+.f64 1 x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+r+_binary64 (+.f64 (/.f64 1 (+.f64 x -1)) (+.f64 (/.f64 -2 x) (/.f64 1 (+.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= expm1-log1p_binary64 (expm1.f64 (log1p.f64 (+.f64 (/.f64 1 (+.f64 x -1)) (+.f64 (/.f64 -2 x) (/.f64 1 (+.f64 1 x))))))): 124 points increase in error, 0 points decrease in error
      (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 (log1p.f64 (+.f64 (/.f64 1 (+.f64 x -1)) (+.f64 (/.f64 -2 x) (/.f64 1 (+.f64 1 x)))))) 1)): 4 points increase in error, 3 points decrease in error
    5. Applied egg-rr1.2

      \[\leadsto \frac{-2}{x} + \color{blue}{\frac{\frac{\left(x + 1\right) + \left(x + -1\right)}{x + -1}}{x + 1}} \]
    6. Applied egg-rr1.2

      \[\leadsto \color{blue}{\frac{\left(x + 1\right) + \left(x \cdot -0.5\right) \cdot \frac{x + x}{x + -1}}{\left(x \cdot -0.5\right) \cdot \left(x + 1\right)}} \]
    7. Applied egg-rr1.2

      \[\leadsto \frac{\color{blue}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(x, x, -1\right), x + -1, \left(x + -1\right) \cdot \left(x \cdot \left(-0.5 \cdot \left(x + x\right)\right)\right)\right)}{{\left(x + -1\right)}^{2}}}}{\left(x \cdot -0.5\right) \cdot \left(x + 1\right)} \]
    8. Simplified0.5

      \[\leadsto \frac{\color{blue}{\frac{\left(x + -1\right) \cdot \left(x \cdot \left(-x\right) + \mathsf{fma}\left(x, x, -1\right)\right)}{{\left(x + -1\right)}^{2}}}}{\left(x \cdot -0.5\right) \cdot \left(x + 1\right)} \]
      Proof
      (/.f64 (*.f64 (+.f64 x -1) (+.f64 (*.f64 x (neg.f64 x)) (fma.f64 x x -1))) (pow.f64 (+.f64 x -1) 2)): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 (+.f64 x -1) (+.f64 (*.f64 x (Rewrite=> neg-mul-1_binary64 (*.f64 -1 x))) (fma.f64 x x -1))) (pow.f64 (+.f64 x -1) 2)): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 (+.f64 x -1) (+.f64 (*.f64 x (*.f64 (Rewrite<= metadata-eval (*.f64 -1/2 2)) x)) (fma.f64 x x -1))) (pow.f64 (+.f64 x -1) 2)): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 (+.f64 x -1) (+.f64 (*.f64 x (Rewrite<= associate-*r*_binary64 (*.f64 -1/2 (*.f64 2 x)))) (fma.f64 x x -1))) (pow.f64 (+.f64 x -1) 2)): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 (+.f64 x -1) (+.f64 (*.f64 x (*.f64 -1/2 (Rewrite<= count-2_binary64 (+.f64 x x)))) (fma.f64 x x -1))) (pow.f64 (+.f64 x -1) 2)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 (+.f64 x -1) (*.f64 x (*.f64 -1/2 (+.f64 x x)))) (*.f64 (+.f64 x -1) (fma.f64 x x -1)))) (pow.f64 (+.f64 x -1) 2)): 29 points increase in error, 3 points decrease in error
      (/.f64 (+.f64 (*.f64 (+.f64 x -1) (*.f64 x (*.f64 -1/2 (+.f64 x x)))) (Rewrite<= *-commutative_binary64 (*.f64 (fma.f64 x x -1) (+.f64 x -1)))) (pow.f64 (+.f64 x -1) 2)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 (fma.f64 x x -1) (+.f64 x -1)) (*.f64 (+.f64 x -1) (*.f64 x (*.f64 -1/2 (+.f64 x x)))))) (pow.f64 (+.f64 x -1) 2)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= fma-udef_binary64 (fma.f64 (fma.f64 x x -1) (+.f64 x -1) (*.f64 (+.f64 x -1) (*.f64 x (*.f64 -1/2 (+.f64 x x)))))) (pow.f64 (+.f64 x -1) 2)): 41 points increase in error, 8 points decrease in error
  3. Recombined 3 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 -20:\\ \;\;\;\;\frac{1}{1 + x} + \frac{x + -2}{x - x \cdot x}\\ \mathbf{elif}\;\left(\frac{1}{1 + x} + \frac{-2}{x}\right) + \frac{1}{x + -1} \leq 2 \cdot 10^{-30}:\\ \;\;\;\;2 \cdot {x}^{-3}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(x + -1\right) \cdot \left(\mathsf{fma}\left(x, x, -1\right) - x \cdot x\right)}{{\left(x + -1\right)}^{2}}}{\left(1 + x\right) \cdot \left(x \cdot -0.5\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error0.4
Cost8712
\[\begin{array}{l} t_0 := \frac{1}{1 + x}\\ t_1 := \left(t_0 + \frac{-2}{x}\right) + \frac{1}{x + -1}\\ t_2 := x \cdot x - x\\ \mathbf{if}\;t_1 \leq -20:\\ \;\;\;\;t_0 + \frac{x + -2}{x - x \cdot x}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{-30}:\\ \;\;\;\;2 \cdot {x}^{-3}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + x\right) \cdot \left(2 - x\right) + t_2}{\left(1 + x\right) \cdot t_2}\\ \end{array} \]
Alternative 2
Error0.4
Cost3528
\[\begin{array}{l} t_0 := \frac{1}{1 + x}\\ t_1 := \left(t_0 + \frac{-2}{x}\right) + \frac{1}{x + -1}\\ t_2 := \left(1 + x\right) \cdot \left(x \cdot -0.5\right)\\ \mathbf{if}\;t_1 \leq -20:\\ \;\;\;\;t_0 + \frac{x + -2}{x - x \cdot x}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-22}:\\ \;\;\;\;\frac{\frac{-1}{x \cdot x} + \frac{-1}{x}}{t_2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + x\right) + \left(x \cdot -0.5\right) \cdot \frac{x + x}{x + -1}}{t_2}\\ \end{array} \]
Alternative 3
Error0.4
Cost3528
\[\begin{array}{l} t_0 := \frac{1}{1 + x}\\ t_1 := \left(t_0 + \frac{-2}{x}\right) + \frac{1}{x + -1}\\ t_2 := x \cdot x - x\\ \mathbf{if}\;t_1 \leq -20:\\ \;\;\;\;t_0 + \frac{x + -2}{x - x \cdot x}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{-30}:\\ \;\;\;\;\frac{\frac{-1}{x \cdot x} + \frac{-1}{x}}{\left(1 + x\right) \cdot \left(x \cdot -0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + x\right) \cdot \left(2 - x\right) + t_2}{\left(1 + x\right) \cdot t_2}\\ \end{array} \]
Alternative 4
Error0.4
Cost3272
\[\begin{array}{l} t_0 := \frac{1}{1 + x}\\ t_1 := \left(t_0 + \frac{-2}{x}\right) + \frac{1}{x + -1}\\ t_2 := \left(1 + x\right) \cdot \left(x \cdot -0.5\right)\\ \mathbf{if}\;t_1 \leq -20:\\ \;\;\;\;t_0 + \frac{x + -2}{x - x \cdot x}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-22}:\\ \;\;\;\;\frac{\frac{-1}{x \cdot x} + \frac{-1}{x}}{t_2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + x\right) + \frac{x \cdot x}{1 - x}}{t_2}\\ \end{array} \]
Alternative 5
Error0.4
Cost3144
\[\begin{array}{l} t_0 := \frac{1}{1 + x}\\ t_1 := \left(t_0 + \frac{-2}{x}\right) + \frac{1}{x + -1}\\ t_2 := t_0 + \frac{x + -2}{x - x \cdot x}\\ \mathbf{if}\;t_1 \leq -20:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-22}:\\ \;\;\;\;\frac{\frac{-1}{x \cdot x} + \frac{-1}{x}}{\left(1 + x\right) \cdot \left(x \cdot -0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error0.6
Cost3016
\[\begin{array}{l} t_0 := \left(\frac{1}{1 + x} + \frac{-2}{x}\right) + \frac{1}{x + -1}\\ \mathbf{if}\;t_0 \leq -20:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-22}:\\ \;\;\;\;\frac{\frac{-1}{x}}{\left(1 + x\right) \cdot \left(x \cdot -0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error0.6
Cost3016
\[\begin{array}{l} t_0 := \frac{1}{1 + x}\\ t_1 := \left(t_0 + \frac{-2}{x}\right) + \frac{1}{x + -1}\\ t_2 := t_0 + \frac{x + -2}{x - x \cdot x}\\ \mathbf{if}\;t_1 \leq -20:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-22}:\\ \;\;\;\;\frac{\frac{-1}{x}}{\left(1 + x\right) \cdot \left(x \cdot -0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 8
Error0.5
Cost1096
\[\begin{array}{l} t_0 := \frac{\frac{-1}{x}}{\left(1 + x\right) \cdot \left(x \cdot -0.5\right)}\\ \mathbf{if}\;x \leq -320000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 230000:\\ \;\;\;\;\frac{-2}{x} - \frac{x + x}{1 - x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error0.9
Cost968
\[\begin{array}{l} t_0 := \frac{\frac{-1}{x}}{\left(1 + x\right) \cdot \left(x \cdot -0.5\right)}\\ \mathbf{if}\;x \leq -0.85:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\frac{-2}{x} + x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error10.3
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{2}{x} - \frac{2}{x}\\ \mathbf{elif}\;x \leq 0.62:\\ \;\;\;\;\frac{-2}{x} + x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{x} + \frac{1}{x + -1}\\ \end{array} \]
Alternative 11
Error10.2
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -0.65:\\ \;\;\;\;\frac{1}{1 + x} + \frac{-1}{x}\\ \mathbf{elif}\;x \leq 0.62:\\ \;\;\;\;\frac{-2}{x} + x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{x} + \frac{1}{x + -1}\\ \end{array} \]
Alternative 12
Error10.5
Cost712
\[\begin{array}{l} t_0 := \frac{2}{x} - \frac{2}{x}\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\frac{-2}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 13
Error10.3
Cost712
\[\begin{array}{l} t_0 := \frac{2}{x} - \frac{2}{x}\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\frac{-2}{x} + x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 14
Error15.1
Cost584
\[\begin{array}{l} t_0 := \frac{-1}{x \cdot x}\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\frac{-2}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 15
Error14.8
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{-1}{x \cdot x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\frac{-2}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot x}\\ \end{array} \]
Alternative 16
Error30.5
Cost192
\[\frac{-2}{x} \]
Alternative 17
Error61.9
Cost64
\[1 \]

Error

Reproduce

herbie shell --seed 2022326 
(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))))