Average Error: 0.1 → 0.1
Time: 24.7s
Precision: 64
\[x \cdot 0.5 + y \cdot \left(\left(1.0 - z\right) + \log z\right)\]
\[\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(y, 1.0 - z, \log z \cdot y\right)\right)\]
x \cdot 0.5 + y \cdot \left(\left(1.0 - z\right) + \log z\right)
\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(y, 1.0 - z, \log z \cdot y\right)\right)
double f(double x, double y, double z) {
        double r16171620 = x;
        double r16171621 = 0.5;
        double r16171622 = r16171620 * r16171621;
        double r16171623 = y;
        double r16171624 = 1.0;
        double r16171625 = z;
        double r16171626 = r16171624 - r16171625;
        double r16171627 = log(r16171625);
        double r16171628 = r16171626 + r16171627;
        double r16171629 = r16171623 * r16171628;
        double r16171630 = r16171622 + r16171629;
        return r16171630;
}

double f(double x, double y, double z) {
        double r16171631 = 0.5;
        double r16171632 = x;
        double r16171633 = y;
        double r16171634 = 1.0;
        double r16171635 = z;
        double r16171636 = r16171634 - r16171635;
        double r16171637 = log(r16171635);
        double r16171638 = r16171637 * r16171633;
        double r16171639 = fma(r16171633, r16171636, r16171638);
        double r16171640 = fma(r16171631, r16171632, r16171639);
        return r16171640;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original0.1
Target0.1
Herbie0.1
\[\left(y + 0.5 \cdot x\right) - y \cdot \left(z - \log z\right)\]

Derivation

  1. Initial program 0.1

    \[x \cdot 0.5 + y \cdot \left(\left(1.0 - z\right) + \log z\right)\]
  2. Taylor expanded around 0 0.1

    \[\leadsto \color{blue}{\left(0.5 \cdot x + \left(1.0 \cdot y + y \cdot \log z\right)\right) - z \cdot y}\]
  3. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, x, \mathsf{fma}\left(y, 1.0 - z, y \cdot \log z\right)\right)}\]
  4. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(0.5, x, \mathsf{fma}\left(y, 1.0 - z, \log z \cdot y\right)\right)\]

Reproduce

herbie shell --seed 2019158 +o rules:numerics
(FPCore (x y z)
  :name "System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2"

  :herbie-target
  (- (+ y (* 0.5 x)) (* y (- z (log z))))

  (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))