
(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:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (a b angle) :precision binary64 (+ (pow (* a (cos (* (PI) (/ angle 180.0)))) 2.0) (pow (* b (sin (/ (/ (PI) 180.0) (pow angle -1.0)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\frac{\frac{\mathsf{PI}\left(\right)}{180}}{{angle}^{-1}}\right)\right)}^{2}
\end{array}
Initial program 79.7%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
div-invN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
inv-powN/A
lower-pow.f6479.9
Applied rewrites79.9%
(FPCore (a b angle) :precision binary64 (+ (pow (* (cos (* (* (PI) angle) -0.005555555555555556)) a) 2.0) (pow (* b (sin (* (PI) (/ -0.005555555555555556 (/ -1.0 angle))))) 2.0)))
\begin{array}{l}
\\
{\left(\cos \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot -0.005555555555555556\right) \cdot a\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{-0.005555555555555556}{\frac{-1}{angle}}\right)\right)}^{2}
\end{array}
Initial program 79.7%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
div-invN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
inv-powN/A
lower-pow.f6479.9
Applied rewrites79.9%
lift-/.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
associate-/l*N/A
lower-*.f64N/A
frac-2negN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f64N/A
metadata-evalN/A
lift-pow.f64N/A
unpow-1N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6479.8
Applied rewrites79.8%
lift-pow.f64N/A
lift-*.f64N/A
unpow-prod-downN/A
lift-cos.f64N/A
cos-negN/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
lift-*.f64N/A
distribute-frac-negN/A
metadata-evalN/A
frac-2negN/A
lift-/.f64N/A
lift-cos.f64N/A
unpow-prod-downN/A
Applied rewrites79.8%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (cos (* (PI) (/ angle 180.0)))) 2.0) (pow (* b (sin (* (* angle (PI)) 0.005555555555555556))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot 0.005555555555555556\right)\right)}^{2}
\end{array}
Initial program 79.7%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
div-invN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
metadata-eval79.8
Applied rewrites79.8%
(FPCore (a b angle) :precision binary64 (fma (pow (cos (* (* (PI) 0.005555555555555556) angle)) 2.0) (* a a) (pow (* (sin (* angle (* 0.005555555555555556 (PI)))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left({\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)}^{2}, a \cdot a, {\left(\sin \left(angle \cdot \left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 79.7%
Taylor expanded in a around 0
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites67.4%
Applied rewrites79.8%
(FPCore (a b angle) :precision binary64 (fma (+ 0.5 (* 0.5 (cos (* 2.0 (* (* 0.005555555555555556 angle) (PI)))))) (* a a) (pow (* (sin (* angle (* 0.005555555555555556 (PI)))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right)\right), a \cdot a, {\left(\sin \left(angle \cdot \left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 79.7%
Taylor expanded in a around 0
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites67.4%
Applied rewrites79.8%
Applied rewrites79.7%
(FPCore (a b angle) :precision binary64 (+ (pow (* a 1.0) 2.0) (pow (* b (sin (* (PI) (/ angle 180.0)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot 1\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}
\end{array}
Initial program 79.7%
Taylor expanded in angle around 0
Applied rewrites79.7%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.6e-159)
(* (pow (sin (* (* (PI) 0.005555555555555556) angle)) 2.0) (* b b))
(if (<= a 1.8e-6)
(fma
(*
(* (PI) (PI))
(fma 3.08641975308642e-5 (* b b) (* -3.08641975308642e-5 (* a a))))
(* angle angle)
(* a a))
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.6 \cdot 10^{-159}:\\
\;\;\;\;{\sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)}^{2} \cdot \left(b \cdot b\right)\\
\mathbf{elif}\;a \leq 1.8 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{fma}\left(3.08641975308642 \cdot 10^{-5}, b \cdot b, -3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot a\right)\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.6e-159Initial program 78.0%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f6439.7
Applied rewrites39.7%
if 1.6e-159 < a < 1.79999999999999992e-6Initial program 80.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites63.6%
if 1.79999999999999992e-6 < a Initial program 84.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6475.1
Applied rewrites75.1%
(FPCore (a b angle) :precision binary64 (fma 1.0 (* a a) (pow (* (sin (* angle (* 0.005555555555555556 (PI)))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(1, a \cdot a, {\left(\sin \left(angle \cdot \left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 79.7%
Taylor expanded in a around 0
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites67.4%
Applied rewrites79.8%
Taylor expanded in angle around 0
Applied rewrites79.7%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.8e-6)
(fma
(*
(* (PI) (PI))
(fma 3.08641975308642e-5 (* b b) (* -3.08641975308642e-5 (* a a))))
(* angle angle)
(* a a))
(* a a)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.8 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{fma}\left(3.08641975308642 \cdot 10^{-5}, b \cdot b, -3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot a\right)\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.79999999999999992e-6Initial program 78.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites46.1%
if 1.79999999999999992e-6 < a Initial program 84.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6475.1
Applied rewrites75.1%
(FPCore (a b angle) :precision binary64 (* a a))
double code(double a, double b, double angle) {
return a * a;
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = a * a
end function
public static double code(double a, double b, double angle) {
return a * a;
}
def code(a, b, angle): return a * a
function code(a, b, angle) return Float64(a * a) end
function tmp = code(a, b, angle) tmp = a * a; end
code[a_, b_, angle_] := N[(a * a), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a
\end{array}
Initial program 79.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6453.5
Applied rewrites53.5%
herbie shell --seed 2024318
(FPCore (a b angle)
:name "ab-angle->ABCF C"
:precision binary64
(+ (pow (* a (cos (* (PI) (/ angle 180.0)))) 2.0) (pow (* b (sin (* (PI) (/ angle 180.0)))) 2.0)))