
(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 9 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
(let* ((t_0 (pow (cbrt (sqrt (PI))) 3.0)))
(fma
(* b (pow (cos (* (* t_0 t_0) (* angle 0.005555555555555556))) 2.0))
b
(pow (* (sin (* (PI) (* angle 0.005555555555555556))) a) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(\sqrt[3]{\sqrt{\mathsf{PI}\left(\right)}}\right)}^{3}\\
\mathsf{fma}\left(b \cdot {\cos \left(\left(t\_0 \cdot t\_0\right) \cdot \left(angle \cdot 0.005555555555555556\right)\right)}^{2}, b, {\left(\sin \left(\mathsf{PI}\left(\right) \cdot \left(angle \cdot 0.005555555555555556\right)\right) \cdot a\right)}^{2}\right)
\end{array}
\end{array}
Initial program 81.2%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6481.1
Applied rewrites81.1%
Applied rewrites81.2%
Applied rewrites81.2%
rem-cube-cbrtN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
cbrt-prodN/A
unpow-prod-downN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-cbrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lower-pow.f64N/A
lower-cbrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6481.2
Applied rewrites81.2%
Final simplification81.2%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (PI) (* angle 0.005555555555555556)))) (fma (* (pow (cos t_0) 2.0) b) b (pow (* (sin t_0) a) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \left(angle \cdot 0.005555555555555556\right)\\
\mathsf{fma}\left({\cos t\_0}^{2} \cdot b, b, {\left(\sin t\_0 \cdot a\right)}^{2}\right)
\end{array}
\end{array}
Initial program 81.2%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6481.1
Applied rewrites81.1%
Applied rewrites81.2%
Applied rewrites81.2%
Final simplification81.2%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (PI) (* angle 0.005555555555555556)))) (+ (pow (* (cos t_0) b) 2.0) (pow (* (sin t_0) a) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \left(angle \cdot 0.005555555555555556\right)\\
{\left(\cos t\_0 \cdot b\right)}^{2} + {\left(\sin t\_0 \cdot a\right)}^{2}
\end{array}
\end{array}
Initial program 81.2%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6481.1
Applied rewrites81.1%
Applied rewrites81.2%
lift-/.f64N/A
lift-/.f64N/A
associate-/r/N/A
div-invN/A
metadata-evalN/A
associate-*r*N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f6481.2
Applied rewrites81.2%
Final simplification81.2%
(FPCore (a b angle)
:precision binary64
(if (<= b 1.32e+104)
(fma
(*
(* (* (PI) (PI)) angle)
(fma (* 3.08641975308642e-5 a) a (* -3.08641975308642e-5 (* b b))))
angle
(* b b))
(* (pow (cos (* (* (PI) 0.005555555555555556) angle)) 2.0) (* b b))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.32 \cdot 10^{+104}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot \mathsf{fma}\left(3.08641975308642 \cdot 10^{-5} \cdot a, a, -3.08641975308642 \cdot 10^{-5} \cdot \left(b \cdot b\right)\right), angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;{\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)}^{2} \cdot \left(b \cdot b\right)\\
\end{array}
\end{array}
if b < 1.32000000000000003e104Initial program 79.3%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
Applied rewrites78.9%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites47.5%
Applied rewrites51.9%
if 1.32000000000000003e104 < b Initial program 89.5%
Taylor expanded in a 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-*.f6489.5
Applied rewrites89.5%
Final simplification58.8%
(FPCore (a b angle) :precision binary64 (fma (* 1.0 b) b (pow (* (sin (* (PI) (* angle 0.005555555555555556))) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(1 \cdot b, b, {\left(\sin \left(\mathsf{PI}\left(\right) \cdot \left(angle \cdot 0.005555555555555556\right)\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 81.2%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6481.1
Applied rewrites81.1%
Applied rewrites81.2%
Applied rewrites81.2%
Taylor expanded in angle around 0
Applied rewrites80.7%
Final simplification80.7%
(FPCore (a b angle)
:precision binary64
(if (<= b 1.32e+104)
(fma
(*
(* (* (PI) (PI)) angle)
(fma (* 3.08641975308642e-5 a) a (* -3.08641975308642e-5 (* b b))))
angle
(* b b))
(* b b)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.32 \cdot 10^{+104}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot \mathsf{fma}\left(3.08641975308642 \cdot 10^{-5} \cdot a, a, -3.08641975308642 \cdot 10^{-5} \cdot \left(b \cdot b\right)\right), angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 1.32000000000000003e104Initial program 79.3%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
Applied rewrites78.9%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites47.5%
Applied rewrites51.9%
if 1.32000000000000003e104 < b Initial program 89.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6489.5
Applied rewrites89.5%
Final simplification58.8%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.42e-101)
(* b b)
(fma
(* (* (* a a) 3.08641975308642e-5) (* (PI) (PI)))
(* angle angle)
(* b b))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.42 \cdot 10^{-101}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), angle \cdot angle, b \cdot b\right)\\
\end{array}
\end{array}
if a < 1.4200000000000001e-101Initial program 79.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.4
Applied rewrites61.4%
if 1.4200000000000001e-101 < a Initial program 85.0%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
Applied rewrites84.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites41.2%
Taylor expanded in a around inf
Applied rewrites67.5%
Final simplification63.3%
(FPCore (a b angle) :precision binary64 (if (<= a 3.1e+163) (* b b) (* (* (* angle angle) (* (PI) (PI))) (* (* a a) 3.08641975308642e-5))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3.1 \cdot 10^{+163}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(angle \cdot angle\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right)\\
\end{array}
\end{array}
if a < 3.10000000000000029e163Initial program 78.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.1
Applied rewrites61.1%
if 3.10000000000000029e163 < a Initial program 99.8%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
Applied rewrites99.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.7%
Taylor expanded in a around inf
Applied rewrites66.0%
Final simplification61.7%
(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 81.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.2
Applied rewrites58.2%
herbie shell --seed 2024283
(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)))