FastMath dist

Percentage Accurate: 97.6% → 100.0%
Time: 1.5s
Alternatives: 3
Speedup: 2.3×

Specification

?
\[d1 \cdot d2 + d1 \cdot d3 \]

Your Program's Arguments

Results

Enter valid numbers for all inputs

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 3 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, 1.4× speedup?

\[d1 \cdot \left(d2 + d3\right) \]
Derivation
  1. Initial program 97.6%

    \[d1 \cdot d2 + d1 \cdot d3 \]
  2. Step-by-step derivation
    1. distribute-lft-out100.0%

      \[\leadsto \color{blue}{d1 \cdot \left(d2 + d3\right)} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{d1 \cdot \left(d2 + d3\right)} \]
  4. Final simplification100.0%

    \[\leadsto d1 \cdot \left(d2 + d3\right) \]

Alternative 2: 65.6% accurate, 1.4× speedup?

\[\begin{array}{l} \mathbf{if}\;d3 \leq 1.3 \cdot 10^{-71}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d3\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if d3 < 1.2999999999999999e-71

    1. Initial program 97.8%

      \[d1 \cdot d2 + d1 \cdot d3 \]
    2. Step-by-step derivation
      1. distribute-lft-out100.0%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 + d3\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{d1 \cdot \left(d2 + d3\right)} \]
    4. Taylor expanded in d2 around inf 62.7%

      \[\leadsto \color{blue}{d2 \cdot d1} \]

    if 1.2999999999999999e-71 < d3

    1. Initial program 97.3%

      \[d1 \cdot d2 + d1 \cdot d3 \]
    2. Step-by-step derivation
      1. distribute-lft-out99.9%

        \[\leadsto \color{blue}{d1 \cdot \left(d2 + d3\right)} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{d1 \cdot \left(d2 + d3\right)} \]
    4. Taylor expanded in d2 around 0 65.0%

      \[\leadsto \color{blue}{d1 \cdot d3} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification63.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d3 \leq 1.3 \cdot 10^{-71}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d3\\ \end{array} \]

Alternative 3: 54.0% accurate, 2.3× speedup?

\[d1 \cdot d3 \]
Derivation
  1. Initial program 97.6%

    \[d1 \cdot d2 + d1 \cdot d3 \]
  2. Step-by-step derivation
    1. distribute-lft-out100.0%

      \[\leadsto \color{blue}{d1 \cdot \left(d2 + d3\right)} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{d1 \cdot \left(d2 + d3\right)} \]
  4. Taylor expanded in d2 around 0 51.3%

    \[\leadsto \color{blue}{d1 \cdot d3} \]
  5. Final simplification51.3%

    \[\leadsto d1 \cdot d3 \]

Developer target: 100.0% accurate, 1.4× speedup?

\[d1 \cdot \left(d2 + d3\right) \]

Reproduce

?
herbie shell --seed 2023167 
(FPCore (d1 d2 d3)
  :name "FastMath dist"
  :precision binary64

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

  (+ (* d1 d2) (* d1 d3)))