
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (/ angle 180.0) (PI)))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \mathsf{PI}\left(\right)\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos t\_0\right)}^{2}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (/ angle 180.0) (PI)))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \mathsf{PI}\left(\right)\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos t\_0\right)}^{2}
\end{array}
\end{array}
(FPCore (a b angle) :precision binary64 (fma (* 1.0 b) b (pow (* (sin (* (PI) (* 0.005555555555555556 angle))) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(1 \cdot b, b, {\left(\sin \left(\mathsf{PI}\left(\right) \cdot \left(0.005555555555555556 \cdot angle\right)\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 79.9%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites80.0%
Taylor expanded in angle around 0
Applied rewrites80.5%
(FPCore (a b angle) :precision binary64 (if (<= a 3.7e-97) (* b b) (fma (* 1.0 b) b (pow (* (* (* 0.005555555555555556 (PI)) angle) a) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3.7 \cdot 10^{-97}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1 \cdot b, b, {\left(\left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot a\right)}^{2}\right)\\
\end{array}
\end{array}
if a < 3.69999999999999976e-97Initial program 79.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6465.3
Applied rewrites65.3%
if 3.69999999999999976e-97 < a Initial program 80.7%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites80.6%
Taylor expanded in angle around 0
Applied rewrites80.8%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6477.0
Applied rewrites77.0%
(FPCore (a b angle)
:precision binary64
(if (<= a 3.7e-97)
(* b b)
(if (<= a 1.35e+154)
(fma
(* (* (* 3.08641975308642e-5 (* a a)) (PI)) (PI))
(* angle angle)
(* b b))
(* (* (* (* 3.08641975308642e-5 a) angle) (* a angle)) (* (PI) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3.7 \cdot 10^{-97}:\\
\;\;\;\;b \cdot b\\
\mathbf{elif}\;a \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot a\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle \cdot angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot angle\right) \cdot \left(a \cdot angle\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 3.69999999999999976e-97Initial program 79.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6465.3
Applied rewrites65.3%
if 3.69999999999999976e-97 < a < 1.35000000000000003e154Initial program 72.7%
Taylor expanded in angle around 0
Applied rewrites72.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites42.2%
Taylor expanded in a around inf
Applied rewrites65.8%
if 1.35000000000000003e154 < a Initial program 99.8%
Taylor expanded in angle around 0
Applied rewrites99.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites71.6%
Taylor expanded in a around inf
Applied rewrites78.1%
Applied rewrites80.2%
(FPCore (a b angle) :precision binary64 (if (<= a 3e+81) (* b b) (* (* (* (* 3.08641975308642e-5 a) angle) (* a angle)) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3 \cdot 10^{+81}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot angle\right) \cdot \left(a \cdot angle\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 2.99999999999999997e81Initial program 78.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.7
Applied rewrites63.7%
if 2.99999999999999997e81 < a Initial program 89.0%
Taylor expanded in angle around 0
Applied rewrites89.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites58.0%
Taylor expanded in a around inf
Applied rewrites62.0%
Applied rewrites65.6%
(FPCore (a b angle) :precision binary64 (if (<= a 3e+81) (* b b) (* (* 3.08641975308642e-5 (* a (* (* a angle) angle))) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3 \cdot 10^{+81}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot \left(\left(a \cdot angle\right) \cdot angle\right)\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 2.99999999999999997e81Initial program 78.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.7
Applied rewrites63.7%
if 2.99999999999999997e81 < a Initial program 89.0%
Taylor expanded in angle around 0
Applied rewrites89.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites58.0%
Taylor expanded in a around inf
Applied rewrites62.0%
Applied rewrites63.4%
(FPCore (a b angle) :precision binary64 (if (<= a 3e+81) (* b b) (* (* 3.08641975308642e-5 a) (* (* (* angle angle) a) (* (PI) (PI))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3 \cdot 10^{+81}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot \left(\left(\left(angle \cdot angle\right) \cdot a\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right)\\
\end{array}
\end{array}
if a < 2.99999999999999997e81Initial program 78.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.7
Applied rewrites63.7%
if 2.99999999999999997e81 < a Initial program 89.0%
Taylor expanded in angle around 0
Applied rewrites89.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites58.0%
Taylor expanded in a around inf
Applied rewrites62.0%
Applied rewrites62.0%
(FPCore (a b angle) :precision binary64 (* b b))
double code(double a, double b, double angle) {
return b * b;
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = b * b
end function
public static double code(double a, double b, double angle) {
return b * b;
}
def code(a, b, angle): return b * b
function code(a, b, angle) return Float64(b * b) end
function tmp = code(a, b, angle) tmp = b * b; end
code[a_, b_, angle_] := N[(b * b), $MachinePrecision]
\begin{array}{l}
\\
b \cdot b
\end{array}
Initial program 79.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.0
Applied rewrites60.0%
herbie shell --seed 2024318
(FPCore (a b angle)
:name "ab-angle->ABCF A"
:precision binary64
(+ (pow (* a (sin (* (/ angle 180.0) (PI)))) 2.0) (pow (* b (cos (* (/ angle 180.0) (PI)))) 2.0)))