?

Average Accuracy: 84.1% → 99.9%
Time: 9.3s
Precision: binary64
Cost: 704

?

\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
\[\frac{\frac{2}{x + 1}}{x \cdot \left(x + -1\right)} \]
(FPCore (x)
 :precision binary64
 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x) :precision binary64 (/ (/ 2.0 (+ x 1.0)) (* x (+ x -1.0))))
double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
double code(double x) {
	return (2.0 / (x + 1.0)) / (x * (x + -1.0));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = ((1.0d0 / (x + 1.0d0)) - (2.0d0 / x)) + (1.0d0 / (x - 1.0d0))
end function
real(8) function code(x)
    real(8), intent (in) :: x
    code = (2.0d0 / (x + 1.0d0)) / (x * (x + (-1.0d0)))
end function
public static double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
public static double code(double x) {
	return (2.0 / (x + 1.0)) / (x * (x + -1.0));
}
def code(x):
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
def code(x):
	return (2.0 / (x + 1.0)) / (x * (x + -1.0))
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)
	return Float64(Float64(2.0 / Float64(x + 1.0)) / Float64(x * Float64(x + -1.0)))
end
function tmp = code(x)
	tmp = ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
end
function tmp = code(x)
	tmp = (2.0 / (x + 1.0)) / (x * (x + -1.0));
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_] := N[(N[(2.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\frac{\frac{2}{x + 1}}{x \cdot \left(x + -1\right)}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original84.1%
Target99.5%
Herbie99.9%
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)} \]

Derivation?

  1. Initial program 84.1%

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

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

    [Start]84.1

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

    associate-+l- [=>]84.1

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

    sub-neg [=>]84.1

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

    neg-mul-1 [=>]84.1

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

    metadata-eval [<=]84.1

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

    cancel-sign-sub-inv [<=]84.1

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

    +-commutative [=>]84.1

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

    *-lft-identity [=>]84.1

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

    sub-neg [=>]84.1

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

    metadata-eval [=>]84.1

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

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

    [Start]84.1

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

    frac-sub [=>]59.0

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

    frac-sub [=>]59.9

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

    *-un-lft-identity [<=]59.9

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

    distribute-rgt-in [=>]59.7

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

    neg-mul-1 [<=]59.7

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

    sub-neg [<=]59.7

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

    *-rgt-identity [=>]59.7

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

    distribute-rgt-in [=>]59.7

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

    metadata-eval [=>]59.7

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

    metadata-eval [<=]59.7

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

    fma-def [=>]59.7

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

    metadata-eval [=>]59.7

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

    distribute-rgt-in [=>]59.7

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

    neg-mul-1 [<=]59.7

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

    sub-neg [<=]59.7

    \[ \frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \color{blue}{\left(x \cdot x - x\right)}} \]
  4. Simplified59.7%

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

    [Start]59.7

    \[ \frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)} \]

    +-commutative [=>]59.7

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

    remove-double-neg [<=]59.7

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

    metadata-eval [<=]59.7

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

    distribute-neg-in [<=]59.7

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

    neg-mul-1 [=>]59.7

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

    *-commutative [=>]59.7

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

    fma-udef [<=]59.7

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

    distribute-lft-neg-in [<=]59.7

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

    distribute-lft-neg-in [=>]59.7

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

    fma-udef [=>]59.7

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

    *-commutative [<=]59.7

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

    neg-mul-1 [<=]59.7

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

    distribute-neg-in [=>]59.7

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

    remove-double-neg [=>]59.7

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

    metadata-eval [=>]59.7

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

    +-commutative [=>]59.7

    \[ \frac{\left(x \cdot x - x\right) - \left(x + 1\right) \cdot \left(\mathsf{fma}\left(x, 2, -2\right) - x\right)}{\color{blue}{\left(x + 1\right)} \cdot \left(x \cdot x - x\right)} \]
  5. Taylor expanded in x around 0 99.5%

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

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

    [Start]99.5

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

    add-log-exp [=>]34.8

    \[ \color{blue}{\log \left(e^{\frac{2}{\left(x + 1\right) \cdot \left(x \cdot x - x\right)}}\right)} \]

    *-un-lft-identity [=>]34.8

    \[ \log \color{blue}{\left(1 \cdot e^{\frac{2}{\left(x + 1\right) \cdot \left(x \cdot x - x\right)}}\right)} \]

    log-prod [=>]34.8

    \[ \color{blue}{\log 1 + \log \left(e^{\frac{2}{\left(x + 1\right) \cdot \left(x \cdot x - x\right)}}\right)} \]

    metadata-eval [=>]34.8

    \[ \color{blue}{0} + \log \left(e^{\frac{2}{\left(x + 1\right) \cdot \left(x \cdot x - x\right)}}\right) \]

    add-log-exp [<=]99.5

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

    associate-/r* [=>]99.9

    \[ 0 + \color{blue}{\frac{\frac{2}{x + 1}}{x \cdot x - x}} \]

    *-un-lft-identity [=>]99.9

    \[ 0 + \frac{\frac{2}{x + 1}}{x \cdot x - \color{blue}{1 \cdot x}} \]

    distribute-rgt-out-- [=>]99.9

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

    sub-neg [=>]99.9

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

    metadata-eval [=>]99.9

    \[ 0 + \frac{\frac{2}{x + 1}}{x \cdot \left(x + \color{blue}{-1}\right)} \]
  7. Final simplification99.9%

    \[\leadsto \frac{\frac{2}{x + 1}}{x \cdot \left(x + -1\right)} \]

Alternatives

Alternative 1
Accuracy99.9%
Cost832
\[\frac{2}{x + 1} \cdot \frac{1}{x \cdot \left(x + -1\right)} \]
Alternative 2
Accuracy98.7%
Cost777
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{-2}{x \cdot \left(x \cdot \left(-x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;x \cdot -2 - \frac{2}{x}\\ \end{array} \]
Alternative 3
Accuracy75.2%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{-1}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{x} - x\\ \end{array} \]
Alternative 4
Accuracy75.6%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{-1}{x \cdot x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\frac{-2}{x} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot x}\\ \end{array} \]
Alternative 5
Accuracy99.5%
Cost576
\[\frac{-2}{x \cdot \left(1 - x \cdot x\right)} \]
Alternative 6
Accuracy82.6%
Cost448
\[1 - \left(\frac{2}{x} - -1\right) \]
Alternative 7
Accuracy51.4%
Cost192
\[\frac{-2}{x} \]
Alternative 8
Accuracy3.3%
Cost64
\[-1 \]

Error

Reproduce?

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