
(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 10 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 (* (* 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 78.6%
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-eval78.8
Applied rewrites78.8%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6478.8
Applied rewrites78.8%
Taylor expanded in angle around 0
Applied rewrites78.9%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (* (PI) angle) 0.005555555555555556))) 2.0) (pow (* b 1.0) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right)\right)}^{2} + {\left(b \cdot 1\right)}^{2}
\end{array}
Initial program 78.6%
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-eval78.8
Applied rewrites78.8%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6478.8
Applied rewrites78.8%
Taylor expanded in angle around 0
Applied rewrites78.9%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-sin.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6478.8
Applied rewrites78.8%
(FPCore (a b angle)
:precision binary64
(if (<= a 3.4e+46)
(* b b)
(+
(pow (* a (* (* (PI) angle) 0.005555555555555556)) 2.0)
(pow (* b 1.0) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3.4 \cdot 10^{+46}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(a \cdot \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right)\right)}^{2} + {\left(b \cdot 1\right)}^{2}\\
\end{array}
\end{array}
if a < 3.3999999999999998e46Initial program 76.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.6
Applied rewrites60.6%
if 3.3999999999999998e46 < a Initial program 87.6%
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-eval87.8
Applied rewrites87.8%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6487.8
Applied rewrites87.8%
Taylor expanded in angle around 0
Applied rewrites87.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6486.2
Applied rewrites86.2%
(FPCore (a b angle) :precision binary64 (fma (* 1.0 b) b (pow (* (sin (* (PI) (* 0.005555555555555556 angle))) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(1 \cdot b, b, {\left(\sin \left(\mathsf{PI}\left(\right) \cdot \left(0.005555555555555556 \cdot angle\right)\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 78.6%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites78.7%
Taylor expanded in angle around 0
Applied rewrites78.8%
(FPCore (a b angle) :precision binary64 (if (<= a 1.25e+129) (* b b) (* (* (* (PI) (PI)) (pow (* angle a) 2.0)) 3.08641975308642e-5)))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.25 \cdot 10^{+129}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot {\left(angle \cdot a\right)}^{2}\right) \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if a < 1.2500000000000001e129Initial program 75.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.1
Applied rewrites60.1%
if 1.2500000000000001e129 < a Initial program 91.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites37.5%
Taylor expanded in a around inf
Applied rewrites62.9%
Applied rewrites78.1%
(FPCore (a b angle) :precision binary64 (if (<= a 1.25e+129) (* b b) (* (* (* (* 3.08641975308642e-5 a) angle) (* angle a)) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.25 \cdot 10^{+129}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot angle\right) \cdot \left(angle \cdot a\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 1.2500000000000001e129Initial program 75.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.1
Applied rewrites60.1%
if 1.2500000000000001e129 < a Initial program 91.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites37.5%
Taylor expanded in a around inf
Applied rewrites62.9%
Applied rewrites78.0%
(FPCore (a b angle) :precision binary64 (if (<= a 1.25e+129) (* b b) (* (* 3.08641975308642e-5 (* (* angle a) (* angle a))) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.25 \cdot 10^{+129}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(\left(angle \cdot a\right) \cdot \left(angle \cdot a\right)\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 1.2500000000000001e129Initial program 75.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.1
Applied rewrites60.1%
if 1.2500000000000001e129 < a Initial program 91.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites37.5%
Taylor expanded in a around inf
Applied rewrites62.9%
Applied rewrites78.0%
(FPCore (a b angle) :precision binary64 (if (<= a 1.25e+129) (* b b) (* (* 3.08641975308642e-5 (* a (* (* angle a) angle))) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.25 \cdot 10^{+129}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot \left(\left(angle \cdot a\right) \cdot angle\right)\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 1.2500000000000001e129Initial program 75.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.1
Applied rewrites60.1%
if 1.2500000000000001e129 < a Initial program 91.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites37.5%
Taylor expanded in a around inf
Applied rewrites62.9%
Applied rewrites74.3%
(FPCore (a b angle) :precision binary64 (if (<= a 1.32e+129) (* b b) (* (* 3.08641975308642e-5 a) (* (* (* angle angle) a) (* (PI) (PI))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.32 \cdot 10^{+129}:\\
\;\;\;\;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 < 1.32e129Initial program 75.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.1
Applied rewrites60.1%
if 1.32e129 < a Initial program 91.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites37.5%
Taylor expanded in a around inf
Applied rewrites62.9%
Applied rewrites62.9%
(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.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6456.2
Applied rewrites56.2%
herbie shell --seed 2024303
(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)))