
(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 (* (/ angle 180.0) (PI))) b) 2.0) (* a a)))
\begin{array}{l}
\\
{\left(\sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2} + a \cdot a
\end{array}
Initial program 80.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6480.8
Applied rewrites80.8%
Final simplification80.8%
(FPCore (a b angle) :precision binary64 (+ (pow (* (sin (* (* 0.005555555555555556 angle) (PI))) b) 2.0) (* a a)))
\begin{array}{l}
\\
{\left(\sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2} + a \cdot a
\end{array}
Initial program 80.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6480.8
Applied rewrites80.8%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6480.8
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f6480.7
Applied rewrites80.7%
(FPCore (a b angle) :precision binary64 (+ (pow (* (sin (* (* 0.005555555555555556 (PI)) angle)) b) 2.0) (* a a)))
\begin{array}{l}
\\
{\left(\sin \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot b\right)}^{2} + a \cdot a
\end{array}
Initial program 80.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6480.8
Applied rewrites80.8%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
lower-sin.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6480.7
Applied rewrites80.7%
Final simplification80.7%
(FPCore (a b angle)
:precision binary64
(if (<= b 2.35e-63)
(* a a)
(+
(pow
(*
(*
(*
(fma
(* (* angle angle) -2.8577960676726107e-8)
(* (PI) (PI))
0.005555555555555556)
(PI))
angle)
b)
2.0)
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.35 \cdot 10^{-63}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\left(\mathsf{fma}\left(\left(angle \cdot angle\right) \cdot -2.8577960676726107 \cdot 10^{-8}, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 0.005555555555555556\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot b\right)}^{2} + a \cdot a\\
\end{array}
\end{array}
if b < 2.35e-63Initial program 77.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.1
Applied rewrites62.1%
if 2.35e-63 < b Initial program 85.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6485.7
Applied rewrites85.7%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6485.7
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f6485.6
Applied rewrites85.6%
Taylor expanded in angle around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites83.0%
Final simplification69.0%
(FPCore (a b angle)
:precision binary64
(if (<= b 2.35e-63)
(* a a)
(+
(* (* 3.08641975308642e-5 (pow (* b angle) 2.0)) (* (PI) (PI)))
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.35 \cdot 10^{-63}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot {\left(b \cdot angle\right)}^{2}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) + a \cdot a\\
\end{array}
\end{array}
if b < 2.35e-63Initial program 77.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.1
Applied rewrites62.1%
if 2.35e-63 < b Initial program 85.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6485.7
Applied rewrites85.7%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
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.f6472.3
Applied rewrites72.3%
Applied rewrites73.4%
Applied rewrites83.3%
Final simplification69.1%
(FPCore (a b angle) :precision binary64 (if (<= b 2.35e-63) (* a a) (+ (* (pow (* (* (PI) b) angle) 2.0) 3.08641975308642e-5) (* a a))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.35 \cdot 10^{-63}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\mathsf{PI}\left(\right) \cdot b\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5} + a \cdot a\\
\end{array}
\end{array}
if b < 2.35e-63Initial program 77.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.1
Applied rewrites62.1%
if 2.35e-63 < b Initial program 85.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6485.7
Applied rewrites85.7%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
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.f6472.3
Applied rewrites72.3%
Applied rewrites73.4%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6473.4
Applied rewrites83.3%
(FPCore (a b angle) :precision binary64 (if (<= b 2.35e-63) (* a a) (+ (pow (* (* (* (PI) b) 0.005555555555555556) angle) 2.0) (* a a))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.35 \cdot 10^{-63}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\left(\mathsf{PI}\left(\right) \cdot b\right) \cdot 0.005555555555555556\right) \cdot angle\right)}^{2} + a \cdot a\\
\end{array}
\end{array}
if b < 2.35e-63Initial program 77.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.1
Applied rewrites62.1%
if 2.35e-63 < b Initial program 85.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6485.7
Applied rewrites85.7%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6483.2
Applied rewrites83.2%
Final simplification69.1%
(FPCore (a b angle)
:precision binary64
(if (<= b 2.35e-63)
(* a a)
(fma
(* (* (* 3.08641975308642e-5 (* angle angle)) b) (* (PI) (PI)))
b
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.35 \cdot 10^{-63}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(angle \cdot angle\right)\right) \cdot b\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), b, a \cdot a\right)\\
\end{array}
\end{array}
if b < 2.35e-63Initial program 77.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.1
Applied rewrites62.1%
if 2.35e-63 < b Initial program 85.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6485.7
Applied rewrites85.7%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6485.7
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f6485.6
Applied rewrites85.6%
lift-+.f64N/A
Applied rewrites83.9%
Taylor expanded in angle around 0
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f6477.1
Applied rewrites77.1%
Final simplification67.1%
(FPCore (a b angle) :precision binary64 (+ (* (* (* (* (* b b) 3.08641975308642e-5) angle) angle) (* (PI) (PI))) (* a a)))
\begin{array}{l}
\\
\left(\left(\left(\left(b \cdot b\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) + a \cdot a
\end{array}
Initial program 80.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6480.8
Applied rewrites80.8%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
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.f6467.8
Applied rewrites67.8%
Applied rewrites68.1%
Applied rewrites74.8%
Final simplification74.8%
(FPCore (a b angle) :precision binary64 (+ (* (* (* (* b b) angle) (* 3.08641975308642e-5 angle)) (* (PI) (PI))) (* a a)))
\begin{array}{l}
\\
\left(\left(\left(b \cdot b\right) \cdot angle\right) \cdot \left(3.08641975308642 \cdot 10^{-5} \cdot angle\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) + a \cdot a
\end{array}
Initial program 80.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6480.8
Applied rewrites80.8%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
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.f6467.8
Applied rewrites67.8%
Applied rewrites68.1%
Applied rewrites74.8%
Final simplification74.8%
(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.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6457.6
Applied rewrites57.6%
herbie shell --seed 2024271
(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)))