
(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 8 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 (* 1.0 b) 2.0)
(pow
(*
(sin
(*
(/ 1.0 (pow (PI) -0.5))
(* angle (* 0.005555555555555556 (sqrt (PI))))))
a)
2.0)))\begin{array}{l}
\\
{\left(1 \cdot b\right)}^{2} + {\left(\sin \left(\frac{1}{{\mathsf{PI}\left(\right)}^{-0.5}} \cdot \left(angle \cdot \left(0.005555555555555556 \cdot \sqrt{\mathsf{PI}\left(\right)}\right)\right)\right) \cdot a\right)}^{2}
\end{array}
Initial program 78.5%
Taylor expanded in angle around 0
Applied rewrites79.0%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r/N/A
clear-numN/A
associate-*r/N/A
div-invN/A
times-fracN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r/N/A
lift-/.f64N/A
Applied rewrites79.1%
Final simplification79.1%
(FPCore (a b angle)
:precision binary64
(+
(pow
(*
(sin (* (/ angle (pow (PI) -0.5)) (* 0.005555555555555556 (sqrt (PI)))))
a)
2.0)
(pow (* 1.0 b) 2.0)))\begin{array}{l}
\\
{\left(\sin \left(\frac{angle}{{\mathsf{PI}\left(\right)}^{-0.5}} \cdot \left(0.005555555555555556 \cdot \sqrt{\mathsf{PI}\left(\right)}\right)\right) \cdot a\right)}^{2} + {\left(1 \cdot b\right)}^{2}
\end{array}
Initial program 78.5%
Taylor expanded in angle around 0
Applied rewrites79.0%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r/N/A
clear-numN/A
un-div-invN/A
lift-*.f64N/A
div-invN/A
times-fracN/A
lift-/.f64N/A
lower-*.f64N/A
Applied rewrites79.1%
Final simplification79.1%
(FPCore (a b angle) :precision binary64 (+ (pow (* (sin (/ (PI) (/ 180.0 angle))) a) 2.0) (pow (* 1.0 b) 2.0)))
\begin{array}{l}
\\
{\left(\sin \left(\frac{\mathsf{PI}\left(\right)}{\frac{180}{angle}}\right) \cdot a\right)}^{2} + {\left(1 \cdot b\right)}^{2}
\end{array}
Initial program 78.5%
Taylor expanded in angle around 0
Applied rewrites79.0%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6479.1
Applied rewrites79.1%
Final simplification79.1%
(FPCore (a b angle) :precision binary64 (fma (* (* 1.0 b) 1.0) b (pow (* (sin (* (* angle 0.005555555555555556) (PI))) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(1 \cdot b\right) \cdot 1, b, {\left(\sin \left(\left(angle \cdot 0.005555555555555556\right) \cdot \mathsf{PI}\left(\right)\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 78.5%
Taylor expanded in angle around 0
Applied rewrites79.0%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites79.0%
Final simplification79.0%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.75e-77)
(* b b)
(+
(pow (* (* (* 0.005555555555555556 (PI)) angle) a) 2.0)
(pow (* 1.0 b) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.75 \cdot 10^{-77}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot a\right)}^{2} + {\left(1 \cdot b\right)}^{2}\\
\end{array}
\end{array}
if a < 1.75000000000000006e-77Initial program 77.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.2
Applied rewrites61.2%
if 1.75000000000000006e-77 < a Initial program 81.5%
Taylor expanded in angle around 0
Applied rewrites80.9%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6478.2
Applied rewrites78.2%
Final simplification66.4%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) (PI))))
(if (<= a 2.3e-77)
(* b b)
(if (<= a 2.4e+162)
(fma (* (* (* a a) 3.08641975308642e-5) t_0) (* angle angle) (* b b))
(* (* (* (* (* angle angle) a) a) 3.08641975308642e-5) t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;a \leq 2.3 \cdot 10^{-77}:\\
\;\;\;\;b \cdot b\\
\mathbf{elif}\;a \leq 2.4 \cdot 10^{+162}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot t\_0, angle \cdot angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(angle \cdot angle\right) \cdot a\right) \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot t\_0\\
\end{array}
\end{array}
if a < 2.29999999999999999e-77Initial program 77.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.2
Applied rewrites61.2%
if 2.29999999999999999e-77 < a < 2.40000000000000009e162Initial program 64.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6464.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6464.4
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval64.3
Applied rewrites64.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites36.8%
Taylor expanded in b around 0
Applied rewrites55.7%
if 2.40000000000000009e162 < a Initial program 99.6%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval99.6
Applied rewrites99.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites40.4%
Taylor expanded in b around 0
Applied rewrites69.4%
Final simplification61.6%
(FPCore (a b angle) :precision binary64 (if (<= a 2.1e+63) (* b b) (* (* (* (* (* angle angle) a) a) 3.08641975308642e-5) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.1 \cdot 10^{+63}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(angle \cdot angle\right) \cdot a\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 < 2.1000000000000002e63Initial program 75.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6459.0
Applied rewrites59.0%
if 2.1000000000000002e63 < a Initial program 91.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6491.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6491.8
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval91.7
Applied rewrites91.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites41.8%
Taylor expanded in b around 0
Applied rewrites64.9%
Final simplification60.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 78.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6453.4
Applied rewrites53.4%
herbie shell --seed 2024267
(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)))