
(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 (+ (pow (* a (cos (/ (* (pow (PI) 0.25) (* (pow (PI) 0.75) angle)) 180.0))) 2.0) (pow (* b (sin (* (PI) (/ angle 180.0)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \cos \left(\frac{{\mathsf{PI}\left(\right)}^{0.25} \cdot \left({\mathsf{PI}\left(\right)}^{0.75} \cdot angle\right)}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}
\end{array}
Initial program 82.6%
lift-*.f64N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*l*N/A
rem-square-sqrtN/A
associate-*l*N/A
lower-*.f64N/A
lift-PI.f64N/A
pow1/2N/A
sqrt-pow1N/A
lower-pow.f64N/A
metadata-evalN/A
lower-*.f64N/A
lift-PI.f64N/A
pow1/2N/A
sqrt-pow1N/A
lower-pow.f64N/A
metadata-evalN/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites82.6%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites82.7%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (* (PI) 0.005555555555555556) angle))
(t_1 (* (PI) (/ angle 180.0)))
(t_2 (+ (pow (* a (cos t_1)) 2.0) (pow (* b (sin t_1)) 2.0))))
(if (<= t_2 0.0)
(* a a)
(if (<= t_2 1e+209)
(+
(fma
(* (* angle angle) -3.08641975308642e-5)
(* (* (* a a) (PI)) (PI))
(* a a))
(pow (* b (sin t_0)) 2.0))
(fma
(pow (cos t_0) 2.0)
(* a a)
(*
(* 3.08641975308642e-5 (* angle angle))
(* (* (* (PI) (PI)) b) b)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\\
t_1 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
t_2 := {\left(a \cdot \cos t\_1\right)}^{2} + {\left(b \cdot \sin t\_1\right)}^{2}\\
\mathbf{if}\;t\_2 \leq 0:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;t\_2 \leq 10^{+209}:\\
\;\;\;\;\mathsf{fma}\left(\left(angle \cdot angle\right) \cdot -3.08641975308642 \cdot 10^{-5}, \left(\left(a \cdot a\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), a \cdot a\right) + {\left(b \cdot \sin t\_0\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\cos t\_0}^{2}, a \cdot a, \left(3.08641975308642 \cdot 10^{-5} \cdot \left(angle \cdot angle\right)\right) \cdot \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right) \cdot b\right)\right)\\
\end{array}
\end{array}
if (+.f64 (pow.f64 (*.f64 a (cos.f64 (*.f64 (PI.f64) (/.f64 angle #s(literal 180 binary64))))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (sin.f64 (*.f64 (PI.f64) (/.f64 angle #s(literal 180 binary64))))) #s(literal 2 binary64))) < 0.0Initial program 100.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
if 0.0 < (+.f64 (pow.f64 (*.f64 a (cos.f64 (*.f64 (PI.f64) (/.f64 angle #s(literal 180 binary64))))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (sin.f64 (*.f64 (PI.f64) (/.f64 angle #s(literal 180 binary64))))) #s(literal 2 binary64))) < 1.0000000000000001e209Initial program 70.8%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
lower-sin.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6470.8
Applied rewrites70.8%
lift-PI.f64N/A
add-cbrt-cubeN/A
lower-cbrt.f64N/A
rem-cube-cbrtN/A
add-cbrt-cubeN/A
lift-PI.f64N/A
lower-pow.f6470.8
Applied rewrites70.8%
Taylor expanded in angle around 0
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites64.5%
if 1.0000000000000001e209 < (+.f64 (pow.f64 (*.f64 a (cos.f64 (*.f64 (PI.f64) (/.f64 angle #s(literal 180 binary64))))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (sin.f64 (*.f64 (PI.f64) (/.f64 angle #s(literal 180 binary64))))) #s(literal 2 binary64))) Initial program 90.1%
Taylor expanded in a around 0
*-commutativeN/A
lower-fma.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-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites86.6%
Taylor expanded in angle around 0
Applied rewrites84.8%
Final simplification77.4%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (cos (* (cbrt (pow (PI) 3.0)) (/ angle 180.0)))) 2.0) (pow (* b (sin (* (* (PI) 0.005555555555555556) angle))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \cos \left(\sqrt[3]{{\mathsf{PI}\left(\right)}^{3}} \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)\right)}^{2}
\end{array}
Initial program 82.6%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
lower-sin.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6482.6
Applied rewrites82.6%
lift-PI.f64N/A
add-cbrt-cubeN/A
lower-cbrt.f64N/A
rem-cube-cbrtN/A
add-cbrt-cubeN/A
lift-PI.f64N/A
lower-pow.f6482.6
Applied rewrites82.6%
(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}
Initial program 82.6%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (cos (* (PI) (/ angle 180.0)))) 2.0) (pow (* b (sin (* (* (PI) 0.005555555555555556) angle))) 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(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)\right)}^{2}
\end{array}
Initial program 82.6%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
lower-sin.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6482.6
Applied rewrites82.6%
(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 82.6%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
lower-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6482.6
Applied rewrites82.6%
(FPCore (a b angle) :precision binary64 (fma (pow (cos (* (* (PI) 0.005555555555555556) angle)) 2.0) (* a a) (pow (* (sin (* (* 0.005555555555555556 (PI)) angle)) 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(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 82.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-fma.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-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites72.1%
Applied rewrites82.5%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (* 0.005555555555555556 (PI)) angle))) (+ (pow (* (cos t_0) a) 2.0) (pow (* b (sin t_0)) 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(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
Initial program 82.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-fma.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-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites72.1%
Applied rewrites82.5%
(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 82.6%
Taylor expanded in angle around 0
Applied rewrites82.3%
(FPCore (a b angle) :precision binary64 (+ (pow (* a 1.0) 2.0) (pow (* b (sin (* (* (PI) 0.005555555555555556) angle))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot 1\right)}^{2} + {\left(b \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)\right)}^{2}
\end{array}
Initial program 82.6%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
lower-sin.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6482.6
Applied rewrites82.6%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6482.5
Applied rewrites82.5%
Taylor expanded in angle around 0
Applied rewrites82.3%
Final simplification82.3%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) (PI))))
(if (<= (/ angle 180.0) 2e-25)
(+
(* (fma -3.08641975308642e-5 (* (* t_0 angle) angle) 1.0) (* a a))
(pow (* b (sin (* (PI) (/ angle 180.0)))) 2.0))
(fma
(pow (cos (* (* (PI) 0.005555555555555556) angle)) 2.0)
(* a a)
(* (* 3.08641975308642e-5 (* angle angle)) (* (* t_0 b) b))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;\frac{angle}{180} \leq 2 \cdot 10^{-25}:\\
\;\;\;\;\mathsf{fma}\left(-3.08641975308642 \cdot 10^{-5}, \left(t\_0 \cdot angle\right) \cdot angle, 1\right) \cdot \left(a \cdot a\right) + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)}^{2}, a \cdot a, \left(3.08641975308642 \cdot 10^{-5} \cdot \left(angle \cdot angle\right)\right) \cdot \left(\left(t\_0 \cdot b\right) \cdot b\right)\right)\\
\end{array}
\end{array}
if (/.f64 angle #s(literal 180 binary64)) < 2.00000000000000008e-25Initial program 86.9%
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-*.f6468.4
Applied rewrites68.4%
if 2.00000000000000008e-25 < (/.f64 angle #s(literal 180 binary64)) Initial program 67.4%
Taylor expanded in a around 0
*-commutativeN/A
lower-fma.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-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites66.9%
Taylor expanded in angle around 0
Applied rewrites59.8%
(FPCore (a b angle)
:precision binary64
(if (<= (/ angle 180.0) 2e-163)
(* a a)
(fma
(pow (cos (* (* (PI) 0.005555555555555556) angle)) 2.0)
(* a a)
(* (* 3.08641975308642e-5 (* angle angle)) (* (* (* (PI) (PI)) b) b)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{angle}{180} \leq 2 \cdot 10^{-163}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)}^{2}, a \cdot a, \left(3.08641975308642 \cdot 10^{-5} \cdot \left(angle \cdot angle\right)\right) \cdot \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right) \cdot b\right)\right)\\
\end{array}
\end{array}
if (/.f64 angle #s(literal 180 binary64)) < 1.99999999999999985e-163Initial program 84.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.8
Applied rewrites63.8%
if 1.99999999999999985e-163 < (/.f64 angle #s(literal 180 binary64)) Initial program 78.0%
Taylor expanded in a around 0
*-commutativeN/A
lower-fma.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-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites74.9%
Taylor expanded in angle around 0
Applied rewrites70.1%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.25e-137)
(* (pow (sin (* (* (PI) 0.005555555555555556) angle)) 2.0) (* b b))
(if (<= a 5.5e+69)
(fma
(* (* -3.08641975308642e-5 (* (PI) (PI))) (- (* a a) (* b b)))
(* angle angle)
(* a a))
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.25 \cdot 10^{-137}:\\
\;\;\;\;{\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 5.5 \cdot 10^{+69}:\\
\;\;\;\;\mathsf{fma}\left(\left(-3.08641975308642 \cdot 10^{-5} \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \left(a \cdot a - b \cdot b\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.25e-137Initial program 83.7%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-sin.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f6443.1
Applied rewrites43.1%
if 1.25e-137 < a < 5.50000000000000002e69Initial program 77.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites59.5%
if 5.50000000000000002e69 < a Initial program 86.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6482.7
Applied rewrites82.7%
(FPCore (a b angle)
:precision binary64
(if (<= a 5.5e+69)
(fma
(* (* -3.08641975308642e-5 (* (PI) (PI))) (- (* a a) (* b b)))
(* angle angle)
(* a a))
(* a a)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 5.5 \cdot 10^{+69}:\\
\;\;\;\;\mathsf{fma}\left(\left(-3.08641975308642 \cdot 10^{-5} \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \left(a \cdot a - b \cdot b\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 5.50000000000000002e69Initial program 82.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites49.1%
if 5.50000000000000002e69 < a Initial program 86.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6482.7
Applied rewrites82.7%
(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.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.6
Applied rewrites60.6%
herbie shell --seed 2024326
(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)))