Average Error: 0.0 → 0.5
Time: 2.2s
Precision: binary64
Cost: 1090
\[\frac{1}{x - 1} + \frac{x}{x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0171651250769214:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.0121555451085444:\\ \;\;\;\;-1 - \left(x \cdot x\right) \cdot 2\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
\frac{1}{x - 1} + \frac{x}{x + 1}
\begin{array}{l}
\mathbf{if}\;x \leq -1.0171651250769214:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 1.0121555451085444:\\
\;\;\;\;-1 - \left(x \cdot x\right) \cdot 2\\

\mathbf{else}:\\
\;\;\;\;1\\

\end{array}
(FPCore (x) :precision binary64 (+ (/ 1.0 (- x 1.0)) (/ x (+ x 1.0))))
(FPCore (x)
 :precision binary64
 (if (<= x -1.0171651250769214)
   1.0
   (if (<= x 1.0121555451085444) (- -1.0 (* (* x x) 2.0)) 1.0)))
double code(double x) {
	return (1.0 / (x - 1.0)) + (x / (x + 1.0));
}
double code(double x) {
	double tmp;
	if (x <= -1.0171651250769214) {
		tmp = 1.0;
	} else if (x <= 1.0121555451085444) {
		tmp = -1.0 - ((x * x) * 2.0);
	} else {
		tmp = 1.0;
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Alternatives

Alternative 1
Error0.0
Cost13568
\[\sqrt[3]{{\left(\frac{1}{x + -1} + \frac{x}{x + 1}\right)}^{3}}\]
Alternative 2
Error0.0
Cost1088
\[\frac{x}{x + 1} + \left(x + 1\right) \cdot \frac{1}{-1 + x \cdot x}\]
Alternative 3
Error0.0
Cost704
\[\frac{1}{x + -1} + \frac{x}{x + 1}\]
Alternative 4
Error0.7
Cost706
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0171651250769214:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.0121555451085444:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 5
Error31.9
Cost64
\[1\]

Error

Derivation

  1. Split input into 2 regimes
  2. if x < -1.01716512507692136 or 1.0121555451085444 < x

    1. Initial program 0.7

      \[1\]

    if -1.01716512507692136 < x < 1.0121555451085444

    1. Initial program 0.0

      \[\frac{1}{x - 1} + \frac{x}{x + 1}\]
    2. Taylor expanded around 0 0.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.0171651250769214:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.0121555451085444:\\ \;\;\;\;-1 - \left(x \cdot x\right) \cdot 2\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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