Average Error: 0.0 → 0.6
Time: 4.9s
Precision: binary64
Cost: 968
\[\frac{1}{x - 1} + \frac{x}{x + 1} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -3.1491243737238447 \cdot 10^{+164}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 217.42425346235066:\\ \;\;\;\;\frac{-1 - x \cdot x}{1 - x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
(FPCore (x) :precision binary64 (+ (/ 1.0 (- x 1.0)) (/ x (+ x 1.0))))
(FPCore (x)
 :precision binary64
 (if (<= x -3.1491243737238447e+164)
   1.0
   (if (<= x 217.42425346235066) (/ (- -1.0 (* x x)) (- 1.0 (* x x))) 1.0)))
double code(double x) {
	return (1.0 / (x - 1.0)) + (x / (x + 1.0));
}
double code(double x) {
	double tmp;
	if (x <= -3.1491243737238447e+164) {
		tmp = 1.0;
	} else if (x <= 217.42425346235066) {
		tmp = (-1.0 - (x * x)) / (1.0 - (x * x));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 / (x - 1.0d0)) + (x / (x + 1.0d0))
end function
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-3.1491243737238447d+164)) then
        tmp = 1.0d0
    else if (x <= 217.42425346235066d0) then
        tmp = ((-1.0d0) - (x * x)) / (1.0d0 - (x * x))
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x) {
	return (1.0 / (x - 1.0)) + (x / (x + 1.0));
}
public static double code(double x) {
	double tmp;
	if (x <= -3.1491243737238447e+164) {
		tmp = 1.0;
	} else if (x <= 217.42425346235066) {
		tmp = (-1.0 - (x * x)) / (1.0 - (x * x));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x):
	return (1.0 / (x - 1.0)) + (x / (x + 1.0))
def code(x):
	tmp = 0
	if x <= -3.1491243737238447e+164:
		tmp = 1.0
	elif x <= 217.42425346235066:
		tmp = (-1.0 - (x * x)) / (1.0 - (x * x))
	else:
		tmp = 1.0
	return tmp
function code(x)
	return Float64(Float64(1.0 / Float64(x - 1.0)) + Float64(x / Float64(x + 1.0)))
end
function code(x)
	tmp = 0.0
	if (x <= -3.1491243737238447e+164)
		tmp = 1.0;
	elseif (x <= 217.42425346235066)
		tmp = Float64(Float64(-1.0 - Float64(x * x)) / Float64(1.0 - Float64(x * x)));
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp = code(x)
	tmp = (1.0 / (x - 1.0)) + (x / (x + 1.0));
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -3.1491243737238447e+164)
		tmp = 1.0;
	elseif (x <= 217.42425346235066)
		tmp = (-1.0 - (x * x)) / (1.0 - (x * x));
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_] := N[(N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision] + N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -3.1491243737238447e+164], 1.0, If[LessEqual[x, 217.42425346235066], N[(N[(-1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]]
\frac{1}{x - 1} + \frac{x}{x + 1}
\begin{array}{l}
\mathbf{if}\;x \leq -3.1491243737238447 \cdot 10^{+164}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 217.42425346235066:\\
\;\;\;\;\frac{-1 - x \cdot x}{1 - x \cdot x}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if x < -3.1491243737238447e164 or 217.424253462350663 < x

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, 1 - x, -1 - x\right)}{\left(1 - x\right) \cdot \left(1 + x\right)}} \]
    3. Taylor expanded in x around 0 42.1

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

      \[\leadsto \frac{\color{blue}{-1 - x \cdot x}}{\left(1 - x\right) \cdot \left(1 + x\right)} \]
      Proof
    5. Taylor expanded in x around 0 42.1

      \[\leadsto \frac{-1 - x \cdot x}{\color{blue}{1 + -1 \cdot {x}^{2}}} \]
    6. Simplified42.1

      \[\leadsto \frac{-1 - x \cdot x}{\color{blue}{1 - x \cdot x}} \]
      Proof
    7. Taylor expanded in x around inf 0.2

      \[\leadsto \color{blue}{1} \]

    if -3.1491243737238447e164 < x < 217.424253462350663

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, 1 - x, -1 - x\right)}{\left(1 - x\right) \cdot \left(1 + x\right)}} \]
    3. Taylor expanded in x around 0 0.8

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

      \[\leadsto \frac{\color{blue}{-1 - x \cdot x}}{\left(1 - x\right) \cdot \left(1 + x\right)} \]
      Proof
    5. Taylor expanded in x around 0 0.8

      \[\leadsto \frac{-1 - x \cdot x}{\color{blue}{1 + -1 \cdot {x}^{2}}} \]
    6. Simplified0.8

      \[\leadsto \frac{-1 - x \cdot x}{\color{blue}{1 - x \cdot x}} \]
      Proof
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error0.0
Cost13440
\[\sqrt[3]{{\left(x + -1\right)}^{-3}} + \frac{x}{x + 1} \]
Alternative 2
Error0.7
Cost904
\[\begin{array}{l} t_0 := \frac{x}{x + 1}\\ \mathbf{if}\;x \leq -24.77383574916951:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 0.0014330358898819087:\\ \;\;\;\;\left(-\left(1 + x\right)\right) + t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + t_0\\ \end{array} \]
Alternative 3
Error0.7
Cost840
\[\begin{array}{l} t_0 := \frac{1}{x} + \frac{x}{x + 1}\\ \mathbf{if}\;x \leq -0.6424099020955067:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.0014330358898819087:\\ \;\;\;\;\frac{1}{x - 1} + x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.7
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -24.77383574916951:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 0.0014330358898819087:\\ \;\;\;\;\frac{1}{x - 1} + x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 5
Error0.0
Cost704
\[\frac{1}{x - 1} + \frac{x}{x + 1} \]
Alternative 6
Error0.7
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -24.77383574916951:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 0.0014330358898819087:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 7
Error32.2
Cost64
\[1 \]

Error

Reproduce

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