bug500, discussion (missed optimization)

Percentage Accurate: 52.9% → 97.0%
Time: 17.2s
Alternatives: 5
Speedup: TODO×

Specification

?
\[\log \left(\frac{\sinh x}{x}\right) \]

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 5 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.

Target

Original52.9%
Target97.8%
Herbie97.0%
\[\begin{array}{l} \mathbf{if}\;\left|x\right| < 0.085:\\ \;\;\;\;\left(x \cdot x\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-2.6455026455026456 \cdot 10^{-5}, x \cdot x, 0.0003527336860670194\right), x \cdot x, -0.005555555555555556\right), x \cdot x, 0.16666666666666666\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{\sinh x}{x}\right)\\ \end{array} \]

Alternative 1?

\[\left(x \cdot x\right) \cdot 0.16666666666666666 + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]
Derivation
  1. Initial program 52.3%

    \[\log \left(\frac{\sinh x}{x}\right) \]
  2. Taylor expanded in x around 0 99.3%

    \[\leadsto \color{blue}{0.16666666666666666 \cdot {x}^{2} + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right)} \]
  3. Step-by-step derivation
    1. pow299.3%

      \[\leadsto 0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)} + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]
    2. add-sqr-sqrt99.1%

      \[\leadsto \color{blue}{\sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)} \cdot \sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)}} + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]
    3. pow299.1%

      \[\leadsto \color{blue}{{\left(\sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)}\right)}^{2}} + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]
    4. *-commutative99.1%

      \[\leadsto {\left(\sqrt{\color{blue}{\left(x \cdot x\right) \cdot 0.16666666666666666}}\right)}^{2} + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]
    5. sqrt-prod99.2%

      \[\leadsto {\color{blue}{\left(\sqrt{x \cdot x} \cdot \sqrt{0.16666666666666666}\right)}}^{2} + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]
    6. sqrt-prod53.9%

      \[\leadsto {\left(\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \cdot \sqrt{0.16666666666666666}\right)}^{2} + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]
    7. add-sqr-sqrt99.2%

      \[\leadsto {\left(\color{blue}{x} \cdot \sqrt{0.16666666666666666}\right)}^{2} + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]
  4. Applied egg-rr99.2%

    \[\leadsto \color{blue}{{\left(x \cdot \sqrt{0.16666666666666666}\right)}^{2}} + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]
  5. Step-by-step derivation
    1. unpow299.2%

      \[\leadsto \color{blue}{\left(x \cdot \sqrt{0.16666666666666666}\right) \cdot \left(x \cdot \sqrt{0.16666666666666666}\right)} + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]
    2. swap-sqr99.3%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(\sqrt{0.16666666666666666} \cdot \sqrt{0.16666666666666666}\right)} + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]
    3. add-sqr-sqrt99.3%

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{0.16666666666666666} + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]
  6. Applied egg-rr99.3%

    \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 0.16666666666666666} + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]
  7. Final simplification99.3%

    \[\leadsto \left(x \cdot x\right) \cdot 0.16666666666666666 + \left(-0.005555555555555556 \cdot {x}^{4} + 0.0003527336860670194 \cdot {x}^{6}\right) \]

Alternative 2?

\[\left(x \cdot x\right) \cdot 0.16666666666666666 + -0.005555555555555556 \cdot {x}^{4} \]
Derivation
  1. Initial program 52.3%

    \[\log \left(\frac{\sinh x}{x}\right) \]
  2. Taylor expanded in x around 0 99.2%

    \[\leadsto \color{blue}{0.16666666666666666 \cdot {x}^{2} + -0.005555555555555556 \cdot {x}^{4}} \]
  3. Step-by-step derivation
    1. +-commutative99.2%

      \[\leadsto \color{blue}{-0.005555555555555556 \cdot {x}^{4} + 0.16666666666666666 \cdot {x}^{2}} \]
    2. fma-def99.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-0.005555555555555556, {x}^{4}, 0.16666666666666666 \cdot {x}^{2}\right)} \]
    3. unpow299.2%

      \[\leadsto \mathsf{fma}\left(-0.005555555555555556, {x}^{4}, 0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)}\right) \]
  4. Simplified99.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(-0.005555555555555556, {x}^{4}, 0.16666666666666666 \cdot \left(x \cdot x\right)\right)} \]
  5. Step-by-step derivation
    1. fma-udef99.2%

      \[\leadsto \color{blue}{-0.005555555555555556 \cdot {x}^{4} + 0.16666666666666666 \cdot \left(x \cdot x\right)} \]
    2. +-commutative99.2%

      \[\leadsto \color{blue}{0.16666666666666666 \cdot \left(x \cdot x\right) + -0.005555555555555556 \cdot {x}^{4}} \]
  6. Applied egg-rr99.2%

    \[\leadsto \color{blue}{0.16666666666666666 \cdot \left(x \cdot x\right) + -0.005555555555555556 \cdot {x}^{4}} \]
  7. Final simplification99.2%

    \[\leadsto \left(x \cdot x\right) \cdot 0.16666666666666666 + -0.005555555555555556 \cdot {x}^{4} \]

Alternative 3?

\[-0.005555555555555556 \cdot {x}^{4} + x \cdot \left(x \cdot 0.16666666666666666\right) \]
Derivation
  1. Initial program 52.3%

    \[\log \left(\frac{\sinh x}{x}\right) \]
  2. Taylor expanded in x around 0 99.2%

    \[\leadsto \color{blue}{0.16666666666666666 \cdot {x}^{2} + -0.005555555555555556 \cdot {x}^{4}} \]
  3. Step-by-step derivation
    1. +-commutative99.2%

      \[\leadsto \color{blue}{-0.005555555555555556 \cdot {x}^{4} + 0.16666666666666666 \cdot {x}^{2}} \]
    2. fma-def99.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-0.005555555555555556, {x}^{4}, 0.16666666666666666 \cdot {x}^{2}\right)} \]
    3. unpow299.2%

      \[\leadsto \mathsf{fma}\left(-0.005555555555555556, {x}^{4}, 0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)}\right) \]
  4. Simplified99.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(-0.005555555555555556, {x}^{4}, 0.16666666666666666 \cdot \left(x \cdot x\right)\right)} \]
  5. Step-by-step derivation
    1. add-cube-cbrt98.4%

      \[\leadsto \color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(-0.005555555555555556, {x}^{4}, 0.16666666666666666 \cdot \left(x \cdot x\right)\right)} \cdot \sqrt[3]{\mathsf{fma}\left(-0.005555555555555556, {x}^{4}, 0.16666666666666666 \cdot \left(x \cdot x\right)\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(-0.005555555555555556, {x}^{4}, 0.16666666666666666 \cdot \left(x \cdot x\right)\right)}} \]
    2. pow398.3%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\mathsf{fma}\left(-0.005555555555555556, {x}^{4}, 0.16666666666666666 \cdot \left(x \cdot x\right)\right)}\right)}^{3}} \]
  6. Applied egg-rr98.3%

    \[\leadsto \color{blue}{{\left(\sqrt[3]{\mathsf{fma}\left(-0.005555555555555556, {x}^{4}, 0.16666666666666666 \cdot \left(x \cdot x\right)\right)}\right)}^{3}} \]
  7. Step-by-step derivation
    1. rem-cube-cbrt99.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-0.005555555555555556, {x}^{4}, 0.16666666666666666 \cdot \left(x \cdot x\right)\right)} \]
    2. fma-udef99.2%

      \[\leadsto \color{blue}{-0.005555555555555556 \cdot {x}^{4} + 0.16666666666666666 \cdot \left(x \cdot x\right)} \]
    3. +-commutative99.2%

      \[\leadsto \color{blue}{0.16666666666666666 \cdot \left(x \cdot x\right) + -0.005555555555555556 \cdot {x}^{4}} \]
    4. *-commutative99.2%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 0.16666666666666666} + -0.005555555555555556 \cdot {x}^{4} \]
    5. associate-*r*99.2%

      \[\leadsto \color{blue}{x \cdot \left(x \cdot 0.16666666666666666\right)} + -0.005555555555555556 \cdot {x}^{4} \]
  8. Applied egg-rr99.2%

    \[\leadsto \color{blue}{x \cdot \left(x \cdot 0.16666666666666666\right) + -0.005555555555555556 \cdot {x}^{4}} \]
  9. Final simplification99.2%

    \[\leadsto -0.005555555555555556 \cdot {x}^{4} + x \cdot \left(x \cdot 0.16666666666666666\right) \]

Alternative 4?

\[\left(x \cdot x\right) \cdot 0.16666666666666666 \]
Derivation
  1. Initial program 52.3%

    \[\log \left(\frac{\sinh x}{x}\right) \]
  2. Taylor expanded in x around 0 98.8%

    \[\leadsto \color{blue}{0.16666666666666666 \cdot {x}^{2}} \]
  3. Step-by-step derivation
    1. unpow298.8%

      \[\leadsto 0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)} \]
  4. Simplified98.8%

    \[\leadsto \color{blue}{0.16666666666666666 \cdot \left(x \cdot x\right)} \]
  5. Final simplification98.8%

    \[\leadsto \left(x \cdot x\right) \cdot 0.16666666666666666 \]

Alternative 5?

\[x \cdot \left(x \cdot 0.16666666666666666\right) \]
Derivation
  1. Initial program 52.3%

    \[\log \left(\frac{\sinh x}{x}\right) \]
  2. Taylor expanded in x around 0 98.8%

    \[\leadsto \color{blue}{0.16666666666666666 \cdot {x}^{2}} \]
  3. Step-by-step derivation
    1. unpow298.8%

      \[\leadsto 0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)} \]
  4. Simplified98.8%

    \[\leadsto \color{blue}{0.16666666666666666 \cdot \left(x \cdot x\right)} \]
  5. Taylor expanded in x around 0 98.8%

    \[\leadsto \color{blue}{0.16666666666666666 \cdot {x}^{2}} \]
  6. Step-by-step derivation
    1. *-commutative98.8%

      \[\leadsto \color{blue}{{x}^{2} \cdot 0.16666666666666666} \]
    2. unpow298.8%

      \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot 0.16666666666666666 \]
    3. associate-*l*98.8%

      \[\leadsto \color{blue}{x \cdot \left(x \cdot 0.16666666666666666\right)} \]
  7. Simplified98.8%

    \[\leadsto \color{blue}{x \cdot \left(x \cdot 0.16666666666666666\right)} \]
  8. Final simplification98.8%

    \[\leadsto x \cdot \left(x \cdot 0.16666666666666666\right) \]

Reproduce

?
herbie shell --seed 2023166 
(FPCore (x)
  :name "bug500, discussion (missed optimization)"
  :precision binary64

  :herbie-target
  (if (< (fabs x) 0.085) (* (* x x) (fma (fma (fma -2.6455026455026456e-5 (* x x) 0.0003527336860670194) (* x x) -0.005555555555555556) (* x x) 0.16666666666666666)) (log (/ (sinh x) x)))

  (log (/ (sinh x) x)))