Asymptote A

Percentage Accurate: 77.5% → 99.9%
Time: 3.8s
Alternatives: 5
Speedup: 1.6×

Specification

?
\[\begin{array}{l} \\ \frac{1}{x + 1} - \frac{1}{x - 1} \end{array} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))
double code(double x) {
	return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 / (x + 1.0d0)) - (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
	return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
def code(x):
	return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0))
function code(x)
	return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / Float64(x - 1.0)))
end
function tmp = code(x)
	tmp = (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{x + 1} - \frac{1}{x - 1}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 5 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 77.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{x + 1} - \frac{1}{x - 1} \end{array} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))
double code(double x) {
	return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 / (x + 1.0d0)) - (1.0d0 / (x - 1.0d0))
end function
public static double code(double x) {
	return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
def code(x):
	return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0))
function code(x)
	return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / Float64(x - 1.0)))
end
function tmp = code(x)
	tmp = (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{x + 1} - \frac{1}{x - 1}
\end{array}

Alternative 1: 99.9% accurate, 1.2× speedup?

\[\begin{array}{l} x = |x|\\ \\ \frac{\frac{2}{-1 - x}}{-1 + x} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x) :precision binary64 (/ (/ 2.0 (- -1.0 x)) (+ -1.0 x)))
x = abs(x);
double code(double x) {
	return (2.0 / (-1.0 - x)) / (-1.0 + x);
}
NOTE: x should be positive before calling this function
real(8) function code(x)
    real(8), intent (in) :: x
    code = (2.0d0 / ((-1.0d0) - x)) / ((-1.0d0) + x)
end function
x = Math.abs(x);
public static double code(double x) {
	return (2.0 / (-1.0 - x)) / (-1.0 + x);
}
x = abs(x)
def code(x):
	return (2.0 / (-1.0 - x)) / (-1.0 + x)
x = abs(x)
function code(x)
	return Float64(Float64(2.0 / Float64(-1.0 - x)) / Float64(-1.0 + x))
end
x = abs(x)
function tmp = code(x)
	tmp = (2.0 / (-1.0 - x)) / (-1.0 + x);
end
NOTE: x should be positive before calling this function
code[x_] := N[(N[(2.0 / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(-1.0 + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
\frac{\frac{2}{-1 - x}}{-1 + x}
\end{array}
Derivation
  1. Initial program 79.0%

    \[\frac{1}{x + 1} - \frac{1}{x - 1} \]
  2. Step-by-step derivation
    1. frac-sub80.0%

      \[\leadsto \color{blue}{\frac{1 \cdot \left(x - 1\right) - \left(x + 1\right) \cdot 1}{\left(x + 1\right) \cdot \left(x - 1\right)}} \]
    2. associate-/r*80.0%

      \[\leadsto \color{blue}{\frac{\frac{1 \cdot \left(x - 1\right) - \left(x + 1\right) \cdot 1}{x + 1}}{x - 1}} \]
    3. *-un-lft-identity80.0%

      \[\leadsto \frac{\frac{\color{blue}{\left(x - 1\right)} - \left(x + 1\right) \cdot 1}{x + 1}}{x - 1} \]
    4. *-rgt-identity80.0%

      \[\leadsto \frac{\frac{\left(x - 1\right) - \color{blue}{\left(x + 1\right)}}{x + 1}}{x - 1} \]
    5. associate--l-80.3%

      \[\leadsto \frac{\frac{\color{blue}{x - \left(1 + \left(x + 1\right)\right)}}{x + 1}}{x - 1} \]
    6. +-commutative80.3%

      \[\leadsto \frac{\frac{x - \left(1 + \color{blue}{\left(1 + x\right)}\right)}{x + 1}}{x - 1} \]
    7. +-commutative80.3%

      \[\leadsto \frac{\frac{x - \left(1 + \left(1 + x\right)\right)}{\color{blue}{1 + x}}}{x - 1} \]
    8. sub-neg80.3%

      \[\leadsto \frac{\frac{x - \left(1 + \left(1 + x\right)\right)}{1 + x}}{\color{blue}{x + \left(-1\right)}} \]
    9. metadata-eval80.3%

      \[\leadsto \frac{\frac{x - \left(1 + \left(1 + x\right)\right)}{1 + x}}{x + \color{blue}{-1}} \]
  3. Applied egg-rr80.3%

    \[\leadsto \color{blue}{\frac{\frac{x - \left(1 + \left(1 + x\right)\right)}{1 + x}}{x + -1}} \]
  4. Step-by-step derivation
    1. frac-2neg80.3%

      \[\leadsto \frac{\color{blue}{\frac{-\left(x - \left(1 + \left(1 + x\right)\right)\right)}{-\left(1 + x\right)}}}{x + -1} \]
    2. div-inv80.3%

      \[\leadsto \frac{\color{blue}{\left(-\left(x - \left(1 + \left(1 + x\right)\right)\right)\right) \cdot \frac{1}{-\left(1 + x\right)}}}{x + -1} \]
    3. associate-+r+80.3%

      \[\leadsto \frac{\left(-\left(x - \color{blue}{\left(\left(1 + 1\right) + x\right)}\right)\right) \cdot \frac{1}{-\left(1 + x\right)}}{x + -1} \]
    4. metadata-eval80.3%

      \[\leadsto \frac{\left(-\left(x - \left(\color{blue}{2} + x\right)\right)\right) \cdot \frac{1}{-\left(1 + x\right)}}{x + -1} \]
    5. +-commutative80.3%

      \[\leadsto \frac{\left(-\left(x - \color{blue}{\left(x + 2\right)}\right)\right) \cdot \frac{1}{-\left(1 + x\right)}}{x + -1} \]
    6. distribute-neg-in80.3%

      \[\leadsto \frac{\left(-\left(x - \left(x + 2\right)\right)\right) \cdot \frac{1}{\color{blue}{\left(-1\right) + \left(-x\right)}}}{x + -1} \]
    7. metadata-eval80.3%

      \[\leadsto \frac{\left(-\left(x - \left(x + 2\right)\right)\right) \cdot \frac{1}{\color{blue}{-1} + \left(-x\right)}}{x + -1} \]
  5. Applied egg-rr80.3%

    \[\leadsto \frac{\color{blue}{\left(-\left(x - \left(x + 2\right)\right)\right) \cdot \frac{1}{-1 + \left(-x\right)}}}{x + -1} \]
  6. Step-by-step derivation
    1. associate-*r/80.3%

      \[\leadsto \frac{\color{blue}{\frac{\left(-\left(x - \left(x + 2\right)\right)\right) \cdot 1}{-1 + \left(-x\right)}}}{x + -1} \]
    2. *-rgt-identity80.3%

      \[\leadsto \frac{\frac{\color{blue}{-\left(x - \left(x + 2\right)\right)}}{-1 + \left(-x\right)}}{x + -1} \]
    3. neg-sub080.3%

      \[\leadsto \frac{\frac{\color{blue}{0 - \left(x - \left(x + 2\right)\right)}}{-1 + \left(-x\right)}}{x + -1} \]
    4. associate-+l-80.3%

      \[\leadsto \frac{\frac{\color{blue}{\left(0 - x\right) + \left(x + 2\right)}}{-1 + \left(-x\right)}}{x + -1} \]
    5. neg-sub080.3%

      \[\leadsto \frac{\frac{\color{blue}{\left(-x\right)} + \left(x + 2\right)}{-1 + \left(-x\right)}}{x + -1} \]
    6. associate-+r+99.9%

      \[\leadsto \frac{\frac{\color{blue}{\left(\left(-x\right) + x\right) + 2}}{-1 + \left(-x\right)}}{x + -1} \]
    7. neg-sub099.9%

      \[\leadsto \frac{\frac{\left(\color{blue}{\left(0 - x\right)} + x\right) + 2}{-1 + \left(-x\right)}}{x + -1} \]
    8. associate-+l-99.9%

      \[\leadsto \frac{\frac{\color{blue}{\left(0 - \left(x - x\right)\right)} + 2}{-1 + \left(-x\right)}}{x + -1} \]
    9. +-inverses99.9%

      \[\leadsto \frac{\frac{\left(0 - \color{blue}{0}\right) + 2}{-1 + \left(-x\right)}}{x + -1} \]
    10. metadata-eval99.9%

      \[\leadsto \frac{\frac{\color{blue}{0} + 2}{-1 + \left(-x\right)}}{x + -1} \]
    11. metadata-eval99.9%

      \[\leadsto \frac{\frac{\color{blue}{2}}{-1 + \left(-x\right)}}{x + -1} \]
    12. unsub-neg99.9%

      \[\leadsto \frac{\frac{2}{\color{blue}{-1 - x}}}{x + -1} \]
  7. Simplified99.9%

    \[\leadsto \frac{\color{blue}{\frac{2}{-1 - x}}}{x + -1} \]
  8. Final simplification99.9%

    \[\leadsto \frac{\frac{2}{-1 - x}}{-1 + x} \]

Alternative 2: 98.9% accurate, 1.0× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\frac{1}{x + 1} + \left(x - -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-2}{x}}{x}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x)
 :precision binary64
 (if (<= x 1.0) (+ (/ 1.0 (+ x 1.0)) (- x -1.0)) (/ (/ -2.0 x) x)))
x = abs(x);
double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = (1.0 / (x + 1.0)) + (x - -1.0);
	} else {
		tmp = (-2.0 / x) / x;
	}
	return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 1.0d0) then
        tmp = (1.0d0 / (x + 1.0d0)) + (x - (-1.0d0))
    else
        tmp = ((-2.0d0) / x) / x
    end if
    code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = (1.0 / (x + 1.0)) + (x - -1.0);
	} else {
		tmp = (-2.0 / x) / x;
	}
	return tmp;
}
x = abs(x)
def code(x):
	tmp = 0
	if x <= 1.0:
		tmp = (1.0 / (x + 1.0)) + (x - -1.0)
	else:
		tmp = (-2.0 / x) / x
	return tmp
x = abs(x)
function code(x)
	tmp = 0.0
	if (x <= 1.0)
		tmp = Float64(Float64(1.0 / Float64(x + 1.0)) + Float64(x - -1.0));
	else
		tmp = Float64(Float64(-2.0 / x) / x);
	end
	return tmp
end
x = abs(x)
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 1.0)
		tmp = (1.0 / (x + 1.0)) + (x - -1.0);
	else
		tmp = (-2.0 / x) / x;
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
code[x_] := If[LessEqual[x, 1.0], N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(x - -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\frac{1}{x + 1} + \left(x - -1\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{-2}{x}}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1

    1. Initial program 84.0%

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

      \[\leadsto \frac{1}{x + 1} - \color{blue}{\left(-1 \cdot x - 1\right)} \]
    3. Step-by-step derivation
      1. sub-neg67.0%

        \[\leadsto \frac{1}{x + 1} - \color{blue}{\left(-1 \cdot x + \left(-1\right)\right)} \]
      2. metadata-eval67.0%

        \[\leadsto \frac{1}{x + 1} - \left(-1 \cdot x + \color{blue}{-1}\right) \]
      3. +-commutative67.0%

        \[\leadsto \frac{1}{x + 1} - \color{blue}{\left(-1 + -1 \cdot x\right)} \]
      4. neg-mul-167.0%

        \[\leadsto \frac{1}{x + 1} - \left(-1 + \color{blue}{\left(-x\right)}\right) \]
      5. unsub-neg67.0%

        \[\leadsto \frac{1}{x + 1} - \color{blue}{\left(-1 - x\right)} \]
    4. Simplified67.0%

      \[\leadsto \frac{1}{x + 1} - \color{blue}{\left(-1 - x\right)} \]

    if 1 < x

    1. Initial program 62.4%

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

      \[\leadsto \color{blue}{\frac{-2}{{x}^{2}}} \]
    3. Step-by-step derivation
      1. unpow298.7%

        \[\leadsto \frac{-2}{\color{blue}{x \cdot x}} \]
    4. Simplified98.7%

      \[\leadsto \color{blue}{\frac{-2}{x \cdot x}} \]
    5. Step-by-step derivation
      1. associate-/r*99.7%

        \[\leadsto \color{blue}{\frac{\frac{-2}{x}}{x}} \]
      2. div-inv99.6%

        \[\leadsto \color{blue}{\frac{-2}{x} \cdot \frac{1}{x}} \]
    6. Applied egg-rr99.6%

      \[\leadsto \color{blue}{\frac{-2}{x} \cdot \frac{1}{x}} \]
    7. Step-by-step derivation
      1. un-div-inv99.7%

        \[\leadsto \color{blue}{\frac{\frac{-2}{x}}{x}} \]
    8. Applied egg-rr99.7%

      \[\leadsto \color{blue}{\frac{\frac{-2}{x}}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification74.6%

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

Alternative 3: 98.4% accurate, 1.6× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{x \cdot x}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ -2.0 (* x x))))
x = abs(x);
double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = 2.0;
	} else {
		tmp = -2.0 / (x * x);
	}
	return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 1.0d0) then
        tmp = 2.0d0
    else
        tmp = (-2.0d0) / (x * x)
    end if
    code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = 2.0;
	} else {
		tmp = -2.0 / (x * x);
	}
	return tmp;
}
x = abs(x)
def code(x):
	tmp = 0
	if x <= 1.0:
		tmp = 2.0
	else:
		tmp = -2.0 / (x * x)
	return tmp
x = abs(x)
function code(x)
	tmp = 0.0
	if (x <= 1.0)
		tmp = 2.0;
	else
		tmp = Float64(-2.0 / Float64(x * x));
	end
	return tmp
end
x = abs(x)
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 1.0)
		tmp = 2.0;
	else
		tmp = -2.0 / (x * x);
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(-2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\

\mathbf{else}:\\
\;\;\;\;\frac{-2}{x \cdot x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1

    1. Initial program 84.0%

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

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

    if 1 < x

    1. Initial program 62.4%

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

      \[\leadsto \color{blue}{\frac{-2}{{x}^{2}}} \]
    3. Step-by-step derivation
      1. unpow298.7%

        \[\leadsto \frac{-2}{\color{blue}{x \cdot x}} \]
    4. Simplified98.7%

      \[\leadsto \color{blue}{\frac{-2}{x \cdot x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification74.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{x \cdot x}\\ \end{array} \]

Alternative 4: 98.9% accurate, 1.6× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-2}{x}}{x}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x) :precision binary64 (if (<= x 1.0) 2.0 (/ (/ -2.0 x) x)))
x = abs(x);
double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = 2.0;
	} else {
		tmp = (-2.0 / x) / x;
	}
	return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 1.0d0) then
        tmp = 2.0d0
    else
        tmp = ((-2.0d0) / x) / x
    end if
    code = tmp
end function
x = Math.abs(x);
public static double code(double x) {
	double tmp;
	if (x <= 1.0) {
		tmp = 2.0;
	} else {
		tmp = (-2.0 / x) / x;
	}
	return tmp;
}
x = abs(x)
def code(x):
	tmp = 0
	if x <= 1.0:
		tmp = 2.0
	else:
		tmp = (-2.0 / x) / x
	return tmp
x = abs(x)
function code(x)
	tmp = 0.0
	if (x <= 1.0)
		tmp = 2.0;
	else
		tmp = Float64(Float64(-2.0 / x) / x);
	end
	return tmp
end
x = abs(x)
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 1.0)
		tmp = 2.0;
	else
		tmp = (-2.0 / x) / x;
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
code[x_] := If[LessEqual[x, 1.0], 2.0, N[(N[(-2.0 / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;2\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{-2}{x}}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1

    1. Initial program 84.0%

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

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

    if 1 < x

    1. Initial program 62.4%

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

      \[\leadsto \color{blue}{\frac{-2}{{x}^{2}}} \]
    3. Step-by-step derivation
      1. unpow298.7%

        \[\leadsto \frac{-2}{\color{blue}{x \cdot x}} \]
    4. Simplified98.7%

      \[\leadsto \color{blue}{\frac{-2}{x \cdot x}} \]
    5. Step-by-step derivation
      1. associate-/r*99.7%

        \[\leadsto \color{blue}{\frac{\frac{-2}{x}}{x}} \]
      2. div-inv99.6%

        \[\leadsto \color{blue}{\frac{-2}{x} \cdot \frac{1}{x}} \]
    6. Applied egg-rr99.6%

      \[\leadsto \color{blue}{\frac{-2}{x} \cdot \frac{1}{x}} \]
    7. Step-by-step derivation
      1. un-div-inv99.7%

        \[\leadsto \color{blue}{\frac{\frac{-2}{x}}{x}} \]
    8. Applied egg-rr99.7%

      \[\leadsto \color{blue}{\frac{\frac{-2}{x}}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification74.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-2}{x}}{x}\\ \end{array} \]

Alternative 5: 51.2% accurate, 11.0× speedup?

\[\begin{array}{l} x = |x|\\ \\ 2 \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x) :precision binary64 2.0)
x = abs(x);
double code(double x) {
	return 2.0;
}
NOTE: x should be positive before calling this function
real(8) function code(x)
    real(8), intent (in) :: x
    code = 2.0d0
end function
x = Math.abs(x);
public static double code(double x) {
	return 2.0;
}
x = abs(x)
def code(x):
	return 2.0
x = abs(x)
function code(x)
	return 2.0
end
x = abs(x)
function tmp = code(x)
	tmp = 2.0;
end
NOTE: x should be positive before calling this function
code[x_] := 2.0
\begin{array}{l}
x = |x|\\
\\
2
\end{array}
Derivation
  1. Initial program 79.0%

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

    \[\leadsto \color{blue}{2} \]
  3. Final simplification52.1%

    \[\leadsto 2 \]

Reproduce

?
herbie shell --seed 2023199 
(FPCore (x)
  :name "Asymptote A"
  :precision binary64
  (- (/ 1.0 (+ x 1.0)) (/ 1.0 (- x 1.0))))