
(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 11 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 (* (sin (* (* t_0 (* angle 0.005555555555555556)) t_0)) b) 2.0)
(pow (* (cos (* angle (* (PI) 0.005555555555555556))) a) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(\sin \left(\left(t\_0 \cdot \left(angle \cdot 0.005555555555555556\right)\right) \cdot t\_0\right) \cdot b\right)}^{2} + {\left(\cos \left(angle \cdot \left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right)\right) \cdot a\right)}^{2}
\end{array}
\end{array}
Initial program 79.8%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval79.8
Applied rewrites79.8%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6479.9
Applied rewrites79.9%
Final simplification79.9%
(FPCore (a b angle) :precision binary64 (+ (pow (* (sin (* (* angle 0.005555555555555556) (PI))) b) 2.0) (pow (* (cos (* angle (* (PI) 0.005555555555555556))) a) 2.0)))
\begin{array}{l}
\\
{\left(\sin \left(\left(angle \cdot 0.005555555555555556\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2} + {\left(\cos \left(angle \cdot \left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right)\right) \cdot a\right)}^{2}
\end{array}
Initial program 79.8%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval79.8
Applied rewrites79.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6479.8
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6479.8
Applied rewrites79.8%
Final simplification79.8%
(FPCore (a b angle) :precision binary64 (pow (hypot (* (cos (* (* angle (PI)) -0.005555555555555556)) a) (* (sin (* (* angle 0.005555555555555556) (PI))) b)) 2.0))
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(\cos \left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot -0.005555555555555556\right) \cdot a, \sin \left(\left(angle \cdot 0.005555555555555556\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)\right)}^{2}
\end{array}
Initial program 79.8%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval79.8
Applied rewrites79.8%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6479.9
Applied rewrites79.9%
Applied rewrites79.7%
Final simplification79.7%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (sqrt (PI))))
(+
(pow (* 1.0 a) 2.0)
(pow (* (sin (* (* t_0 (* angle 0.005555555555555556)) t_0)) b) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(1 \cdot a\right)}^{2} + {\left(\sin \left(\left(t\_0 \cdot \left(angle \cdot 0.005555555555555556\right)\right) \cdot t\_0\right) \cdot b\right)}^{2}
\end{array}
\end{array}
Initial program 79.8%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval79.8
Applied rewrites79.8%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6479.9
Applied rewrites79.9%
Taylor expanded in angle around 0
Applied rewrites79.2%
Final simplification79.2%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (* b angle) (PI))))
(if (<= a 3.15e-105)
(fma
(*
(* (* (PI) (PI)) angle)
(fma (* b b) 3.08641975308642e-5 (* -3.08641975308642e-5 (* a a))))
angle
(* a a))
(if (<= a 8e+120)
(*
(fma
(* t_0 t_0)
(/ 3.08641975308642e-5 (* a a))
(fma (* (* (* angle angle) -3.08641975308642e-5) (PI)) (PI) 1.0))
(* a a))
(* (pow (cos (* (* angle (PI)) -0.005555555555555556)) 2.0) (* a a))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(b \cdot angle\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;a \leq 3.15 \cdot 10^{-105}:\\
\;\;\;\;\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{elif}\;a \leq 8 \cdot 10^{+120}:\\
\;\;\;\;\mathsf{fma}\left(t\_0 \cdot t\_0, \frac{3.08641975308642 \cdot 10^{-5}}{a \cdot a}, \mathsf{fma}\left(\left(\left(angle \cdot angle\right) \cdot -3.08641975308642 \cdot 10^{-5}\right) \cdot \mathsf{PI}\left(\right), \mathsf{PI}\left(\right), 1\right)\right) \cdot \left(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 < 3.15e-105Initial program 75.7%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval75.8
Applied rewrites75.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites42.0%
Applied rewrites48.4%
if 3.15e-105 < a < 7.9999999999999998e120Initial program 80.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval80.1
Applied rewrites80.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites63.9%
Taylor expanded in a around inf
Applied rewrites73.9%
if 7.9999999999999998e120 < a Initial program 96.3%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6496.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6496.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6496.3
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval96.3
Applied rewrites96.3%
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-*.f6496.2
Applied rewrites96.2%
Final simplification59.5%
(FPCore (a b angle) :precision binary64 (fma (* (* 1.0 a) 1.0) a (pow (* (sin (* (* angle 0.005555555555555556) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(1 \cdot a\right) \cdot 1, 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.8%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval79.8
Applied rewrites79.8%
Taylor expanded in angle around 0
Applied rewrites79.1%
Applied rewrites79.1%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (* b angle) (PI))))
(if (<= a 3.15e-105)
(fma
(*
(* (* (PI) (PI)) angle)
(fma (* b b) 3.08641975308642e-5 (* -3.08641975308642e-5 (* a a))))
angle
(* a a))
(if (<= a 9e+121)
(*
(fma
(* t_0 t_0)
(/ 3.08641975308642e-5 (* a a))
(fma (* (* (* angle angle) -3.08641975308642e-5) (PI)) (PI) 1.0))
(* a a))
(* a a)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(b \cdot angle\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;a \leq 3.15 \cdot 10^{-105}:\\
\;\;\;\;\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{elif}\;a \leq 9 \cdot 10^{+121}:\\
\;\;\;\;\mathsf{fma}\left(t\_0 \cdot t\_0, \frac{3.08641975308642 \cdot 10^{-5}}{a \cdot a}, \mathsf{fma}\left(\left(\left(angle \cdot angle\right) \cdot -3.08641975308642 \cdot 10^{-5}\right) \cdot \mathsf{PI}\left(\right), \mathsf{PI}\left(\right), 1\right)\right) \cdot \left(a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 3.15e-105Initial program 75.7%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval75.8
Applied rewrites75.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites42.0%
Applied rewrites48.4%
if 3.15e-105 < a < 9.0000000000000007e121Initial program 80.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval80.1
Applied rewrites80.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites63.9%
Taylor expanded in a around inf
Applied rewrites73.9%
if 9.0000000000000007e121 < a Initial program 96.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6496.2
Applied rewrites96.2%
Final simplification59.5%
(FPCore (a b angle)
:precision binary64
(if (<= (/ angle 180.0) 1e-180)
(* a a)
(if (<= (/ angle 180.0) 2e+198)
(fma
(* (* (* 3.08641975308642e-5 (* b b)) (PI)) (PI))
(* angle angle)
(* a a))
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{angle}{180} \leq 10^{-180}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;\frac{angle}{180} \leq 2 \cdot 10^{+198}:\\
\;\;\;\;\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)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if (/.f64 angle #s(literal 180 binary64)) < 1e-180 or 2.00000000000000004e198 < (/.f64 angle #s(literal 180 binary64)) Initial program 80.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6464.0
Applied rewrites64.0%
if 1e-180 < (/.f64 angle #s(literal 180 binary64)) < 2.00000000000000004e198Initial program 77.4%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval77.3
Applied rewrites77.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.0%
Taylor expanded in a around 0
Applied rewrites68.4%
(FPCore (a b angle)
:precision binary64
(if (<= a 4.9e+121)
(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 4.9 \cdot 10^{+121}:\\
\;\;\;\;\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 < 4.8999999999999998e121Initial program 76.3%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval76.4
Applied rewrites76.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites45.0%
Applied rewrites50.5%
if 4.8999999999999998e121 < a Initial program 96.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6496.2
Applied rewrites96.2%
Final simplification58.4%
(FPCore (a b angle) :precision binary64 (if (<= b 8e+153) (* a a) (* (* (* (* (PI) (PI)) b) b) (* (* angle angle) 3.08641975308642e-5))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8 \cdot 10^{+153}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right) \cdot b\right) \cdot \left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right)\\
\end{array}
\end{array}
if b < 8e153Initial program 77.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.8
Applied rewrites62.8%
if 8e153 < b Initial program 99.6%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval99.6
Applied rewrites99.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites36.9%
Taylor expanded in a around 0
Applied rewrites55.1%
Final simplification62.1%
(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)))