Average Error: 0.0 → 0.0
Time: 2.7s
Precision: binary64
Cost: 6976
$0 \leq x \land x \leq 1$
$\frac{x}{x + 1}$
$\frac{x}{\mathsf{fma}\left(x, x, -1\right)} \cdot \left(x + -1\right)$
(FPCore (x) :precision binary64 (/ x (+ x 1.0)))
(FPCore (x) :precision binary64 (* (/ x (fma x x -1.0)) (+ x -1.0)))
double code(double x) {
return x / (x + 1.0);
}

double code(double x) {
return (x / fma(x, x, -1.0)) * (x + -1.0);
}

function code(x)
return Float64(x / Float64(x + 1.0))
end

function code(x)
return Float64(Float64(x / fma(x, x, -1.0)) * Float64(x + -1.0))
end

code[x_] := N[(x / N[(x + 1.0), $MachinePrecision]),$MachinePrecision]

code[x_] := N[(N[(x / N[(x * x + -1.0), $MachinePrecision]),$MachinePrecision] * N[(x + -1.0), $MachinePrecision]),$MachinePrecision]

\frac{x}{x + 1}

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


Derivation

1. Initial program 0.0

$\frac{x}{x + 1}$
2. Applied egg-rr0.0

$\leadsto \color{blue}{\frac{x}{\mathsf{fma}\left(x, x, -1\right)} \cdot \left(x + -1\right)}$
3. Final simplification0.0

$\leadsto \frac{x}{\mathsf{fma}\left(x, x, -1\right)} \cdot \left(x + -1\right)$

Alternatives

Alternative 1
Error0.0
Cost448
$x \cdot \frac{1}{x + 1}$
Alternative 2
Error0.7
Cost320
$x - x \cdot x$
Alternative 3
Error0.0
Cost320
$\frac{x}{x + 1}$
Alternative 4
Error1.4
Cost64
$x$

Reproduce

herbie shell --seed 1
(FPCore (x)
:name "x/(x+1)"
:precision binary64
:pre (and (<= 0.0 x) (<= x 1.0))
(/ x (+ x 1.0)))