
(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 13 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 (cbrt (pow (PI) 1.5))))
(+
(pow (* (sin (* (/ angle 180.0) (PI))) b) 2.0)
(pow
(*
(cos
(* (sqrt (PI)) (* angle (* 0.005555555555555556 (sqrt (* t_0 t_0))))))
a)
2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{{\mathsf{PI}\left(\right)}^{1.5}}\\
{\left(\sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2} + {\left(\cos \left(\sqrt{\mathsf{PI}\left(\right)} \cdot \left(angle \cdot \left(0.005555555555555556 \cdot \sqrt{t\_0 \cdot t\_0}\right)\right)\right) \cdot a\right)}^{2}
\end{array}
\end{array}
Initial program 82.1%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
metadata-evalN/A
lift-PI.f64N/A
lower-sqrt.f6482.1
Applied rewrites82.1%
lift-PI.f64N/A
add-cbrt-cubeN/A
lift-PI.f64N/A
lift-PI.f64N/A
lift-PI.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
unswap-sqrN/A
cbrt-prodN/A
lower-*.f64N/A
lower-cbrt.f64N/A
unpow1N/A
lift-sqrt.f64N/A
pow1/2N/A
pow-prod-upN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
Applied rewrites82.2%
Final simplification82.2%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (sqrt (PI))))
(+
(pow (* (sin (* (* t_0 t_0) (/ angle 180.0))) b) 2.0)
(pow (* (cos (* (* (* t_0 0.005555555555555556) angle) t_0)) a) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(\sin \left(\left(t\_0 \cdot t\_0\right) \cdot \frac{angle}{180}\right) \cdot b\right)}^{2} + {\left(\cos \left(\left(\left(t\_0 \cdot 0.005555555555555556\right) \cdot angle\right) \cdot t\_0\right) \cdot a\right)}^{2}
\end{array}
\end{array}
Initial program 82.1%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
metadata-evalN/A
lift-PI.f64N/A
lower-sqrt.f6482.1
Applied rewrites82.1%
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lower-*.f6482.1
Applied rewrites82.1%
Final simplification82.1%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (sqrt (PI))))
(+
(pow (* (cos (* (* (* t_0 0.005555555555555556) angle) t_0)) a) 2.0)
(pow (* (sin (* (/ angle 180.0) (PI))) b) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(\cos \left(\left(\left(t\_0 \cdot 0.005555555555555556\right) \cdot angle\right) \cdot t\_0\right) \cdot a\right)}^{2} + {\left(\sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}
\end{array}
\end{array}
Initial program 82.1%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
metadata-evalN/A
lift-PI.f64N/A
lower-sqrt.f6482.1
Applied rewrites82.1%
Final simplification82.1%
(FPCore (a b angle) :precision binary64 (+ (pow (* (sin (/ 1.0 (/ (/ 180.0 angle) (PI)))) b) 2.0) (pow (* (cos (* (/ angle 180.0) (PI))) a) 2.0)))
\begin{array}{l}
\\
{\left(\sin \left(\frac{1}{\frac{\frac{180}{angle}}{\mathsf{PI}\left(\right)}}\right) \cdot b\right)}^{2} + {\left(\cos \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot a\right)}^{2}
\end{array}
Initial program 82.1%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
clear-numN/A
lower-/.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6482.1
Applied rewrites82.1%
Final simplification82.1%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (* 0.005555555555555556 (PI)) angle))) (+ (pow (* (cos t_0) a) 2.0) (pow (* (sin t_0) b) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\\
{\left(\cos t\_0 \cdot a\right)}^{2} + {\left(\sin t\_0 \cdot b\right)}^{2}
\end{array}
\end{array}
Initial program 82.1%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
metadata-evalN/A
lift-PI.f64N/A
lower-sqrt.f6482.1
Applied rewrites82.1%
lift-PI.f64N/A
add-cbrt-cubeN/A
lift-PI.f64N/A
lift-PI.f64N/A
lift-PI.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
unswap-sqrN/A
cbrt-prodN/A
lower-*.f64N/A
lower-cbrt.f64N/A
unpow1N/A
lift-sqrt.f64N/A
pow1/2N/A
pow-prod-upN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
Applied rewrites82.2%
Applied rewrites82.1%
Final simplification82.1%
(FPCore (a b angle) :precision binary64 (fma (+ (* (cos (* (* (* 0.005555555555555556 (PI)) angle) 2.0)) 0.5) 0.5) (* a a) (pow (* (sin (* (* angle 0.005555555555555556) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\cos \left(\left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot 2\right) \cdot 0.5 + 0.5, a \cdot 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 82.1%
lift-+.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
lower-fma.f64N/A
Applied rewrites82.0%
lift-pow.f64N/A
unpow2N/A
lift-cos.f64N/A
lift-/.f64N/A
metadata-evalN/A
distribute-neg-frac2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r/N/A
lift-/.f64N/A
lift-*.f64N/A
cos-negN/A
lift-cos.f64N/A
lift-/.f64N/A
metadata-evalN/A
distribute-neg-frac2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r/N/A
lift-/.f64N/A
lift-*.f64N/A
Applied rewrites82.1%
Final simplification82.1%
(FPCore (a b angle) :precision binary64 (fma (fma (cos (* (* angle (PI)) -0.011111111111111112)) 0.5 0.5) (* a a) (pow (* (sin (* (* angle 0.005555555555555556) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(\cos \left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot -0.011111111111111112\right), 0.5, 0.5\right), a \cdot 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 82.1%
lift-+.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
lower-fma.f64N/A
Applied rewrites82.0%
lift-pow.f64N/A
unpow2N/A
lift-cos.f64N/A
lift-cos.f64N/A
sqr-cos-aN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites26.7%
lift-/.f64N/A
lift--.f64N/A
metadata-evalN/A
lift-*.f64N/A
lift--.f64N/A
flip-+N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6482.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.0
Applied rewrites82.0%
Final simplification82.0%
(FPCore (a b angle)
:precision binary64
(if (<= a 0.0074)
(fma
(*
(* (* (PI) (PI)) angle)
(fma (* b b) 3.08641975308642e-5 (* -3.08641975308642e-5 (* a a))))
angle
(* a a))
(* (pow (cos (* (* angle (PI)) -0.005555555555555556)) 2.0) (* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 0.0074:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot \mathsf{fma}\left(b \cdot b, 3.08641975308642 \cdot 10^{-5}, -3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot a\right)\right), angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\cos \left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot -0.005555555555555556\right)}^{2} \cdot \left(a \cdot a\right)\\
\end{array}
\end{array}
if a < 0.0074000000000000003Initial program 80.6%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
metadata-evalN/A
lift-PI.f64N/A
lower-sqrt.f6480.7
Applied rewrites80.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites42.6%
Applied rewrites47.9%
if 0.0074000000000000003 < a Initial program 86.7%
lift-+.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
lower-fma.f64N/A
Applied rewrites86.8%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f6481.9
Applied rewrites81.9%
Final simplification56.0%
(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(\left(angle \cdot 0.005555555555555556\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 82.1%
lift-+.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
lower-fma.f64N/A
Applied rewrites82.0%
Taylor expanded in angle around 0
Applied rewrites82.0%
Final simplification82.0%
(FPCore (a b angle)
:precision binary64
(if (<= (/ angle 180.0) 1e-183)
(* a a)
(if (<= (/ angle 180.0) 5e+146)
(fma
(* (* (* (* (PI) (PI)) 3.08641975308642e-5) b) b)
(* angle angle)
(* a a))
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{angle}{180} \leq 10^{-183}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;\frac{angle}{180} \leq 5 \cdot 10^{+146}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right) \cdot b, angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if (/.f64 angle #s(literal 180 binary64)) < 1.00000000000000001e-183 or 4.9999999999999999e146 < (/.f64 angle #s(literal 180 binary64)) Initial program 80.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6464.9
Applied rewrites64.9%
if 1.00000000000000001e-183 < (/.f64 angle #s(literal 180 binary64)) < 4.9999999999999999e146Initial program 85.6%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
metadata-evalN/A
lift-PI.f64N/A
lower-sqrt.f6485.7
Applied rewrites85.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites52.1%
Taylor expanded in a around 0
Applied rewrites81.8%
(FPCore (a b angle)
:precision binary64
(if (<= a 0.0074)
(fma
(*
(* (* (PI) (PI)) angle)
(fma (* b b) 3.08641975308642e-5 (* -3.08641975308642e-5 (* a a))))
angle
(* a a))
(* a a)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 0.0074:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot \mathsf{fma}\left(b \cdot b, 3.08641975308642 \cdot 10^{-5}, -3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot a\right)\right), angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 0.0074000000000000003Initial program 80.6%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
metadata-evalN/A
lift-PI.f64N/A
lower-sqrt.f6480.7
Applied rewrites80.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites42.6%
Applied rewrites47.9%
if 0.0074000000000000003 < a Initial program 86.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6482.2
Applied rewrites82.2%
Final simplification56.0%
(FPCore (a b angle) :precision binary64 (if (<= b 5.5e+253) (* a a) (* (* (* (* angle angle) 3.08641975308642e-5) (* b b)) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.5 \cdot 10^{+253}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(b \cdot b\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if b < 5.5000000000000003e253Initial program 81.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6467.1
Applied rewrites67.1%
if 5.5000000000000003e253 < b Initial program 99.6%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
metadata-evalN/A
lift-PI.f64N/A
lower-sqrt.f6499.6
Applied rewrites99.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites46.0%
Taylor expanded in a around 0
Applied rewrites55.1%
Applied rewrites55.1%
Final simplification66.6%
(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 82.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6465.6
Applied rewrites65.6%
herbie shell --seed 2024304
(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)))