Average Error: 32.4 → 0
Time: 11.2s
Precision: 64
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[\mathsf{log1p}\left(\mathsf{expm1}\left(1 \cdot \left(-\frac{\left|x\right|}{x}\right)\right)\right) + 1\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\mathsf{log1p}\left(\mathsf{expm1}\left(1 \cdot \left(-\frac{\left|x\right|}{x}\right)\right)\right) + 1
double f(double x) {
        double r149519 = x;
        double r149520 = r149519 / r149519;
        double r149521 = 1.0;
        double r149522 = r149521 / r149519;
        double r149523 = r149519 * r149519;
        double r149524 = sqrt(r149523);
        double r149525 = r149522 * r149524;
        double r149526 = r149520 - r149525;
        return r149526;
}

double f(double x) {
        double r149527 = 1.0;
        double r149528 = x;
        double r149529 = fabs(r149528);
        double r149530 = r149529 / r149528;
        double r149531 = -r149530;
        double r149532 = r149527 * r149531;
        double r149533 = expm1(r149532);
        double r149534 = log1p(r149533);
        double r149535 = 1.0;
        double r149536 = r149534 + r149535;
        return r149536;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.4
Target0
Herbie0
\[\begin{array}{l} \mathbf{if}\;x \lt 0.0:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;0.0\\ \end{array}\]

Derivation

  1. Initial program 32.4

    \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
  2. Simplified30.5

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left|x\right|, \frac{-1}{x}, 1\right)}\]
  3. Using strategy rm
  4. Applied fma-udef4.8

    \[\leadsto \color{blue}{\left|x\right| \cdot \frac{-1}{x} + 1}\]
  5. Using strategy rm
  6. Applied log1p-expm1-u0.0

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left|x\right| \cdot \frac{-1}{x}\right)\right)} + 1\]
  7. Simplified0

    \[\leadsto \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\frac{\left|x\right|}{x} \cdot \left(-1\right)\right)}\right) + 1\]
  8. Final simplification0

    \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(1 \cdot \left(-\frac{\left|x\right|}{x}\right)\right)\right) + 1\]

Reproduce

herbie shell --seed 2019195 +o rules:numerics
(FPCore (x)
  :name "sqrt sqr"

  :herbie-target
  (if (< x 0.0) 2.0 0.0)

  (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))