Falkner and Boettcher, Equation (20:1,3)

Percentage Accurate: 99.3% → 99.3%
Time: 1.8s
Alternatives: 3
Speedup: 1.0×

Specification

?
\[\mathsf{TRUE}\left(\right)\]
\[\begin{array}{l} \\ \frac{1 - 5 \cdot \left(v \cdot v\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot t\right) \cdot \sqrt{2 \cdot \left(1 - 3 \cdot \left(v \cdot v\right)\right)}\right) \cdot \left(1 - v \cdot v\right)} \end{array} \]
(FPCore (v t)
 :precision binary64
 (/
  (- 1.0 (* 5.0 (* v v)))
  (* (* (* (PI) t) (sqrt (* 2.0 (- 1.0 (* 3.0 (* v v)))))) (- 1.0 (* v v)))))
\begin{array}{l}

\\
\frac{1 - 5 \cdot \left(v \cdot v\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot t\right) \cdot \sqrt{2 \cdot \left(1 - 3 \cdot \left(v \cdot v\right)\right)}\right) \cdot \left(1 - v \cdot v\right)}
\end{array}

Sampling outcomes in binary64 precision:

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.

Initial Program: 99.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1 - 5 \cdot \left(v \cdot v\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot t\right) \cdot \sqrt{2 \cdot \left(1 - 3 \cdot \left(v \cdot v\right)\right)}\right) \cdot \left(1 - v \cdot v\right)} \end{array} \]
(FPCore (v t)
 :precision binary64
 (/
  (- 1.0 (* 5.0 (* v v)))
  (* (* (* (PI) t) (sqrt (* 2.0 (- 1.0 (* 3.0 (* v v)))))) (- 1.0 (* v v)))))
\begin{array}{l}

\\
\frac{1 - 5 \cdot \left(v \cdot v\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot t\right) \cdot \sqrt{2 \cdot \left(1 - 3 \cdot \left(v \cdot v\right)\right)}\right) \cdot \left(1 - v \cdot v\right)}
\end{array}

Alternative 1: 99.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1 - 5 \cdot \left(v \cdot v\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot t\right) \cdot \sqrt{2 \cdot \left(1 - 3 \cdot \left(v \cdot v\right)\right)}\right) \cdot \left(1 - v \cdot v\right)} \end{array} \]
(FPCore (v t)
 :precision binary64
 (/
  (- 1.0 (* 5.0 (* v v)))
  (* (* (* (PI) t) (sqrt (* 2.0 (- 1.0 (* 3.0 (* v v)))))) (- 1.0 (* v v)))))
\begin{array}{l}

\\
\frac{1 - 5 \cdot \left(v \cdot v\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot t\right) \cdot \sqrt{2 \cdot \left(1 - 3 \cdot \left(v \cdot v\right)\right)}\right) \cdot \left(1 - v \cdot v\right)}
\end{array}
Derivation
  1. Initial program 99.1%

    \[\frac{1 - 5 \cdot \left(v \cdot v\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot t\right) \cdot \sqrt{2 \cdot \left(1 - 3 \cdot \left(v \cdot v\right)\right)}\right) \cdot \left(1 - v \cdot v\right)} \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 5.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := 1 - 5 \cdot \left(v \cdot v\right)\\ t_2 := 5 \cdot t\_1\\ \mathbf{if}\;\frac{t\_1}{\left(\left(\mathsf{PI}\left(\right) \cdot t\right) \cdot \sqrt{2 \cdot \left(1 - 3 \cdot \left(v \cdot v\right)\right)}\right) \cdot \left(1 - v \cdot v\right)} \leq 0:\\ \;\;\;\;1 - t\_2\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (v t)
 :precision binary64
 (let* ((t_1 (- 1.0 (* 5.0 (* v v)))) (t_2 (* 5.0 t_1)))
   (if (<=
        (/
         t_1
         (*
          (* (* (PI) t) (sqrt (* 2.0 (- 1.0 (* 3.0 (* v v))))))
          (- 1.0 (* v v))))
        0.0)
     (- 1.0 t_2)
     t_2)))
\begin{array}{l}

\\
\begin{array}{l}
t_1 := 1 - 5 \cdot \left(v \cdot v\right)\\
t_2 := 5 \cdot t\_1\\
\mathbf{if}\;\frac{t\_1}{\left(\left(\mathsf{PI}\left(\right) \cdot t\right) \cdot \sqrt{2 \cdot \left(1 - 3 \cdot \left(v \cdot v\right)\right)}\right) \cdot \left(1 - v \cdot v\right)} \leq 0:\\
\;\;\;\;1 - t\_2\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 #s(literal 1 binary64) (*.f64 #s(literal 5 binary64) (*.f64 v v))) (*.f64 (*.f64 (*.f64 (PI.f64) t) (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 #s(literal 1 binary64) (*.f64 #s(literal 3 binary64) (*.f64 v v)))))) (-.f64 #s(literal 1 binary64) (*.f64 v v)))) < 0.0

    1. Initial program 98.9%

      \[\frac{1 - 5 \cdot \left(v \cdot v\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot t\right) \cdot \sqrt{2 \cdot \left(1 - 3 \cdot \left(v \cdot v\right)\right)}\right) \cdot \left(1 - v \cdot v\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in v around 0

      \[\leadsto \color{blue}{\frac{-5}{2} \cdot \frac{{v}^{2}}{t \cdot \left(\mathsf{PI}\left(\right) \cdot \sqrt{2}\right)} + \frac{1}{t \cdot \left(\mathsf{PI}\left(\right) \cdot \sqrt{2}\right)}} \]
    4. Applied rewrites1.6%

      \[\leadsto \color{blue}{1 - 5 \cdot \left(v \cdot v\right)} \]
    5. Taylor expanded in v around 0

      \[\leadsto 1 - 5 \cdot {v}^{\color{blue}{2}} \]
    6. Applied rewrites5.6%

      \[\leadsto 1 - 5 \cdot \left(1 - \color{blue}{5 \cdot \left(v \cdot v\right)}\right) \]

    if 0.0 < (/.f64 (-.f64 #s(literal 1 binary64) (*.f64 #s(literal 5 binary64) (*.f64 v v))) (*.f64 (*.f64 (*.f64 (PI.f64) t) (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 #s(literal 1 binary64) (*.f64 #s(literal 3 binary64) (*.f64 v v)))))) (-.f64 #s(literal 1 binary64) (*.f64 v v))))

    1. Initial program 99.3%

      \[\frac{1 - 5 \cdot \left(v \cdot v\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot t\right) \cdot \sqrt{2 \cdot \left(1 - 3 \cdot \left(v \cdot v\right)\right)}\right) \cdot \left(1 - v \cdot v\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in v around 0

      \[\leadsto \color{blue}{{v}^{2} \cdot \left(\frac{-53}{8} \cdot \frac{{v}^{2}}{t \cdot \left(\mathsf{PI}\left(\right) \cdot \sqrt{2}\right)} - \frac{5}{2} \cdot \frac{1}{t \cdot \left(\mathsf{PI}\left(\right) \cdot \sqrt{2}\right)}\right) + \frac{1}{t \cdot \left(\mathsf{PI}\left(\right) \cdot \sqrt{2}\right)}} \]
    4. Applied rewrites4.0%

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

      \[\leadsto 5 \cdot {v}^{\color{blue}{2}} \]
    6. Applied rewrites5.5%

      \[\leadsto 5 \cdot \left(1 - \color{blue}{5 \cdot \left(v \cdot v\right)}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 3.8% accurate, 12.7× speedup?

\[\begin{array}{l} \\ \mathsf{PI}\left(\right) \cdot t \end{array} \]
(FPCore (v t) :precision binary64 (* (PI) t))
\begin{array}{l}

\\
\mathsf{PI}\left(\right) \cdot t
\end{array}
Derivation
  1. Initial program 99.1%

    \[\frac{1 - 5 \cdot \left(v \cdot v\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot t\right) \cdot \sqrt{2 \cdot \left(1 - 3 \cdot \left(v \cdot v\right)\right)}\right) \cdot \left(1 - v \cdot v\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in v around 0

    \[\leadsto \color{blue}{\frac{-5}{2} \cdot \frac{{v}^{2}}{t \cdot \left(\mathsf{PI}\left(\right) \cdot \sqrt{2}\right)} + \frac{1}{t \cdot \left(\mathsf{PI}\left(\right) \cdot \sqrt{2}\right)}} \]
  4. Applied rewrites3.5%

    \[\leadsto \color{blue}{1 - 5 \cdot \left(v \cdot v\right)} \]
  5. Taylor expanded in v around 0

    \[\leadsto 1 + \color{blue}{-5 \cdot {v}^{2}} \]
  6. Applied rewrites3.9%

    \[\leadsto \mathsf{PI}\left(\right) \cdot \color{blue}{t} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024321 
(FPCore (v t)
  :name "Falkner and Boettcher, Equation (20:1,3)"
  :precision binary64
  :pre (TRUE)
  (/ (- 1.0 (* 5.0 (* v v))) (* (* (* (PI) t) (sqrt (* 2.0 (- 1.0 (* 3.0 (* v v)))))) (- 1.0 (* v v)))))