Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, H

Percentage Accurate: 99.8% → 99.8%
Time: 3.1s
Alternatives: 4
Speedup: 7.0×

Specification

?
\[\frac{x \cdot x - 3}{6} \]

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 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: 99.8% accurate, 1.0× speedup?

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

    \[\frac{x \cdot x - 3}{6} \]
  2. Step-by-step derivation
    1. div-sub99.9%

      \[\leadsto \color{blue}{\frac{x \cdot x}{6} - \frac{3}{6}} \]
    2. div-inv99.9%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{6}} - \frac{3}{6} \]
    3. metadata-eval99.9%

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{0.16666666666666666} - \frac{3}{6} \]
    4. metadata-eval99.9%

      \[\leadsto \left(x \cdot x\right) \cdot 0.16666666666666666 - \color{blue}{0.5} \]
  3. Applied egg-rr99.9%

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

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

Alternative 2: 99.0% accurate, 0.8× speedup?

\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 2:\\ \;\;\;\;-0.5\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot 0.16666666666666666\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x x) < 2

    1. Initial program 100.0%

      \[\frac{x \cdot x - 3}{6} \]
    2. Taylor expanded in x around 0 98.4%

      \[\leadsto \color{blue}{-0.5} \]

    if 2 < (*.f64 x x)

    1. Initial program 99.8%

      \[\frac{x \cdot x - 3}{6} \]
    2. Taylor expanded in x around inf 99.3%

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

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

      \[\leadsto \color{blue}{0.16666666666666666 \cdot \left(x \cdot x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2:\\ \;\;\;\;-0.5\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot 0.16666666666666666\\ \end{array} \]

Alternative 3: 99.9% accurate, 1.0× speedup?

\[x \cdot \left(x \cdot 0.16666666666666666\right) + -0.5 \]
Derivation
  1. Initial program 99.9%

    \[\frac{x \cdot x - 3}{6} \]
  2. Step-by-step derivation
    1. add-cbrt-cube85.2%

      \[\leadsto \color{blue}{\sqrt[3]{\left(\frac{x \cdot x - 3}{6} \cdot \frac{x \cdot x - 3}{6}\right) \cdot \frac{x \cdot x - 3}{6}}} \]
    2. pow385.2%

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\frac{x \cdot x - 3}{6}\right)}^{3}}} \]
    3. div-inv85.2%

      \[\leadsto \sqrt[3]{{\color{blue}{\left(\left(x \cdot x - 3\right) \cdot \frac{1}{6}\right)}}^{3}} \]
    4. fma-neg85.2%

      \[\leadsto \sqrt[3]{{\left(\color{blue}{\mathsf{fma}\left(x, x, -3\right)} \cdot \frac{1}{6}\right)}^{3}} \]
    5. metadata-eval85.2%

      \[\leadsto \sqrt[3]{{\left(\mathsf{fma}\left(x, x, \color{blue}{-3}\right) \cdot \frac{1}{6}\right)}^{3}} \]
    6. metadata-eval85.2%

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

    \[\leadsto \color{blue}{\sqrt[3]{{\left(\mathsf{fma}\left(x, x, -3\right) \cdot 0.16666666666666666\right)}^{3}}} \]
  4. Step-by-step derivation
    1. rem-cbrt-cube99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, -3\right) \cdot 0.16666666666666666} \]
    2. *-commutative99.9%

      \[\leadsto \color{blue}{0.16666666666666666 \cdot \mathsf{fma}\left(x, x, -3\right)} \]
    3. fma-udef99.9%

      \[\leadsto 0.16666666666666666 \cdot \color{blue}{\left(x \cdot x + -3\right)} \]
    4. distribute-rgt-in99.9%

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

      \[\leadsto \color{blue}{x \cdot \left(x \cdot 0.16666666666666666\right)} + -3 \cdot 0.16666666666666666 \]
    6. metadata-eval99.9%

      \[\leadsto x \cdot \left(x \cdot 0.16666666666666666\right) + \color{blue}{-0.5} \]
  5. Applied egg-rr99.9%

    \[\leadsto \color{blue}{x \cdot \left(x \cdot 0.16666666666666666\right) + -0.5} \]
  6. Final simplification99.9%

    \[\leadsto x \cdot \left(x \cdot 0.16666666666666666\right) + -0.5 \]

Alternative 4: 49.4% accurate, 7.0× speedup?

\[-0.5 \]
Derivation
  1. Initial program 99.9%

    \[\frac{x \cdot x - 3}{6} \]
  2. Taylor expanded in x around 0 51.5%

    \[\leadsto \color{blue}{-0.5} \]
  3. Final simplification51.5%

    \[\leadsto -0.5 \]

Reproduce

?
herbie shell --seed 2023167 
(FPCore (x)
  :name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, H"
  :precision binary64
  (/ (- (* x x) 3.0) 6.0))