
(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
(let* ((t_0 (sqrt (PI))))
(+
(pow (* (cos (* (* t_0 t_0) (/ angle 180.0))) b) 2.0)
(pow
(sqrt
(sqrt (pow (* (sin (* (PI) (* angle 0.005555555555555556))) a) 2.0)))
4.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(\cos \left(\left(t\_0 \cdot t\_0\right) \cdot \frac{angle}{180}\right) \cdot b\right)}^{2} + {\left(\sqrt{\sqrt{{\left(\sin \left(\mathsf{PI}\left(\right) \cdot \left(angle \cdot 0.005555555555555556\right)\right) \cdot a\right)}^{2}}}\right)}^{4}
\end{array}
\end{array}
Initial program 83.1%
lift-pow.f64N/A
unpow1N/A
sqr-powN/A
unpow-prod-downN/A
pow-prod-upN/A
lower-pow.f64N/A
Applied rewrites48.4%
rem-square-sqrtN/A
sqrt-unprodN/A
unpow2N/A
lift-pow.f64N/A
lower-sqrt.f6483.4
Applied rewrites83.4%
lift-PI.f64N/A
add-sqr-sqrtN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6483.5
Applied rewrites83.5%
Final simplification83.5%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (cos (/ (* (PI) angle) -180.0))))
(fma
(* t_0 (* b b))
t_0
(pow (* (sin (* (PI) (* angle 0.005555555555555556))) a) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{\mathsf{PI}\left(\right) \cdot angle}{-180}\right)\\
\mathsf{fma}\left(t\_0 \cdot \left(b \cdot b\right), t\_0, {\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 83.1%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites83.4%
Final simplification83.4%
(FPCore (a b angle) :precision binary64 (+ (pow (* (cos (/ (* (PI) angle) -180.0)) b) 2.0) (pow (* (sin (* (PI) (* angle 0.005555555555555556))) a) 2.0)))
\begin{array}{l}
\\
{\left(\cos \left(\frac{\mathsf{PI}\left(\right) \cdot angle}{-180}\right) \cdot b\right)}^{2} + {\left(\sin \left(\mathsf{PI}\left(\right) \cdot \left(angle \cdot 0.005555555555555556\right)\right) \cdot a\right)}^{2}
\end{array}
Initial program 83.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6483.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6483.1
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval83.4
Applied rewrites83.4%
Final simplification83.4%
(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 83.1%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites83.4%
lift-fma.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
pow2N/A
pow2N/A
unpow-prod-downN/A
*-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
lift-+.f6483.4
Applied rewrites83.4%
Final simplification83.4%
(FPCore (a b angle) :precision binary64 (+ (pow (* 1.0 b) 2.0) (pow (* (sin (* (/ angle 180.0) (PI))) a) 2.0)))
\begin{array}{l}
\\
{\left(1 \cdot b\right)}^{2} + {\left(\sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot a\right)}^{2}
\end{array}
Initial program 83.1%
Taylor expanded in angle around 0
Applied rewrites83.1%
Final simplification83.1%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (sin (* (PI) (* angle 0.005555555555555556))))) (fma (* (* t_0 a) t_0) a (* b b))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\mathsf{PI}\left(\right) \cdot \left(angle \cdot 0.005555555555555556\right)\right)\\
\mathsf{fma}\left(\left(t\_0 \cdot a\right) \cdot t\_0, a, b \cdot b\right)
\end{array}
\end{array}
Initial program 83.1%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites83.4%
Applied rewrites81.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6481.5
Applied rewrites81.5%
Final simplification81.5%
(FPCore (a b angle) :precision binary64 (if (<= a 4.9e+135) (* (pow (cos (* (* (PI) 0.005555555555555556) angle)) 2.0) (* b b)) (* (* (PI) (PI)) (* (* (* angle a) (* angle a)) 3.08641975308642e-5))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.9 \cdot 10^{+135}:\\
\;\;\;\;{\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)}^{2} \cdot \left(b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(\left(\left(angle \cdot a\right) \cdot \left(angle \cdot a\right)\right) \cdot 3.08641975308642 \cdot 10^{-5}\right)\\
\end{array}
\end{array}
if a < 4.9000000000000001e135Initial program 81.0%
Taylor expanded in b around inf
*-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-*.f6465.1
Applied rewrites65.1%
if 4.9000000000000001e135 < a Initial program 97.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites38.2%
Taylor expanded in b around 0
Applied rewrites74.1%
Applied rewrites79.6%
Final simplification67.0%
(FPCore (a b angle) :precision binary64 (if (<= a 4.9e+135) (* (pow (cos (* -0.005555555555555556 (* (PI) angle))) 2.0) (* b b)) (* (* (PI) (PI)) (* (* (* angle a) (* angle a)) 3.08641975308642e-5))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.9 \cdot 10^{+135}:\\
\;\;\;\;{\cos \left(-0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\right)\right)}^{2} \cdot \left(b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(\left(\left(angle \cdot a\right) \cdot \left(angle \cdot a\right)\right) \cdot 3.08641975308642 \cdot 10^{-5}\right)\\
\end{array}
\end{array}
if a < 4.9000000000000001e135Initial program 81.0%
lift-+.f64N/A
Applied rewrites48.8%
Taylor expanded in b 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-*.f6465.1
Applied rewrites65.1%
if 4.9000000000000001e135 < a Initial program 97.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites38.2%
Taylor expanded in b around 0
Applied rewrites74.1%
Applied rewrites79.6%
Final simplification67.0%
(FPCore (a b angle) :precision binary64 (if (<= a 5.7e+135) (* b b) (* (* (PI) (PI)) (* (* (* angle a) (* angle a)) 3.08641975308642e-5))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 5.7 \cdot 10^{+135}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(\left(\left(angle \cdot a\right) \cdot \left(angle \cdot a\right)\right) \cdot 3.08641975308642 \cdot 10^{-5}\right)\\
\end{array}
\end{array}
if a < 5.7000000000000002e135Initial program 81.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6465.1
Applied rewrites65.1%
if 5.7000000000000002e135 < a Initial program 97.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites38.2%
Taylor expanded in b around 0
Applied rewrites74.1%
Applied rewrites79.6%
Final simplification66.9%
(FPCore (a b angle) :precision binary64 (if (<= a 5.7e+135) (* b b) (* (* (* (* (* angle a) angle) a) 3.08641975308642e-5) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 5.7 \cdot 10^{+135}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(angle \cdot a\right) \cdot angle\right) \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 5.7000000000000002e135Initial program 81.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6465.1
Applied rewrites65.1%
if 5.7000000000000002e135 < a Initial program 97.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites38.2%
Taylor expanded in b around 0
Applied rewrites74.1%
Final simplification66.2%
(FPCore (a b angle) :precision binary64 (if (<= a 4.9e+135) (* b b) (* (* (* (* angle a) angle) (* (PI) (PI))) (* 3.08641975308642e-5 a))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.9 \cdot 10^{+135}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(angle \cdot a\right) \cdot angle\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \left(3.08641975308642 \cdot 10^{-5} \cdot a\right)\\
\end{array}
\end{array}
if a < 4.9000000000000001e135Initial program 81.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6465.1
Applied rewrites65.1%
if 4.9000000000000001e135 < a Initial program 97.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites38.2%
Taylor expanded in b around 0
Applied rewrites74.1%
Applied rewrites74.1%
Final simplification66.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 83.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.5
Applied rewrites60.5%
herbie shell --seed 2024255
(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)))