Expression, p14

Percentage Accurate: 99.9% → 100.0%
Time: 4.6s
Alternatives: 4
Speedup: 2.3×

Specification

?
\[a \cdot \left(\left(b + c\right) + d\right) \]

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 4 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Alternative 1: 100.0% accurate, 0.1× speedup?

\[\mathsf{fma}\left(d, a, a \cdot \left(b + c\right)\right) \]
Derivation
  1. Initial program 100.0%

    \[a \cdot \left(\left(b + c\right) + d\right) \]
  2. Step-by-step derivation
    1. +-commutative100.0%

      \[\leadsto a \cdot \color{blue}{\left(d + \left(b + c\right)\right)} \]
    2. distribute-rgt-in100.0%

      \[\leadsto \color{blue}{d \cdot a + \left(b + c\right) \cdot a} \]
    3. fma-def100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(d, a, \left(b + c\right) \cdot a\right)} \]
    4. *-commutative100.0%

      \[\leadsto \mathsf{fma}\left(d, a, \color{blue}{a \cdot \left(b + c\right)}\right) \]
  3. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(d, a, a \cdot \left(b + c\right)\right)} \]
  4. Final simplification100.0%

    \[\leadsto \mathsf{fma}\left(d, a, a \cdot \left(b + c\right)\right) \]

Alternative 2: 99.9% accurate, 1.0× speedup?

\[a \cdot \left(d + \left(b + c\right)\right) \]
Derivation
  1. Initial program 100.0%

    \[a \cdot \left(\left(b + c\right) + d\right) \]
  2. Final simplification100.0%

    \[\leadsto a \cdot \left(d + \left(b + c\right)\right) \]

Alternative 3: 99.7% accurate, 1.4× speedup?

\[a \cdot \left(d + c\right) \]
Derivation
  1. Initial program 100.0%

    \[a \cdot \left(\left(b + c\right) + d\right) \]
  2. Taylor expanded in b around 0 63.3%

    \[\leadsto \color{blue}{a \cdot \left(c + d\right)} \]
  3. Final simplification63.3%

    \[\leadsto a \cdot \left(d + c\right) \]

Alternative 4: 93.9% accurate, 2.3× speedup?

\[d \cdot a \]
Derivation
  1. Initial program 100.0%

    \[a \cdot \left(\left(b + c\right) + d\right) \]
  2. Taylor expanded in d around inf 33.2%

    \[\leadsto \color{blue}{a \cdot d} \]
  3. Step-by-step derivation
    1. *-commutative33.2%

      \[\leadsto \color{blue}{d \cdot a} \]
  4. Simplified33.2%

    \[\leadsto \color{blue}{d \cdot a} \]
  5. Final simplification33.2%

    \[\leadsto d \cdot a \]

Developer target: 99.9% accurate, 0.8× speedup?

\[a \cdot b + a \cdot \left(c + d\right) \]

Reproduce

?
herbie shell --seed 2023167 
(FPCore (a b c d)
  :name "Expression, p14"
  :precision binary64
  :pre (and (and (and (and (<= 56789.0 a) (<= a 98765.0)) (and (<= 0.0 b) (<= b 1.0))) (and (<= 0.0 c) (<= c 0.0016773))) (and (<= 0.0 d) (<= d 0.0016773)))

  :herbie-target
  (+ (* a b) (* a (+ c d)))

  (* a (+ (+ b c) d)))