
(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 15 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
(let* ((t_0 (sqrt (PI))))
(+
(pow (* a (cos (* (PI) (/ angle 180.0)))) 2.0)
(pow (* b (sin (* (* (/ angle 180.0) t_0) t_0))) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\left(\frac{angle}{180} \cdot t\_0\right) \cdot t\_0\right)\right)}^{2}
\end{array}
\end{array}
Initial program 79.8%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
sqr-neg-revN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
lower-sqrt.f6479.9
Applied rewrites79.9%
Final simplification79.9%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (sqrt (PI))))
(+
(pow (* a (cos (* (PI) (/ angle 180.0)))) 2.0)
(pow (* b (sin (* (/ (* t_0 angle) 180.0) t_0))) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\frac{t\_0 \cdot angle}{180} \cdot t\_0\right)\right)}^{2}
\end{array}
\end{array}
Initial program 79.8%
lift-*.f64N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6479.8
Applied rewrites79.8%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (sqrt (PI))))
(+
(pow (* a (cos (* (* (/ angle 180.0) t_0) t_0))) 2.0)
(pow (* b (sin (* (* 0.005555555555555556 (PI)) angle))) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(a \cdot \cos \left(\left(\frac{angle}{180} \cdot t\_0\right) \cdot t\_0\right)\right)}^{2} + {\left(b \cdot \sin \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)\right)}^{2}
\end{array}
\end{array}
Initial program 79.8%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
sqr-neg-revN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
lower-sqrt.f6479.8
Applied rewrites79.8%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
cos-PIN/A
associate-*r*N/A
*-commutativeN/A
lower-sin.f64N/A
*-commutativeN/A
associate-*r*N/A
cos-PIN/A
metadata-evalN/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6479.8
Applied rewrites79.8%
Final simplification79.8%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (cos (* (* (PI) 0.005555555555555556) angle))) 2.0) (pow (* b (sin (* (PI) (/ angle 180.0)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}
\end{array}
Initial program 79.8%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6479.8
Applied rewrites79.8%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (cos (* (* 0.005555555555555556 (PI)) angle))) 2.0) (pow (* b (sin (/ (* (PI) angle) 180.0))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \cos \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)\right)}^{2} + {\left(b \cdot \sin \left(\frac{\mathsf{PI}\left(\right) \cdot angle}{180}\right)\right)}^{2}
\end{array}
Initial program 79.8%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
sqr-neg-revN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
lower-sqrt.f6479.9
Applied rewrites79.9%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-neg-revN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-/.f64N/A
associate-*l/N/A
lift-*.f64N/A
lift-/.f6479.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6479.7
Applied rewrites79.7%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6479.7
Applied rewrites79.7%
(FPCore (a b angle) :precision binary64 (fma (pow (cos (fma -0.005555555555555556 (* (PI) angle) (PI))) 2.0) (* a a) (pow (* (sin (* (* 0.005555555555555556 (PI)) angle)) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left({\cos \left(\mathsf{fma}\left(-0.005555555555555556, \mathsf{PI}\left(\right) \cdot angle, \mathsf{PI}\left(\right)\right)\right)}^{2}, a \cdot a, {\left(\sin \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 79.8%
lift-pow.f64N/A
pow-to-expN/A
*-commutativeN/A
exp-prodN/A
unpow1N/A
pow-to-expN/A
rem-log-expN/A
lower-pow.f64N/A
lower-exp.f64N/A
rem-log-expN/A
pow-to-expN/A
unpow1N/A
lower-log.f6441.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6441.6
Applied rewrites41.6%
Taylor expanded in a around -inf
+-commutativeN/A
distribute-rgt-inN/A
exp-sumN/A
lower-fma.f64N/A
Applied rewrites69.3%
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.8%
Taylor expanded in angle around 0
Applied rewrites79.1%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) (/ angle 180.0))) (t_1 (* (PI) (PI))))
(if (<= angle 3e-58)
(+
(* (fma -3.08641975308642e-5 (* (* t_1 angle) angle) 1.0) (* a a))
(pow (* b (sin t_0)) 2.0))
(if (<= angle 5.4e+201)
(+
(pow (* a (cos t_0)) 2.0)
(* (* 3.08641975308642e-5 (* angle angle)) (* (* t_1 b) b)))
(* a a)))))\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)\\
\mathbf{if}\;angle \leq 3 \cdot 10^{-58}:\\
\;\;\;\;\mathsf{fma}\left(-3.08641975308642 \cdot 10^{-5}, \left(t\_1 \cdot angle\right) \cdot angle, 1\right) \cdot \left(a \cdot a\right) + {\left(b \cdot \sin t\_0\right)}^{2}\\
\mathbf{elif}\;angle \leq 5.4 \cdot 10^{+201}:\\
\;\;\;\;{\left(a \cdot \cos t\_0\right)}^{2} + \left(3.08641975308642 \cdot 10^{-5} \cdot \left(angle \cdot angle\right)\right) \cdot \left(\left(t\_1 \cdot b\right) \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if angle < 3.00000000000000008e-58Initial program 84.5%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
distribute-lft1-inN/A
lower-*.f64N/A
lower-fma.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f6469.4
Applied rewrites69.4%
if 3.00000000000000008e-58 < angle < 5.3999999999999999e201Initial program 69.7%
Taylor expanded in angle around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f6462.7
Applied rewrites62.7%
if 5.3999999999999999e201 < angle Initial program 65.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.1
Applied rewrites60.1%
(FPCore (a b angle)
:precision binary64
(if (<= a 26.0)
(fma
(*
(* (* (- a b) (+ b a)) (* (* (PI) (PI)) -3.08641975308642e-5))
(- angle))
(- angle)
(* a a))
(+ (pow (* a (cos (* (PI) (/ angle 180.0)))) 2.0) 0.0)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 26:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(a - b\right) \cdot \left(b + a\right)\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -3.08641975308642 \cdot 10^{-5}\right)\right) \cdot \left(-angle\right), -angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(a \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2} + 0\\
\end{array}
\end{array}
if a < 26Initial program 75.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites42.8%
Applied rewrites49.8%
if 26 < a Initial program 93.3%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
sqr-neg-revN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
lower-sqrt.f6494.7
Applied rewrites94.7%
lift-sin.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
sin-negN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-outN/A
associate-*r*N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
*-commutativeN/A
Applied rewrites83.9%
Taylor expanded in angle around 0
unpow2N/A
sin-PIN/A
sin-PIN/A
metadata-evalN/A
mul0-rgt89.8
Applied rewrites89.8%
(FPCore (a b angle)
:precision binary64
(if (<= a 26.0)
(fma
(*
(* (* (- a b) (+ b a)) (* (* (PI) (PI)) -3.08641975308642e-5))
(- angle))
(- angle)
(* a a))
(* (pow (cos (* (* 0.005555555555555556 (PI)) angle)) 2.0) (* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 26:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(a - b\right) \cdot \left(b + a\right)\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -3.08641975308642 \cdot 10^{-5}\right)\right) \cdot \left(-angle\right), -angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\cos \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)}^{2} \cdot \left(a \cdot a\right)\\
\end{array}
\end{array}
if a < 26Initial program 75.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites42.8%
Applied rewrites49.8%
if 26 < a Initial program 93.3%
lift-pow.f64N/A
pow-to-expN/A
*-commutativeN/A
exp-prodN/A
unpow1N/A
pow-to-expN/A
rem-log-expN/A
lower-pow.f64N/A
lower-exp.f64N/A
rem-log-expN/A
pow-to-expN/A
unpow1N/A
lower-log.f6475.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6475.9
Applied rewrites75.9%
Taylor expanded in a around -inf
+-commutativeN/A
distribute-rgt-inN/A
exp-sumN/A
lower-fma.f64N/A
Applied rewrites86.1%
Taylor expanded in a around inf
Applied rewrites89.9%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.35e+121)
(fma
(*
(* (* (- a b) (+ b a)) (* (* (PI) (PI)) -3.08641975308642e-5))
(- angle))
(- angle)
(* a a))
(* a a)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.35 \cdot 10^{+121}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(a - b\right) \cdot \left(b + a\right)\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -3.08641975308642 \cdot 10^{-5}\right)\right) \cdot \left(-angle\right), -angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.3500000000000001e121Initial program 76.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites45.0%
Applied rewrites51.5%
if 1.3500000000000001e121 < a Initial program 96.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6496.2
Applied rewrites96.2%
(FPCore (a b angle)
:precision binary64
(if (or (<= angle 1.2e-176) (not (<= angle 5.4e+201)))
(* a a)
(fma
(* (* (* 3.08641975308642e-5 (* b b)) (PI)) (PI))
(* angle angle)
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;angle \leq 1.2 \cdot 10^{-176} \lor \neg \left(angle \leq 5.4 \cdot 10^{+201}\right):\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(b \cdot b\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle \cdot angle, a \cdot a\right)\\
\end{array}
\end{array}
if angle < 1.20000000000000003e-176 or 5.3999999999999999e201 < angle Initial program 80.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6464.0
Applied rewrites64.0%
if 1.20000000000000003e-176 < angle < 5.3999999999999999e201Initial program 77.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.0%
Taylor expanded in a around 0
Applied rewrites68.4%
Final simplification65.2%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.35e+121)
(fma
(* (* (- a b) (+ b a)) (* (* (* (PI) (PI)) -3.08641975308642e-5) angle))
angle
(* a a))
(* a a)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.35 \cdot 10^{+121}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(a - b\right) \cdot \left(b + a\right)\right) \cdot \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -3.08641975308642 \cdot 10^{-5}\right) \cdot angle\right), angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.3500000000000001e121Initial program 76.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites45.0%
Applied rewrites51.5%
if 1.3500000000000001e121 < a Initial program 96.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6496.2
Applied rewrites96.2%
(FPCore (a b angle) :precision binary64 (if (<= a 8.5e-157) (* (* 3.08641975308642e-5 (* angle (* (* b b) angle))) (* (PI) (PI))) (* a a)))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 8.5 \cdot 10^{-157}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(angle \cdot \left(\left(b \cdot b\right) \cdot angle\right)\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 8.49999999999999976e-157Initial program 76.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites40.7%
Taylor expanded in a around 0
Applied rewrites32.7%
Taylor expanded in a around 0
Applied rewrites41.1%
if 8.49999999999999976e-157 < a Initial program 87.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6476.3
Applied rewrites76.3%
(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.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.8
Applied rewrites60.8%
herbie shell --seed 2024332
(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)))