Diagrams.Solve.Polynomial:quadForm from diagrams-solve-0.1, A

Percentage Accurate: 99.9% → 100.0%
Time: 1.7s
Alternatives: 4
Speedup: TODO×

Specification

?
\[x - \left(y \cdot 4\right) \cdot z \]

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?

\[\mathsf{fma}\left(z, y \cdot -4, x\right) \]
Derivation
  1. Initial program 100.0%

    \[x - \left(y \cdot 4\right) \cdot z \]
  2. Step-by-step derivation
    1. sub-neg100.0%

      \[\leadsto \color{blue}{x + \left(-\left(y \cdot 4\right) \cdot z\right)} \]
    2. +-commutative100.0%

      \[\leadsto \color{blue}{\left(-\left(y \cdot 4\right) \cdot z\right) + x} \]
    3. *-commutative100.0%

      \[\leadsto \left(-\color{blue}{z \cdot \left(y \cdot 4\right)}\right) + x \]
    4. distribute-rgt-neg-in100.0%

      \[\leadsto \color{blue}{z \cdot \left(-y \cdot 4\right)} + x \]
    5. fma-def100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, -y \cdot 4, x\right)} \]
    6. distribute-rgt-neg-in100.0%

      \[\leadsto \mathsf{fma}\left(z, \color{blue}{y \cdot \left(-4\right)}, x\right) \]
    7. metadata-eval100.0%

      \[\leadsto \mathsf{fma}\left(z, y \cdot \color{blue}{-4}, x\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(z, y \cdot -4, x\right)} \]
  4. Final simplification100.0%

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

Alternative 2?

\[\begin{array}{l} \mathbf{if}\;z \leq -2.35 \cdot 10^{-188} \lor \neg \left(z \leq 160 \lor \neg \left(z \leq 1.05 \cdot 10^{+54}\right) \land z \leq 4.2 \cdot 10^{+125}\right):\\ \;\;\;\;-4 \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if z < -2.34999999999999999e-188 or 160 < z < 1.04999999999999993e54 or 4.2000000000000001e125 < z

    1. Initial program 100.0%

      \[x - \left(y \cdot 4\right) \cdot z \]
    2. Taylor expanded in x around 0 67.5%

      \[\leadsto \color{blue}{-4 \cdot \left(y \cdot z\right)} \]

    if -2.34999999999999999e-188 < z < 160 or 1.04999999999999993e54 < z < 4.2000000000000001e125

    1. Initial program 100.0%

      \[x - \left(y \cdot 4\right) \cdot z \]
    2. Taylor expanded in x around inf 81.5%

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.35 \cdot 10^{-188} \lor \neg \left(z \leq 160 \lor \neg \left(z \leq 1.05 \cdot 10^{+54}\right) \land z \leq 4.2 \cdot 10^{+125}\right):\\ \;\;\;\;-4 \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 3?

\[x - z \cdot \left(y \cdot 4\right) \]
Derivation
  1. Initial program 100.0%

    \[x - \left(y \cdot 4\right) \cdot z \]
  2. Final simplification100.0%

    \[\leadsto x - z \cdot \left(y \cdot 4\right) \]

Alternative 4?

\[x \]
Derivation
  1. Initial program 100.0%

    \[x - \left(y \cdot 4\right) \cdot z \]
  2. Taylor expanded in x around inf 53.6%

    \[\leadsto \color{blue}{x} \]
  3. Final simplification53.6%

    \[\leadsto x \]

Reproduce

?
herbie shell --seed 2023166 
(FPCore (x y z)
  :name "Diagrams.Solve.Polynomial:quadForm from diagrams-solve-0.1, A"
  :precision binary64
  (- x (* (* y 4.0) z)))