Average Error: 0.2 → 0.1
Time: 14.2s
Precision: 64
Internal Precision: 128
\[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20\]
\[(d1 \cdot \left(10 + d2\right) + \left(20 \cdot d1\right))_*\]

Error

Bits error versus d1

Bits error versus d2

Target

Original0.2
Target0.0
Herbie0.1
\[d1 \cdot \left(30 + d2\right)\]

Derivation

  1. Initial program 0.2

    \[\left(d1 \cdot 10 + d1 \cdot d2\right) + d1 \cdot 20\]
  2. Using strategy rm
  3. Applied *-commutative0.2

    \[\leadsto \left(d1 \cdot 10 + \color{blue}{d2 \cdot d1}\right) + d1 \cdot 20\]
  4. Applied *-commutative0.2

    \[\leadsto \left(\color{blue}{10 \cdot d1} + d2 \cdot d1\right) + d1 \cdot 20\]
  5. Applied distribute-rgt-out0.2

    \[\leadsto \color{blue}{d1 \cdot \left(10 + d2\right)} + d1 \cdot 20\]
  6. Applied fma-def0.1

    \[\leadsto \color{blue}{(d1 \cdot \left(10 + d2\right) + \left(d1 \cdot 20\right))_*}\]
  7. Final simplification0.1

    \[\leadsto (d1 \cdot \left(10 + d2\right) + \left(20 \cdot d1\right))_*\]

Reproduce

herbie shell --seed 2019072 +o rules:numerics
(FPCore (d1 d2)
  :name "FastMath test2"

  :herbie-target
  (* d1 (+ 30 d2))

  (+ (+ (* d1 10) (* d1 d2)) (* d1 20)))