ENA, Section 1.4, Exercise 4a

Percentage Accurate: 52.9% → 99.6%
Time: 19.5s
Alternatives: 7
Speedup: N/A×

Specification

?
\[\frac{x - \sin x}{\tan x} \]

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 7 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: 99.6% accurate, 0.4× speedup?

\[\sqrt{0.16666666666666666} \cdot \left(x \cdot \left(x \cdot \sqrt{0.16666666666666666}\right)\right) + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
Derivation
  1. Initial program 51.0%

    \[\frac{x - \sin x}{\tan x} \]
  2. Taylor expanded in x around 0 99.4%

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

      \[\leadsto 0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
    2. add-sqr-sqrt99.2%

      \[\leadsto \color{blue}{\sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)} \cdot \sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)}} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
    3. pow299.2%

      \[\leadsto \color{blue}{{\left(\sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)}\right)}^{2}} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
    4. *-commutative99.2%

      \[\leadsto {\left(\sqrt{\color{blue}{\left(x \cdot x\right) \cdot 0.16666666666666666}}\right)}^{2} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
    5. sqrt-prod99.3%

      \[\leadsto {\color{blue}{\left(\sqrt{x \cdot x} \cdot \sqrt{0.16666666666666666}\right)}}^{2} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
    6. sqrt-prod46.1%

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

      \[\leadsto {\left(\color{blue}{x} \cdot \sqrt{0.16666666666666666}\right)}^{2} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
  4. Applied egg-rr99.3%

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

      \[\leadsto \color{blue}{\left(x \cdot \sqrt{0.16666666666666666}\right) \cdot \left(x \cdot \sqrt{0.16666666666666666}\right)} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
    2. associate-*r*99.5%

      \[\leadsto \color{blue}{\left(\left(x \cdot \sqrt{0.16666666666666666}\right) \cdot x\right) \cdot \sqrt{0.16666666666666666}} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
  6. Applied egg-rr99.5%

    \[\leadsto \color{blue}{\left(\left(x \cdot \sqrt{0.16666666666666666}\right) \cdot x\right) \cdot \sqrt{0.16666666666666666}} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
  7. Final simplification99.5%

    \[\leadsto \sqrt{0.16666666666666666} \cdot \left(x \cdot \left(x \cdot \sqrt{0.16666666666666666}\right)\right) + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]

Alternative 2: 99.6% accurate, 0.6× speedup?

\[\left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) + 0.16666666666666666 \cdot \left(x \cdot x\right) \]
Derivation
  1. Initial program 51.0%

    \[\frac{x - \sin x}{\tan x} \]
  2. Taylor expanded in x around 0 99.4%

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

      \[\leadsto 0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
    2. add-sqr-sqrt99.2%

      \[\leadsto \color{blue}{\sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)} \cdot \sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)}} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
    3. pow299.2%

      \[\leadsto \color{blue}{{\left(\sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)}\right)}^{2}} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
    4. *-commutative99.2%

      \[\leadsto {\left(\sqrt{\color{blue}{\left(x \cdot x\right) \cdot 0.16666666666666666}}\right)}^{2} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
    5. sqrt-prod99.3%

      \[\leadsto {\color{blue}{\left(\sqrt{x \cdot x} \cdot \sqrt{0.16666666666666666}\right)}}^{2} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
    6. sqrt-prod46.1%

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

      \[\leadsto {\left(\color{blue}{x} \cdot \sqrt{0.16666666666666666}\right)}^{2} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
  4. Applied egg-rr99.3%

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

      \[\leadsto \color{blue}{\left(x \cdot \sqrt{0.16666666666666666}\right) \cdot \left(x \cdot \sqrt{0.16666666666666666}\right)} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
    2. swap-sqr99.4%

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

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

    \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 0.16666666666666666} + \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) \]
  7. Final simplification99.4%

    \[\leadsto \left(-0.00023644179894179894 \cdot {x}^{8} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)\right) + 0.16666666666666666 \cdot \left(x \cdot x\right) \]

Alternative 3: 99.3% accurate, 1.0× speedup?

\[\mathsf{fma}\left(0.16666666666666666, x \cdot x, -0.06388888888888888 \cdot {x}^{4}\right) \]
Derivation
  1. Initial program 51.0%

    \[\frac{x - \sin x}{\tan x} \]
  2. Taylor expanded in x around 0 99.1%

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.16666666666666666, x \cdot x, -0.06388888888888888 \cdot {x}^{4}\right)} \]
  5. Final simplification99.1%

    \[\leadsto \mathsf{fma}\left(0.16666666666666666, x \cdot x, -0.06388888888888888 \cdot {x}^{4}\right) \]

Alternative 4: 99.3% accurate, 1.0× speedup?

\[\mathsf{fma}\left({x}^{4}, -0.06388888888888888, 0.16666666666666666 \cdot \left(x \cdot x\right)\right) \]
Derivation
  1. Initial program 51.0%

    \[\frac{x - \sin x}{\tan x} \]
  2. Taylor expanded in x around inf 51.0%

    \[\leadsto \color{blue}{\frac{\cos x \cdot x}{\sin x} + -1 \cdot \cos x} \]
  3. Step-by-step derivation
    1. *-commutative51.0%

      \[\leadsto \frac{\color{blue}{x \cdot \cos x}}{\sin x} + -1 \cdot \cos x \]
    2. associate-*l/51.0%

      \[\leadsto \color{blue}{\frac{x}{\sin x} \cdot \cos x} + -1 \cdot \cos x \]
    3. distribute-rgt-out51.0%

      \[\leadsto \color{blue}{\cos x \cdot \left(\frac{x}{\sin x} + -1\right)} \]
  4. Simplified51.0%

    \[\leadsto \color{blue}{\cos x \cdot \left(\frac{x}{\sin x} + -1\right)} \]
  5. Taylor expanded in x around 0 99.1%

    \[\leadsto \color{blue}{0.16666666666666666 \cdot {x}^{2} + -0.06388888888888888 \cdot {x}^{4}} \]
  6. Step-by-step derivation
    1. unpow299.1%

      \[\leadsto 0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)} + -0.06388888888888888 \cdot {x}^{4} \]
    2. associate-*l*99.1%

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

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

      \[\leadsto \color{blue}{{x}^{4} \cdot -0.06388888888888888} + \left(0.16666666666666666 \cdot x\right) \cdot x \]
    5. fma-def99.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{4}, -0.06388888888888888, \left(0.16666666666666666 \cdot x\right) \cdot x\right)} \]
    6. associate-*l*99.1%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{4}, -0.06388888888888888, 0.16666666666666666 \cdot \left(x \cdot x\right)\right)} \]
  8. Final simplification99.1%

    \[\leadsto \mathsf{fma}\left({x}^{4}, -0.06388888888888888, 0.16666666666666666 \cdot \left(x \cdot x\right)\right) \]

Alternative 5: 98.8% accurate, 1.0× speedup?

\[x \cdot \left(\sqrt{0.16666666666666666} \cdot \left(x \cdot \sqrt{0.16666666666666666}\right)\right) \]
Derivation
  1. Initial program 51.0%

    \[\frac{x - \sin x}{\tan x} \]
  2. Step-by-step derivation
    1. add-sqr-sqrt51.0%

      \[\leadsto \color{blue}{\sqrt{\frac{x - \sin x}{\tan x}} \cdot \sqrt{\frac{x - \sin x}{\tan x}}} \]
    2. pow251.0%

      \[\leadsto \color{blue}{{\left(\sqrt{\frac{x - \sin x}{\tan x}}\right)}^{2}} \]
    3. div-sub51.0%

      \[\leadsto {\left(\sqrt{\color{blue}{\frac{x}{\tan x} - \frac{\sin x}{\tan x}}}\right)}^{2} \]
    4. tan-quot50.9%

      \[\leadsto {\left(\sqrt{\frac{x}{\tan x} - \frac{\sin x}{\color{blue}{\frac{\sin x}{\cos x}}}}\right)}^{2} \]
    5. associate-/r/51.0%

      \[\leadsto {\left(\sqrt{\frac{x}{\tan x} - \color{blue}{\frac{\sin x}{\sin x} \cdot \cos x}}\right)}^{2} \]
    6. pow151.0%

      \[\leadsto {\left(\sqrt{\frac{x}{\tan x} - \frac{\color{blue}{{\sin x}^{1}}}{\sin x} \cdot \cos x}\right)}^{2} \]
    7. pow151.0%

      \[\leadsto {\left(\sqrt{\frac{x}{\tan x} - \frac{{\sin x}^{1}}{\color{blue}{{\sin x}^{1}}} \cdot \cos x}\right)}^{2} \]
    8. pow-div51.0%

      \[\leadsto {\left(\sqrt{\frac{x}{\tan x} - \color{blue}{{\sin x}^{\left(1 - 1\right)}} \cdot \cos x}\right)}^{2} \]
    9. metadata-eval51.0%

      \[\leadsto {\left(\sqrt{\frac{x}{\tan x} - {\sin x}^{\color{blue}{0}} \cdot \cos x}\right)}^{2} \]
    10. metadata-eval51.0%

      \[\leadsto {\left(\sqrt{\frac{x}{\tan x} - \color{blue}{1} \cdot \cos x}\right)}^{2} \]
    11. *-un-lft-identity51.0%

      \[\leadsto {\left(\sqrt{\frac{x}{\tan x} - \color{blue}{\cos x}}\right)}^{2} \]
  3. Applied egg-rr51.0%

    \[\leadsto \color{blue}{{\left(\sqrt{\frac{x}{\tan x} - \cos x}\right)}^{2}} \]
  4. Taylor expanded in x around 0 98.0%

    \[\leadsto {\color{blue}{\left(\sqrt{0.16666666666666666} \cdot x\right)}}^{2} \]
  5. Step-by-step derivation
    1. unpow298.0%

      \[\leadsto \color{blue}{\left(\sqrt{0.16666666666666666} \cdot x\right) \cdot \left(\sqrt{0.16666666666666666} \cdot x\right)} \]
    2. associate-*r*98.1%

      \[\leadsto \color{blue}{\left(\left(\sqrt{0.16666666666666666} \cdot x\right) \cdot \sqrt{0.16666666666666666}\right) \cdot x} \]
    3. *-commutative98.1%

      \[\leadsto \left(\color{blue}{\left(x \cdot \sqrt{0.16666666666666666}\right)} \cdot \sqrt{0.16666666666666666}\right) \cdot x \]
  6. Applied egg-rr98.1%

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

    \[\leadsto x \cdot \left(\sqrt{0.16666666666666666} \cdot \left(x \cdot \sqrt{0.16666666666666666}\right)\right) \]

Alternative 6: 98.7% accurate, 41.0× speedup?

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

    \[\frac{x - \sin x}{\tan x} \]
  2. Taylor expanded in x around 0 98.1%

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

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

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

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

Alternative 7: 98.7% accurate, 41.0× speedup?

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

    \[\frac{x - \sin x}{\tan x} \]
  2. Taylor expanded in x around 0 98.1%

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

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

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

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

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

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

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

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

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

Developer target: 98.7% accurate, 41.0× speedup?

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

Reproduce

?
herbie shell --seed 2023167 
(FPCore (x)
  :name "ENA, Section 1.4, Exercise 4a"
  :precision binary64
  :pre (and (<= -1.0 x) (<= x 1.0))

  :herbie-target
  (* 0.16666666666666666 (* x x))

  (/ (- x (sin x)) (tan x)))