
(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 (+ (pow (* (sin (* (* 0.005555555555555556 (PI)) angle)) b) 2.0) (pow (* (cos (* (/ angle 180.0) (PI))) a) 2.0)))
\begin{array}{l}
\\
{\left(\sin \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot b\right)}^{2} + {\left(\cos \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot a\right)}^{2}
\end{array}
Initial program 80.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-eval80.4
Applied rewrites80.4%
Final simplification80.4%
(FPCore (a b angle) :precision binary64 (+ (pow (* (cos (* (* 0.005555555555555556 angle) (PI))) a) 2.0) (pow (* (sin (* (* 0.005555555555555556 (PI)) angle)) b) 2.0)))
\begin{array}{l}
\\
{\left(\cos \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot a\right)}^{2} + {\left(\sin \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot b\right)}^{2}
\end{array}
Initial program 80.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-eval80.4
Applied rewrites80.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6480.4
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f6480.4
Applied rewrites80.4%
Final simplification80.4%
(FPCore (a b angle) :precision binary64 (+ (* a a) (pow (* (sin (* (* 0.005555555555555556 (PI)) angle)) b) 2.0)))
\begin{array}{l}
\\
a \cdot a + {\left(\sin \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot b\right)}^{2}
\end{array}
Initial program 80.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-eval80.4
Applied rewrites80.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6480.3
Applied rewrites80.3%
Final simplification80.3%
(FPCore (a b angle) :precision binary64 (if (<= b 4.2e-84) (* a a) (+ (pow (* (* (* 0.005555555555555556 (PI)) angle) b) 2.0) (* a a))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.2 \cdot 10^{-84}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot b\right)}^{2} + a \cdot a\\
\end{array}
\end{array}
if b < 4.19999999999999996e-84Initial program 79.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.8
Applied rewrites60.8%
if 4.19999999999999996e-84 < b Initial program 81.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-eval81.7
Applied rewrites81.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6481.7
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f6481.7
Applied rewrites81.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6482.3
Applied rewrites82.3%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6477.3
Applied rewrites77.3%
Final simplification66.4%
(FPCore (a b angle)
:precision binary64
(if (<= b 4.2e-84)
(* a a)
(if (<= b 3.3e+153)
(fma
(* (* (* (* b b) 3.08641975308642e-5) (PI)) (PI))
(* angle angle)
(* a a))
(* (pow (* (* b (PI)) angle) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.2 \cdot 10^{-84}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{+153}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(b \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 4.19999999999999996e-84Initial program 79.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.8
Applied rewrites60.8%
if 4.19999999999999996e-84 < b < 3.29999999999999994e153Initial program 71.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-eval72.1
Applied rewrites72.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites39.8%
Taylor expanded in b around inf
Applied rewrites63.0%
if 3.29999999999999994e153 < b Initial program 95.0%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval95.0
Applied rewrites95.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites34.7%
Taylor expanded in b around inf
Applied rewrites56.9%
Applied rewrites73.6%
Final simplification63.1%
(FPCore (a b angle)
:precision binary64
(if (<= a 8.8e+136)
(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 8.8 \cdot 10^{+136}:\\
\;\;\;\;\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 < 8.7999999999999998e136Initial 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.5
Applied rewrites77.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.0%
Applied rewrites49.0%
if 8.7999999999999998e136 < a Initial program 95.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6494.0
Applied rewrites94.0%
Final simplification56.0%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.35e+137)
(+
(* (* (* (* (PI) (PI)) b) b) (* (* angle angle) 3.08641975308642e-5))
(* a a))
(* a a)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.35 \cdot 10^{+137}:\\
\;\;\;\;\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) + a \cdot a\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.35000000000000009e137Initial 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.5
Applied rewrites77.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6477.5
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f6477.5
Applied rewrites77.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6477.7
Applied rewrites77.7%
Taylor expanded in angle around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f6460.9
Applied rewrites60.9%
if 1.35000000000000009e137 < a Initial program 95.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6494.0
Applied rewrites94.0%
Final simplification66.1%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.35e+137)
(fma
(* (* (* (* b b) 3.08641975308642e-5) (PI)) (PI))
(* angle angle)
(* a a))
(* a a)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.35 \cdot 10^{+137}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\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 a < 1.35000000000000009e137Initial 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.5
Applied rewrites77.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.0%
Taylor expanded in b around inf
Applied rewrites60.9%
if 1.35000000000000009e137 < a Initial program 95.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6494.0
Applied rewrites94.0%
Final simplification66.1%
(FPCore (a b angle) :precision binary64 (if (<= b 3.3e+153) (* a a) (* (* (* (* angle angle) 3.08641975308642e-5) b) (* (* (PI) (PI)) b))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.3 \cdot 10^{+153}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)\\
\end{array}
\end{array}
if b < 3.29999999999999994e153Initial program 77.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.1
Applied rewrites60.1%
if 3.29999999999999994e153 < b Initial program 95.0%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval95.0
Applied rewrites95.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites34.7%
Taylor expanded in b around inf
Applied rewrites56.9%
Applied rewrites57.6%
(FPCore (a b angle) :precision binary64 (if (<= b 1.9e+170) (* a a) (* (* (* (* (PI) (PI)) b) b) (* (* angle angle) 3.08641975308642e-5))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.9 \cdot 10^{+170}:\\
\;\;\;\;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 < 1.8999999999999999e170Initial program 77.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.5
Applied rewrites60.5%
if 1.8999999999999999e170 < 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.7
Applied rewrites99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites38.6%
Taylor expanded in b around inf
Applied rewrites66.2%
Final simplification61.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 80.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6457.0
Applied rewrites57.0%
herbie shell --seed 2024284
(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)))