Average Error: 0.1 → 0.1
Time: 2.1m
Precision: 64
\[x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right)\]
\[\mathsf{fma}\left(x, 0.5, \mathsf{fma}\left(y, 1 - z, \log z \cdot y\right)\right)\]
x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right)
\mathsf{fma}\left(x, 0.5, \mathsf{fma}\left(y, 1 - z, \log z \cdot y\right)\right)
double f(double x, double y, double z) {
        double r14564148 = x;
        double r14564149 = 0.5;
        double r14564150 = r14564148 * r14564149;
        double r14564151 = y;
        double r14564152 = 1.0;
        double r14564153 = z;
        double r14564154 = r14564152 - r14564153;
        double r14564155 = log(r14564153);
        double r14564156 = r14564154 + r14564155;
        double r14564157 = r14564151 * r14564156;
        double r14564158 = r14564150 + r14564157;
        return r14564158;
}

double f(double x, double y, double z) {
        double r14564159 = x;
        double r14564160 = 0.5;
        double r14564161 = y;
        double r14564162 = 1.0;
        double r14564163 = z;
        double r14564164 = r14564162 - r14564163;
        double r14564165 = log(r14564163);
        double r14564166 = r14564165 * r14564161;
        double r14564167 = fma(r14564161, r14564164, r14564166);
        double r14564168 = fma(r14564159, r14564160, r14564167);
        return r14564168;
}

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 - z\right) + \log z\right)\]
  2. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, \log z + \left(1 - z\right), 0.5 \cdot x\right)}\]
  3. Using strategy rm
  4. Applied fma-udef0.1

    \[\leadsto \color{blue}{y \cdot \left(\log z + \left(1 - z\right)\right) + 0.5 \cdot x}\]
  5. Taylor expanded around inf 0.1

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

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

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

Reproduce

herbie shell --seed 2019200 +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)))))