
(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 12 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 (+ (pow (* a (sin (/ -1.0 (/ -180.0 (* angle (PI)))))) 2.0) (pow (* b (cos (* (* angle 0.005555555555555556) (PI)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\frac{-1}{\frac{-180}{angle \cdot \mathsf{PI}\left(\right)}}\right)\right)}^{2} + {\left(b \cdot \cos \left(\left(angle \cdot 0.005555555555555556\right) \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}
\end{array}
Initial program 77.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
div-invN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
metadata-eval77.3
Applied rewrites77.3%
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6477.4
Applied rewrites77.4%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lift-*.f64N/A
associate-*l*N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
metadata-evalN/A
associate-/r/N/A
associate-/l/N/A
lift-/.f64N/A
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
lower-/.f64N/A
Applied rewrites77.4%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (* angle (PI)) 0.005555555555555556))) 2.0) (pow (* b (cos (* (* angle 0.005555555555555556) (PI)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot 0.005555555555555556\right)\right)}^{2} + {\left(b \cdot \cos \left(\left(angle \cdot 0.005555555555555556\right) \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}
\end{array}
Initial program 77.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
div-invN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
metadata-eval77.3
Applied rewrites77.3%
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6477.4
Applied rewrites77.4%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
associate-*l*N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6477.4
Applied rewrites77.4%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (* 0.005555555555555556 (PI)) angle))) 2.0) (pow (* b 1.0) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)\right)}^{2} + {\left(b \cdot 1\right)}^{2}
\end{array}
Initial program 77.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
div-invN/A
*-commutativeN/A
lower-*.f64N/A
metadata-eval77.3
Applied rewrites77.3%
Taylor expanded in angle around 0
Applied rewrites77.1%
(FPCore (a b angle) :precision binary64 (fma (* (* 1.0 b) 1.0) b (pow (* (sin (* (* 0.005555555555555556 angle) (PI))) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(1 \cdot b\right) \cdot 1, b, {\left(\sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 77.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
div-invN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
metadata-eval77.3
Applied rewrites77.3%
Taylor expanded in angle around 0
Applied rewrites77.1%
Applied rewrites77.0%
(FPCore (a b angle)
:precision binary64
(if (<= a 3.5e-72)
(* b b)
(if (<= a 3.4e+153)
(fma
(* (* (* 3.08641975308642e-5 (* a a)) (PI)) (PI))
(* angle angle)
(* b b))
(* (* (* (* 3.08641975308642e-5 a) angle) (* a angle)) (* (PI) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3.5 \cdot 10^{-72}:\\
\;\;\;\;b \cdot b\\
\mathbf{elif}\;a \leq 3.4 \cdot 10^{+153}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot a\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle \cdot angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot angle\right) \cdot \left(a \cdot angle\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 3.5e-72Initial program 74.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.8
Applied rewrites60.8%
if 3.5e-72 < a < 3.3999999999999997e153Initial program 74.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites34.6%
Taylor expanded in a around inf
Applied rewrites62.3%
if 3.3999999999999997e153 < a Initial program 97.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites50.0%
Taylor expanded in a around inf
Applied rewrites77.1%
Applied rewrites87.4%
(FPCore (a b angle) :precision binary64 (if (<= a 1.9e+153) (* b b) (* (* (* (* 3.08641975308642e-5 a) angle) (* a angle)) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.9 \cdot 10^{+153}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot angle\right) \cdot \left(a \cdot angle\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 1.89999999999999983e153Initial program 74.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.4
Applied rewrites58.4%
if 1.89999999999999983e153 < a Initial program 97.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites50.0%
Taylor expanded in a around inf
Applied rewrites77.1%
Applied rewrites87.4%
(FPCore (a b angle) :precision binary64 (if (<= a 2e+153) (* b b) (* (* (* 3.08641975308642e-5 (* (* angle angle) a)) a) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2 \cdot 10^{+153}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(\left(angle \cdot angle\right) \cdot a\right)\right) \cdot a\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 2e153Initial program 74.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.4
Applied rewrites58.4%
if 2e153 < a Initial program 97.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites50.0%
Taylor expanded in a around inf
Applied rewrites77.1%
Applied rewrites77.1%
(FPCore (a b angle) :precision binary64 (if (<= a 2e+153) (* b b) (* (* 3.08641975308642e-5 (* a (* (* angle angle) a))) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2 \cdot 10^{+153}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot \left(\left(angle \cdot angle\right) \cdot a\right)\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 2e153Initial program 74.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.4
Applied rewrites58.4%
if 2e153 < a Initial program 97.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites50.0%
Taylor expanded in a around inf
Applied rewrites77.1%
(FPCore (a b angle) :precision binary64 (if (<= a 2e+153) (* b b) (* (* 3.08641975308642e-5 a) (* (* (* angle angle) a) (* (PI) (PI))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2 \cdot 10^{+153}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot \left(\left(\left(angle \cdot angle\right) \cdot a\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right)\\
\end{array}
\end{array}
if a < 2e153Initial program 74.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.4
Applied rewrites58.4%
if 2e153 < a Initial program 97.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites50.0%
Taylor expanded in a around inf
Applied rewrites77.1%
Applied rewrites77.0%
(FPCore (a b angle) :precision binary64 (if (<= b 2.9e-89) (* (* (* (* (* a a) 3.08641975308642e-5) angle) angle) (* (PI) (PI))) (* b b)))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.9 \cdot 10^{-89}:\\
\;\;\;\;\left(\left(\left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot angle\right) \cdot angle\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 2.89999999999999992e-89Initial program 76.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites37.2%
Taylor expanded in a around inf
Applied rewrites36.4%
Taylor expanded in a around 0
Applied rewrites40.4%
if 2.89999999999999992e-89 < b Initial program 78.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6464.7
Applied rewrites64.7%
(FPCore (a b angle) :precision binary64 (if (<= a 2e+153) (* b b) (* (* (* angle angle) 3.08641975308642e-5) (* (* (* (PI) (PI)) a) a))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2 \cdot 10^{+153}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot a\right) \cdot a\right)\\
\end{array}
\end{array}
if a < 2e153Initial program 74.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.4
Applied rewrites58.4%
if 2e153 < a Initial program 97.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites50.0%
Taylor expanded in a around inf
Applied rewrites77.1%
Taylor expanded in a around 0
Applied rewrites71.2%
(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 77.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6454.7
Applied rewrites54.7%
herbie shell --seed 2024322
(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)))