ab-angle->ABCF C

Percentage Accurate: 79.7% → 79.7%
Time: 2.7s
Alternatives: 11
Speedup: 1.0×

Specification

?
\[\mathsf{TRUE}\left(\right)\]
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\ {\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2} \end{array} \end{array} \]
(FPCore (a b angle)
 :precision binary64
 (let* ((t_0 (* (PI) (/ angle 180.0))))
   (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\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 11 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: 79.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\ {\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2} \end{array} \end{array} \]
(FPCore (a b angle)
 :precision binary64
 (let* ((t_0 (* (PI) (/ angle 180.0))))
   (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}

Alternative 1: 79.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\ {\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2} \end{array} \end{array} \]
(FPCore (a b angle)
 :precision binary64
 (let* ((t_0 (* (PI) (/ angle 180.0))))
   (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
Derivation
  1. Initial program 81.5%

    \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 68.4% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\ t_1 := {\left(b \cdot \sin t\_0\right)}^{2}\\ \mathbf{if}\;b \leq -1.6 \cdot 10^{+144}:\\ \;\;\;\;t\_0 + t\_1\\ \mathbf{elif}\;b \leq 10^{+108}:\\ \;\;\;\;{\left(a \cdot \cos t\_0\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;{t\_0}^{2} + t\_1\\ \end{array} \end{array} \]
(FPCore (a b angle)
 :precision binary64
 (let* ((t_0 (* (PI) (/ angle 180.0))) (t_1 (pow (* b (sin t_0)) 2.0)))
   (if (<= b -1.6e+144)
     (+ t_0 t_1)
     (if (<= b 1e+108) (pow (* a (cos t_0)) 2.0) (+ (pow t_0 2.0) t_1)))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
t_1 := {\left(b \cdot \sin t\_0\right)}^{2}\\
\mathbf{if}\;b \leq -1.6 \cdot 10^{+144}:\\
\;\;\;\;t\_0 + t\_1\\

\mathbf{elif}\;b \leq 10^{+108}:\\
\;\;\;\;{\left(a \cdot \cos t\_0\right)}^{2}\\

\mathbf{else}:\\
\;\;\;\;{t\_0}^{2} + t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -1.6e144

    1. Initial program 94.4%

      \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    4. Applied rewrites78.3%

      \[\leadsto \color{blue}{a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    5. Taylor expanded in angle around 0

      \[\leadsto a + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    6. Applied rewrites78.8%

      \[\leadsto {\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{\color{blue}{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    7. Taylor expanded in angle around 0

      \[\leadsto \left(a + \color{blue}{{angle}^{2} \cdot \left(\frac{-1}{64800} \cdot \left(a \cdot {\mathsf{PI}\left(\right)}^{2}\right) + {angle}^{2} \cdot \left(\frac{-1}{24488801280000000} \cdot \left(a \cdot \left({angle}^{2} \cdot {\mathsf{PI}\left(\right)}^{6}\right)\right) + \frac{1}{25194240000} \cdot \left(a \cdot {\mathsf{PI}\left(\right)}^{4}\right)\right)\right)}\right) + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    8. Applied rewrites78.9%

      \[\leadsto \mathsf{PI}\left(\right) \cdot \color{blue}{\frac{angle}{180}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]

    if -1.6e144 < b < 1e108

    1. Initial program 77.2%

      \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {b}^{2} \cdot {\sin \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} \]
    4. Applied rewrites72.5%

      \[\leadsto \color{blue}{{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}} \]

    if 1e108 < b

    1. Initial program 89.9%

      \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    4. Applied rewrites72.9%

      \[\leadsto \color{blue}{a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    5. Taylor expanded in angle around 0

      \[\leadsto a + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    6. Applied rewrites75.2%

      \[\leadsto {\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{\color{blue}{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 68.2% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\ t_1 := t\_0 + {\left(b \cdot \sin t\_0\right)}^{2}\\ \mathbf{if}\;b \leq -1.6 \cdot 10^{+144}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;b \leq 2.6 \cdot 10^{+108}:\\ \;\;\;\;{\left(a \cdot \cos t\_0\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b angle)
 :precision binary64
 (let* ((t_0 (* (PI) (/ angle 180.0))) (t_1 (+ t_0 (pow (* b (sin t_0)) 2.0))))
   (if (<= b -1.6e+144)
     t_1
     (if (<= b 2.6e+108) (pow (* a (cos t_0)) 2.0) t_1))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
t_1 := t\_0 + {\left(b \cdot \sin t\_0\right)}^{2}\\
\mathbf{if}\;b \leq -1.6 \cdot 10^{+144}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;b \leq 2.6 \cdot 10^{+108}:\\
\;\;\;\;{\left(a \cdot \cos t\_0\right)}^{2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -1.6e144 or 2.6000000000000002e108 < b

    1. Initial program 91.7%

      \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    4. Applied rewrites75.1%

      \[\leadsto \color{blue}{a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    5. Taylor expanded in angle around 0

      \[\leadsto a + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    6. Applied rewrites76.7%

      \[\leadsto {\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{\color{blue}{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    7. Taylor expanded in angle around 0

      \[\leadsto \left(a + \color{blue}{{angle}^{2} \cdot \left(\frac{-1}{64800} \cdot \left(a \cdot {\mathsf{PI}\left(\right)}^{2}\right) + {angle}^{2} \cdot \left(\frac{-1}{24488801280000000} \cdot \left(a \cdot \left({angle}^{2} \cdot {\mathsf{PI}\left(\right)}^{6}\right)\right) + \frac{1}{25194240000} \cdot \left(a \cdot {\mathsf{PI}\left(\right)}^{4}\right)\right)\right)}\right) + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    8. Applied rewrites76.7%

      \[\leadsto \mathsf{PI}\left(\right) \cdot \color{blue}{\frac{angle}{180}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]

    if -1.6e144 < b < 2.6000000000000002e108

    1. Initial program 77.2%

      \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {b}^{2} \cdot {\sin \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} \]
    4. Applied rewrites72.5%

      \[\leadsto \color{blue}{{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 66.5% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\ t_1 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\ \mathbf{if}\;b \leq -2.3 \cdot 10^{+167}:\\ \;\;\;\;t\_1 + {\left(b \cdot \sin t\_0\right)}^{2}\\ \mathbf{elif}\;b \leq 1.25 \cdot 10^{+155}:\\ \;\;\;\;{\left(a \cdot \cos t\_1\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;t\_0 + {\left(b \cdot \sin t\_1\right)}^{2}\\ \end{array} \end{array} \]
(FPCore (a b angle)
 :precision binary64
 (let* ((t_0 (* (PI) (PI))) (t_1 (* (PI) (/ angle 180.0))))
   (if (<= b -2.3e+167)
     (+ t_1 (pow (* b (sin t_0)) 2.0))
     (if (<= b 1.25e+155)
       (pow (* a (cos t_1)) 2.0)
       (+ t_0 (pow (* b (sin t_1)) 2.0))))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
t_1 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
\mathbf{if}\;b \leq -2.3 \cdot 10^{+167}:\\
\;\;\;\;t\_1 + {\left(b \cdot \sin t\_0\right)}^{2}\\

\mathbf{elif}\;b \leq 1.25 \cdot 10^{+155}:\\
\;\;\;\;{\left(a \cdot \cos t\_1\right)}^{2}\\

\mathbf{else}:\\
\;\;\;\;t\_0 + {\left(b \cdot \sin t\_1\right)}^{2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if b < -2.29999999999999988e167

    1. Initial program 96.4%

      \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    4. Applied rewrites84.6%

      \[\leadsto \color{blue}{a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    5. Taylor expanded in angle around 0

      \[\leadsto a + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    6. Applied rewrites84.7%

      \[\leadsto {\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{\color{blue}{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    7. Taylor expanded in angle around 0

      \[\leadsto \left(a + \color{blue}{{angle}^{2} \cdot \left(\frac{-1}{64800} \cdot \left(a \cdot {\mathsf{PI}\left(\right)}^{2}\right) + {angle}^{2} \cdot \left(\frac{-1}{24488801280000000} \cdot \left(a \cdot \left({angle}^{2} \cdot {\mathsf{PI}\left(\right)}^{6}\right)\right) + \frac{1}{25194240000} \cdot \left(a \cdot {\mathsf{PI}\left(\right)}^{4}\right)\right)\right)}\right) + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    8. Applied rewrites84.7%

      \[\leadsto \mathsf{PI}\left(\right) \cdot \color{blue}{\frac{angle}{180}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    9. Taylor expanded in angle around 0

      \[\leadsto \mathsf{PI}\left(\right) \cdot \frac{angle}{180} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \color{blue}{\left(\frac{1}{180} \cdot angle\right)}\right)\right)}^{2} \]
    10. Applied rewrites85.3%

      \[\leadsto \mathsf{PI}\left(\right) \cdot \frac{angle}{180} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \color{blue}{\mathsf{PI}\left(\right)}\right)\right)}^{2} \]

    if -2.29999999999999988e167 < b < 1.25e155

    1. Initial program 76.5%

      \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {b}^{2} \cdot {\sin \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} \]
    4. Applied rewrites69.1%

      \[\leadsto \color{blue}{{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}} \]

    if 1.25e155 < b

    1. Initial program 99.6%

      \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    4. Applied rewrites85.2%

      \[\leadsto \color{blue}{a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    5. Taylor expanded in angle around 0

      \[\leadsto a + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    6. Applied rewrites88.2%

      \[\leadsto {\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{\color{blue}{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    7. Taylor expanded in angle around 0

      \[\leadsto \left(a + \color{blue}{{angle}^{2} \cdot \left(\frac{-1}{64800} \cdot \left(a \cdot {\mathsf{PI}\left(\right)}^{2}\right) + {angle}^{2} \cdot \left(\frac{-1}{24488801280000000} \cdot \left(a \cdot \left({angle}^{2} \cdot {\mathsf{PI}\left(\right)}^{6}\right)\right) + \frac{1}{25194240000} \cdot \left(a \cdot {\mathsf{PI}\left(\right)}^{4}\right)\right)\right)}\right) + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    8. Applied rewrites88.2%

      \[\leadsto \mathsf{PI}\left(\right) \cdot \color{blue}{\frac{angle}{180}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    9. Taylor expanded in angle around 0

      \[\leadsto \mathsf{PI}\left(\right) \cdot \left(\frac{1}{180} \cdot angle\right) + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    10. Applied rewrites77.6%

      \[\leadsto \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right) + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 67.5% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\ t_1 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right) + {\left(b \cdot \sin t\_0\right)}^{2}\\ \mathbf{if}\;b \leq -1.95 \cdot 10^{+154}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;b \leq 1.25 \cdot 10^{+155}:\\ \;\;\;\;{\left(a \cdot \cos t\_0\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b angle)
 :precision binary64
 (let* ((t_0 (* (PI) (/ angle 180.0)))
        (t_1 (+ (* (PI) (PI)) (pow (* b (sin t_0)) 2.0))))
   (if (<= b -1.95e+154)
     t_1
     (if (<= b 1.25e+155) (pow (* a (cos t_0)) 2.0) t_1))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
t_1 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right) + {\left(b \cdot \sin t\_0\right)}^{2}\\
\mathbf{if}\;b \leq -1.95 \cdot 10^{+154}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;b \leq 1.25 \cdot 10^{+155}:\\
\;\;\;\;{\left(a \cdot \cos t\_0\right)}^{2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -1.9500000000000001e154 or 1.25e155 < b

    1. Initial program 98.3%

      \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    4. Applied rewrites84.2%

      \[\leadsto \color{blue}{a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    5. Taylor expanded in angle around 0

      \[\leadsto a + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    6. Applied rewrites85.8%

      \[\leadsto {\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{\color{blue}{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    7. Taylor expanded in angle around 0

      \[\leadsto \left(a + \color{blue}{{angle}^{2} \cdot \left(\frac{-1}{64800} \cdot \left(a \cdot {\mathsf{PI}\left(\right)}^{2}\right) + {angle}^{2} \cdot \left(\frac{-1}{24488801280000000} \cdot \left(a \cdot \left({angle}^{2} \cdot {\mathsf{PI}\left(\right)}^{6}\right)\right) + \frac{1}{25194240000} \cdot \left(a \cdot {\mathsf{PI}\left(\right)}^{4}\right)\right)\right)}\right) + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    8. Applied rewrites85.8%

      \[\leadsto \mathsf{PI}\left(\right) \cdot \color{blue}{\frac{angle}{180}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    9. Taylor expanded in angle around 0

      \[\leadsto \mathsf{PI}\left(\right) \cdot \left(\frac{1}{180} \cdot angle\right) + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    10. Applied rewrites78.6%

      \[\leadsto \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right) + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]

    if -1.9500000000000001e154 < b < 1.25e155

    1. Initial program 76.1%

      \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {b}^{2} \cdot {\sin \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} \]
    4. Applied rewrites69.6%

      \[\leadsto \color{blue}{{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 57.3% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\ \mathbf{if}\;\frac{angle}{180} \leq -2 \cdot 10^{+131}:\\ \;\;\;\;{\left({t\_0}^{2}\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;{\left(a \cdot \cos t\_0\right)}^{2}\\ \end{array} \end{array} \]
(FPCore (a b angle)
 :precision binary64
 (let* ((t_0 (* (PI) (/ angle 180.0))))
   (if (<= (/ angle 180.0) -2e+131)
     (pow (pow t_0 2.0) 2.0)
     (pow (* a (cos t_0)) 2.0))))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
\mathbf{if}\;\frac{angle}{180} \leq -2 \cdot 10^{+131}:\\
\;\;\;\;{\left({t\_0}^{2}\right)}^{2}\\

\mathbf{else}:\\
\;\;\;\;{\left(a \cdot \cos t\_0\right)}^{2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 angle #s(literal 180 binary64)) < -1.9999999999999998e131

    1. Initial program 62.9%

      \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {b}^{2} \cdot {\sin \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} \]
    4. Applied rewrites33.8%

      \[\leadsto \color{blue}{{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}} \]
    5. Taylor expanded in angle around 0

      \[\leadsto {a}^{2} \]
    6. Applied rewrites49.9%

      \[\leadsto {\left({\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{2}\right)}^{2} \]

    if -1.9999999999999998e131 < (/.f64 angle #s(literal 180 binary64))

    1. Initial program 85.1%

      \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

      \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {b}^{2} \cdot {\sin \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} \]
    4. Applied rewrites64.8%

      \[\leadsto \color{blue}{{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 23.6% accurate, 2.0× speedup?

\[\begin{array}{l} \\ {\left({\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{2}\right)}^{2} \end{array} \]
(FPCore (a b angle)
 :precision binary64
 (pow (pow (* (PI) (/ angle 180.0)) 2.0) 2.0))
\begin{array}{l}

\\
{\left({\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{2}\right)}^{2}
\end{array}
Derivation
  1. Initial program 81.5%

    \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  2. Add Preprocessing
  3. Taylor expanded in a around 0

    \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {b}^{2} \cdot {\sin \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} \]
  4. Applied rewrites59.7%

    \[\leadsto \color{blue}{{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}} \]
  5. Taylor expanded in angle around 0

    \[\leadsto {a}^{2} \]
  6. Applied rewrites24.3%

    \[\leadsto {\left({\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{2}\right)}^{2} \]
  7. Add Preprocessing

Alternative 8: 17.8% accurate, 3.8× speedup?

\[\begin{array}{l} \\ {\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{2} \end{array} \]
(FPCore (a b angle) :precision binary64 (pow (* (PI) (/ angle 180.0)) 2.0))
\begin{array}{l}

\\
{\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{2}
\end{array}
Derivation
  1. Initial program 81.5%

    \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  2. Add Preprocessing
  3. Taylor expanded in a around 0

    \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  4. Applied rewrites27.8%

    \[\leadsto \color{blue}{a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  5. Taylor expanded in angle around 0

    \[\leadsto a + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  6. Applied rewrites34.3%

    \[\leadsto {\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{\color{blue}{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  7. Taylor expanded in a around 0

    \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {b}^{2} \cdot {\sin \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} \]
  8. Applied rewrites17.9%

    \[\leadsto \color{blue}{{\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{2}} \]
  9. Add Preprocessing

Alternative 9: 4.4% accurate, 4.2× speedup?

\[\begin{array}{l} \\ {\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)}^{2} \end{array} \]
(FPCore (a b angle) :precision binary64 (pow (* (PI) (PI)) 2.0))
\begin{array}{l}

\\
{\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)}^{2}
\end{array}
Derivation
  1. Initial program 81.5%

    \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  2. Add Preprocessing
  3. Taylor expanded in a around 0

    \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  4. Applied rewrites27.8%

    \[\leadsto \color{blue}{a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  5. Taylor expanded in angle around 0

    \[\leadsto a + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  6. Applied rewrites34.3%

    \[\leadsto {\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{\color{blue}{2}} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  7. Taylor expanded in a around 0

    \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {b}^{2} \cdot {\sin \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} \]
  8. Applied rewrites17.9%

    \[\leadsto \color{blue}{{\left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}^{2}} \]
  9. Taylor expanded in angle around 0

    \[\leadsto {\left(\mathsf{PI}\left(\right) \cdot \left(\frac{1}{180} \cdot angle\right)\right)}^{2} \]
  10. Applied rewrites4.3%

    \[\leadsto {\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)}^{2} \]
  11. Add Preprocessing

Alternative 10: 4.4% accurate, 74.7× speedup?

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

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

    \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  2. Add Preprocessing
  3. Taylor expanded in a around 0

    \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {b}^{2} \cdot {\sin \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} \]
  4. Applied rewrites59.7%

    \[\leadsto \color{blue}{{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}} \]
  5. Taylor expanded in b around inf

    \[\leadsto \color{blue}{{b}^{2} \cdot \left(\frac{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}}{{b}^{2}} + {\sin \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}\right)} \]
  6. Applied rewrites3.1%

    \[\leadsto \color{blue}{\mathsf{PI}\left(\right) \cdot \frac{angle}{180}} \]
  7. Taylor expanded in angle around 0

    \[\leadsto \mathsf{PI}\left(\right) \cdot \left(\frac{1}{180} \cdot \color{blue}{angle}\right) \]
  8. Applied rewrites4.3%

    \[\leadsto \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right) \]
  9. Add Preprocessing

Alternative 11: 4.4% accurate, 448.0× speedup?

\[\begin{array}{l} \\ \mathsf{PI}\left(\right) \end{array} \]
(FPCore (a b angle) :precision binary64 (PI))
\begin{array}{l}

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

    \[{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} \]
  2. Add Preprocessing
  3. Taylor expanded in a around 0

    \[\leadsto \color{blue}{{a}^{2} \cdot {\cos \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {b}^{2} \cdot {\sin \left(\frac{1}{180} \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}} \]
  4. Applied rewrites59.7%

    \[\leadsto \color{blue}{{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}} \]
  5. Taylor expanded in angle around 0

    \[\leadsto \color{blue}{{a}^{2}} \]
  6. Applied rewrites4.3%

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

Reproduce

?
herbie shell --seed 2024321 
(FPCore (a b angle)
  :name "ab-angle->ABCF C"
  :precision binary64
  :pre (TRUE)
  (+ (pow (* a (cos (* (PI) (/ angle 180.0)))) 2.0) (pow (* b (sin (* (PI) (/ angle 180.0)))) 2.0)))