Average Error: 29.5 → 0.5
Time: 5.5s
Precision: binary64
Cost: 8388
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{x}{x + 1}\\ \mathbf{if}\;t_0 + \frac{-1 - x}{x + -1} \leq 0:\\ \;\;\;\;\frac{-3}{x} + \frac{\frac{-1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \left(x + 1\right) \cdot \frac{-1 - x}{\mathsf{fma}\left(x, x, -1\right)}\\ \end{array} \]
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ x (+ x 1.0))))
   (if (<= (+ t_0 (/ (- -1.0 x) (+ x -1.0))) 0.0)
     (+ (/ -3.0 x) (/ (/ -1.0 x) x))
     (+ t_0 (* (+ x 1.0) (/ (- -1.0 x) (fma x x -1.0)))))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double t_0 = x / (x + 1.0);
	double tmp;
	if ((t_0 + ((-1.0 - x) / (x + -1.0))) <= 0.0) {
		tmp = (-3.0 / x) + ((-1.0 / x) / x);
	} else {
		tmp = t_0 + ((x + 1.0) * ((-1.0 - x) / fma(x, x, -1.0)));
	}
	return tmp;
}
function code(x)
	return Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0)))
end
function code(x)
	t_0 = Float64(x / Float64(x + 1.0))
	tmp = 0.0
	if (Float64(t_0 + Float64(Float64(-1.0 - x) / Float64(x + -1.0))) <= 0.0)
		tmp = Float64(Float64(-3.0 / x) + Float64(Float64(-1.0 / x) / x));
	else
		tmp = Float64(t_0 + Float64(Float64(x + 1.0) * Float64(Float64(-1.0 - x) / fma(x, x, -1.0))));
	end
	return tmp
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]
code[x_] := Block[{t$95$0 = N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 + N[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(-3.0 / x), $MachinePrecision] + N[(N[(-1.0 / x), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[(N[(x + 1.0), $MachinePrecision] * N[(N[(-1.0 - x), $MachinePrecision] / N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
\mathbf{if}\;t_0 + \frac{-1 - x}{x + -1} \leq 0:\\
\;\;\;\;\frac{-3}{x} + \frac{\frac{-1}{x}}{x}\\

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


\end{array}

Error

Derivation

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

    1. Initial program 59.4

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded in x around inf 0.7

      \[\leadsto \color{blue}{-\left(\frac{1}{{x}^{2}} + 3 \cdot \frac{1}{x}\right)} \]
    3. Simplified0.4

      \[\leadsto \color{blue}{\frac{-3}{x} - \frac{\frac{1}{x}}{x}} \]
      Proof
      (-.f64 (/.f64 -3 x) (/.f64 (/.f64 1 x) x)): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 (Rewrite<= metadata-eval (neg.f64 3)) x) (/.f64 (/.f64 1 x) x)): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 3 x))) (/.f64 (/.f64 1 x) x)): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (/.f64 (Rewrite<= metadata-eval (*.f64 3 1)) x)) (/.f64 (/.f64 1 x) x)): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (Rewrite<= associate-*r/_binary64 (*.f64 3 (/.f64 1 x)))) (/.f64 (/.f64 1 x) x)): 39 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 x))) (Rewrite<= associate-/r*_binary64 (/.f64 1 (*.f64 x x)))): 14 points increase in error, 12 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 x))) (/.f64 1 (Rewrite<= unpow2_binary64 (pow.f64 x 2)))): 1 points increase in error, 0 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (neg.f64 (*.f64 3 (/.f64 1 x))) (neg.f64 (/.f64 1 (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 (*.f64 3 (/.f64 1 x)) (/.f64 1 (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
      (neg.f64 (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 1 (pow.f64 x 2)) (*.f64 3 (/.f64 1 x))))): 0 points increase in error, 0 points decrease in error

    if 0.0 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 0.6

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Applied egg-rr0.6

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{x + 1}{\mathsf{fma}\left(x, x, -1\right)} \cdot \left(x + 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1} \leq 0:\\ \;\;\;\;\frac{-3}{x} + \frac{\frac{-1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x + 1} + \left(x + 1\right) \cdot \frac{-1 - x}{\mathsf{fma}\left(x, x, -1\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error0.5
Cost1732
\[\begin{array}{l} t_0 := \frac{x}{x + 1} + \frac{-1 - x}{x + -1}\\ \mathbf{if}\;t_0 \leq 0:\\ \;\;\;\;\frac{-3}{x} + \frac{\frac{-1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error1.4
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -536393854973384900:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 0.47159077191104254:\\ \;\;\;\;1 + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x} + \frac{\frac{-1}{x}}{x}\\ \end{array} \]
Alternative 3
Error1.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -536393854973384900:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 0.47159077191104254:\\ \;\;\;\;1 + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 4
Error1.9
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -536393854973384900:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 0.47159077191104254:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 5
Error31.7
Cost64
\[1 \]

Error

Reproduce

herbie shell --seed 2022290 
(FPCore (x)
  :name "Asymptote C"
  :precision binary64
  (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))