Average Error: 5.7 → 0.1
Time: 12.9s
Precision: 64
\[x + \frac{y \cdot y}{z}\]
\[\mathsf{fma}\left(\frac{y}{z}, y, x\right)\]
x + \frac{y \cdot y}{z}
\mathsf{fma}\left(\frac{y}{z}, y, x\right)
double f(double x, double y, double z) {
        double r31835370 = x;
        double r31835371 = y;
        double r31835372 = r31835371 * r31835371;
        double r31835373 = z;
        double r31835374 = r31835372 / r31835373;
        double r31835375 = r31835370 + r31835374;
        return r31835375;
}

double f(double x, double y, double z) {
        double r31835376 = y;
        double r31835377 = z;
        double r31835378 = r31835376 / r31835377;
        double r31835379 = x;
        double r31835380 = fma(r31835378, r31835376, r31835379);
        return r31835380;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original5.7
Target0.1
Herbie0.1
\[x + y \cdot \frac{y}{z}\]

Derivation

  1. Initial program 5.7

    \[x + \frac{y \cdot y}{z}\]
  2. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{z}, y, x\right)}\]
  3. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(\frac{y}{z}, y, x\right)\]

Reproduce

herbie shell --seed 2019163 +o rules:numerics
(FPCore (x y z)
  :name "Crypto.Random.Test:calculate from crypto-random-0.0.9"

  :herbie-target
  (+ x (* y (/ y z)))

  (+ x (/ (* y y) z)))