
(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 12 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 (* (sin (* (* (PI) 0.005555555555555556) angle)) b) 2.0) (pow (* (cos (* (- 0.005555555555555556) (/ (PI) (/ -1.0 angle)))) a) 2.0)))
\begin{array}{l}
\\
{\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right) \cdot b\right)}^{2} + {\left(\cos \left(\left(-0.005555555555555556\right) \cdot \frac{\mathsf{PI}\left(\right)}{\frac{-1}{angle}}\right) \cdot a\right)}^{2}
\end{array}
Initial program 79.3%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
*-commutativeN/A
div-invN/A
times-fracN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
inv-powN/A
lower-pow.f6479.5
Applied rewrites79.5%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lower-neg.f64N/A
lift-pow.f64N/A
unpow-1N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6479.5
Applied rewrites79.5%
lift-*.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6479.5
Applied rewrites79.5%
Final simplification79.5%
(FPCore (a b angle) :precision binary64 (+ (pow (* (cos (/ (* -0.005555555555555556 (PI)) (/ -1.0 angle))) a) 2.0) (pow (* (sin (* (* (PI) 0.005555555555555556) angle)) b) 2.0)))
\begin{array}{l}
\\
{\left(\cos \left(\frac{-0.005555555555555556 \cdot \mathsf{PI}\left(\right)}{\frac{-1}{angle}}\right) \cdot a\right)}^{2} + {\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right) \cdot b\right)}^{2}
\end{array}
Initial program 79.3%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
*-commutativeN/A
div-invN/A
times-fracN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
inv-powN/A
lower-pow.f6479.5
Applied rewrites79.5%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lower-neg.f64N/A
lift-pow.f64N/A
unpow-1N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6479.5
Applied rewrites79.5%
lift-*.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6479.5
Applied rewrites79.5%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
lift-neg.f64N/A
neg-mul-1N/A
associate-*r*N/A
metadata-evalN/A
lower-*.f6479.4
Applied rewrites79.4%
Final simplification79.4%
(FPCore (a b angle) :precision binary64 (+ (pow (* (cos (* (* angle (PI)) -0.005555555555555556)) a) 2.0) (pow (* (sin (* (* angle 0.005555555555555556) (PI))) b) 2.0)))
\begin{array}{l}
\\
{\left(\cos \left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot -0.005555555555555556\right) \cdot a\right)}^{2} + {\left(\sin \left(\left(angle \cdot 0.005555555555555556\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}
\end{array}
Initial program 79.3%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
*-commutativeN/A
div-invN/A
times-fracN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
inv-powN/A
lower-pow.f6479.5
Applied rewrites79.5%
Applied rewrites79.4%
Final simplification79.4%
(FPCore (a b angle) :precision binary64 (fma (* (+ (* (cos (* (* (* angle (PI)) -0.005555555555555556) 2.0)) 0.5) 0.5) a) a (pow (* (sin (* (* angle 0.005555555555555556) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\cos \left(\left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot -0.005555555555555556\right) \cdot 2\right) \cdot 0.5 + 0.5\right) \cdot a, a, {\left(\sin \left(\left(angle \cdot 0.005555555555555556\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 79.3%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites79.4%
lift-pow.f64N/A
unpow2N/A
lift-cos.f64N/A
lift-cos.f64N/A
sqr-cos-aN/A
lower-+.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6479.4
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval79.4
Applied rewrites79.4%
Final simplification79.4%
(FPCore (a b angle)
:precision binary64
(if (<= b 1.3e-41)
(* (pow (cos (* (* (PI) 0.005555555555555556) angle)) 2.0) (* a a))
(if (<= b 1.1e+152)
(fma
(* (* (* (* b b) 3.08641975308642e-5) (PI)) (PI))
(* angle angle)
(* a a))
(* (pow (* (* b (PI)) angle) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.3 \cdot 10^{-41}:\\
\;\;\;\;{\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)}^{2} \cdot \left(a \cdot a\right)\\
\mathbf{elif}\;b \leq 1.1 \cdot 10^{+152}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(b \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 1.3e-41Initial program 78.0%
Taylor expanded in b around 0
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f6464.9
Applied rewrites64.9%
if 1.3e-41 < b < 1.0999999999999999e152Initial program 68.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites29.2%
Taylor expanded in b around inf
Applied rewrites60.3%
if 1.0999999999999999e152 < b Initial program 99.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites45.3%
Taylor expanded in b around inf
Applied rewrites55.7%
Applied rewrites86.5%
Final simplification66.8%
(FPCore (a b angle)
:precision binary64
(if (<= b 1.3e-41)
(* (pow (cos (* (* angle (PI)) -0.005555555555555556)) 2.0) (* a a))
(if (<= b 1.1e+152)
(fma
(* (* (* (* b b) 3.08641975308642e-5) (PI)) (PI))
(* angle angle)
(* a a))
(* (pow (* (* b (PI)) angle) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.3 \cdot 10^{-41}:\\
\;\;\;\;{\cos \left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot -0.005555555555555556\right)}^{2} \cdot \left(a \cdot a\right)\\
\mathbf{elif}\;b \leq 1.1 \cdot 10^{+152}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(b \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 1.3e-41Initial program 78.0%
rem-exp-logN/A
unpow1N/A
log-powN/A
lift-pow.f64N/A
log-powN/A
*-commutativeN/A
exp-prodN/A
lower-pow.f64N/A
exp-1-eN/A
lower-E.f64N/A
*-commutativeN/A
log-powN/A
lift-pow.f64N/A
lower-log.f6476.0
Applied rewrites76.1%
Taylor expanded in b around 0
log-EN/A
unpow1N/A
*-commutativeN/A
rem-exp-logN/A
*-rgt-identityN/A
log-EN/A
lower-*.f64N/A
Applied rewrites65.0%
if 1.3e-41 < b < 1.0999999999999999e152Initial program 68.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites29.2%
Taylor expanded in b around inf
Applied rewrites60.3%
if 1.0999999999999999e152 < b Initial program 99.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites45.3%
Taylor expanded in b around inf
Applied rewrites55.7%
Applied rewrites86.5%
Final simplification66.9%
(FPCore (a b angle) :precision binary64 (+ (* a a) (pow (* (sin (* (* (PI) 0.005555555555555556) angle)) b) 2.0)))
\begin{array}{l}
\\
a \cdot a + {\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right) \cdot b\right)}^{2}
\end{array}
Initial program 79.3%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
*-commutativeN/A
div-invN/A
times-fracN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
inv-powN/A
lower-pow.f6479.5
Applied rewrites79.5%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lower-neg.f64N/A
lift-pow.f64N/A
unpow-1N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6479.5
Applied rewrites79.5%
lift-*.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6479.5
Applied rewrites79.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6479.2
Applied rewrites79.2%
Final simplification79.2%
(FPCore (a b angle)
:precision binary64
(if (<= b 1.3e-41)
(* a a)
(if (<= b 1.1e+152)
(fma
(* (* (* (* b b) 3.08641975308642e-5) (PI)) (PI))
(* angle angle)
(* a a))
(* (pow (* (* b (PI)) angle) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.3 \cdot 10^{-41}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 1.1 \cdot 10^{+152}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(b \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 1.3e-41Initial program 78.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6464.7
Applied rewrites64.7%
if 1.3e-41 < b < 1.0999999999999999e152Initial program 68.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites29.2%
Taylor expanded in b around inf
Applied rewrites60.3%
if 1.0999999999999999e152 < b Initial program 99.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites45.3%
Taylor expanded in b around inf
Applied rewrites55.7%
Applied rewrites86.5%
Final simplification66.7%
(FPCore (a b angle)
:precision binary64
(if (<= a 4e+56)
(fma
(PI)
(*
(*
(*
(fma (* b b) 3.08641975308642e-5 (* -3.08641975308642e-5 (* a a)))
angle)
angle)
(PI))
(* a a))
(* a a)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4 \cdot 10^{+56}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right), \left(\left(\mathsf{fma}\left(b \cdot b, 3.08641975308642 \cdot 10^{-5}, -3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot a\right)\right) \cdot angle\right) \cdot angle\right) \cdot \mathsf{PI}\left(\right), a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 4.00000000000000037e56Initial program 78.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.0%
Applied rewrites50.2%
if 4.00000000000000037e56 < a Initial program 83.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6484.2
Applied rewrites84.2%
Final simplification57.6%
(FPCore (a b angle)
:precision binary64
(if (<= a 4e+56)
(fma
(* (* (* (* b b) 3.08641975308642e-5) (PI)) (PI))
(* angle angle)
(* a a))
(* a a)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4 \cdot 10^{+56}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 4.00000000000000037e56Initial program 78.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.0%
Taylor expanded in b around inf
Applied rewrites61.5%
if 4.00000000000000037e56 < a Initial program 83.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6484.2
Applied rewrites84.2%
Final simplification66.5%
(FPCore (a b angle) :precision binary64 (if (<= b 1.7e+153) (* a a) (* (* (* (* b b) (PI)) (PI)) (* (* angle angle) 3.08641975308642e-5))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.7 \cdot 10^{+153}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(b \cdot b\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right)\\
\end{array}
\end{array}
if b < 1.6999999999999999e153Initial program 76.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.8
Applied rewrites63.8%
if 1.6999999999999999e153 < b Initial program 99.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites45.3%
Taylor expanded in b around inf
Applied rewrites55.7%
Final simplification62.8%
(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.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6459.3
Applied rewrites59.3%
herbie shell --seed 2024259
(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)))