
(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 14 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
(let* ((t_0 (sqrt (PI))))
(+
(pow (* (sin (* (* (* t_0 t_0) angle) 0.005555555555555556)) b) 2.0)
(pow (* (cos (* angle (* (PI) 0.005555555555555556))) a) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(\sin \left(\left(\left(t\_0 \cdot t\_0\right) \cdot angle\right) \cdot 0.005555555555555556\right) \cdot b\right)}^{2} + {\left(\cos \left(angle \cdot \left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right)\right) \cdot a\right)}^{2}
\end{array}
\end{array}
Initial program 82.9%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval83.0
Applied rewrites83.0%
lift-*.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
lower-*.f6483.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6483.0
Applied rewrites83.0%
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.1
Applied rewrites83.1%
Final simplification83.1%
(FPCore (a b angle) :precision binary64 (+ (pow (* (sin (* (* angle (PI)) 0.005555555555555556)) b) 2.0) (pow (* (cos (* angle (* (PI) 0.005555555555555556))) a) 2.0)))
\begin{array}{l}
\\
{\left(\sin \left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot 0.005555555555555556\right) \cdot b\right)}^{2} + {\left(\cos \left(angle \cdot \left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right)\right) \cdot a\right)}^{2}
\end{array}
Initial program 82.9%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval83.0
Applied rewrites83.0%
lift-*.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
lower-*.f6483.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6483.0
Applied rewrites83.0%
Final simplification83.0%
(FPCore (a b angle) :precision binary64 (fma (* (+ (* (cos (* -0.011111111111111112 (* angle (PI)))) 0.5) 0.5) a) a (pow (* (sin (* (* angle 0.005555555555555556) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\cos \left(-0.011111111111111112 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right) \cdot 0.5 + 0.5\right) \cdot a, a, {\left(\sin \left(\left(angle \cdot 0.005555555555555556\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 82.9%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites82.9%
lift-pow.f64N/A
unpow2N/A
lift-cos.f64N/A
lift-cos.f64N/A
sqr-cos-aN/A
lower-+.f64N/A
lower-*.f64N/A
cos-2N/A
cos-sumN/A
lower-cos.f64N/A
lift-/.f64N/A
div-invN/A
lift-/.f64N/A
div-invN/A
distribute-lft-outN/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
metadata-evalN/A
Applied rewrites82.9%
Final simplification82.9%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (sqrt (PI))))
(+
(* a a)
(pow (* (sin (* (* (* t_0 t_0) angle) 0.005555555555555556)) b) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
a \cdot a + {\left(\sin \left(\left(\left(t\_0 \cdot t\_0\right) \cdot angle\right) \cdot 0.005555555555555556\right) \cdot b\right)}^{2}
\end{array}
\end{array}
Initial program 82.9%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval83.0
Applied rewrites83.0%
lift-*.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
lower-*.f6483.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6483.0
Applied rewrites83.0%
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.1
Applied rewrites83.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6482.3
Applied rewrites82.3%
Final simplification82.3%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.1e+49)
(fma
(*
(* (* (PI) (PI)) angle)
(fma (* 3.08641975308642e-5 b) b (* (* -3.08641975308642e-5 a) a)))
angle
(* a a))
(* (pow (cos (* angle (* (PI) 0.005555555555555556))) 2.0) (* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.1 \cdot 10^{+49}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot \mathsf{fma}\left(3.08641975308642 \cdot 10^{-5} \cdot b, b, \left(-3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot a\right), angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\cos \left(angle \cdot \left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right)\right)}^{2} \cdot \left(a \cdot a\right)\\
\end{array}
\end{array}
if a < 1.1e49Initial program 82.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-eval82.6
Applied rewrites82.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites51.7%
Applied rewrites53.3%
if 1.1e49 < a Initial program 84.8%
Taylor expanded in b around 0
*-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-*.f6481.1
Applied rewrites81.1%
Final simplification59.0%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.1e+49)
(fma
(*
(* (* (PI) (PI)) angle)
(fma (* 3.08641975308642e-5 b) b (* (* -3.08641975308642e-5 a) a)))
angle
(* a a))
(* (pow (cos (* -0.005555555555555556 (* angle (PI)))) 2.0) (* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.1 \cdot 10^{+49}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot \mathsf{fma}\left(3.08641975308642 \cdot 10^{-5} \cdot b, b, \left(-3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot a\right), angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\cos \left(-0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} \cdot \left(a \cdot a\right)\\
\end{array}
\end{array}
if a < 1.1e49Initial program 82.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-eval82.6
Applied rewrites82.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites51.7%
Applied rewrites53.3%
if 1.1e49 < a Initial program 84.8%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites84.7%
Taylor expanded in b around 0
*-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-*.f6481.1
Applied rewrites81.1%
Final simplification59.0%
(FPCore (a b angle) :precision binary64 (+ (* a a) (pow (* (sin (* (* angle (PI)) 0.005555555555555556)) b) 2.0)))
\begin{array}{l}
\\
a \cdot a + {\left(\sin \left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot 0.005555555555555556\right) \cdot b\right)}^{2}
\end{array}
Initial program 82.9%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval83.0
Applied rewrites83.0%
lift-*.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
lower-*.f6483.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6483.0
Applied rewrites83.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6482.3
Applied rewrites82.3%
Final simplification82.3%
(FPCore (a b angle)
:precision binary64
(if (<= b 2.4e-145)
(* a a)
(if (<= b 1.26e+120)
(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 2.4 \cdot 10^{-145}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 1.26 \cdot 10^{+120}:\\
\;\;\;\;\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 < 2.40000000000000015e-145Initial program 82.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6466.6
Applied rewrites66.6%
if 2.40000000000000015e-145 < b < 1.26e120Initial program 73.5%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval73.5
Applied rewrites73.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites45.5%
Taylor expanded in b around inf
Applied rewrites65.1%
if 1.26e120 < b Initial program 94.5%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval94.5
Applied rewrites94.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites68.2%
Taylor expanded in b around inf
Applied rewrites66.3%
Applied rewrites83.4%
Final simplification69.3%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.35e+49)
(fma
(*
(* (* (PI) (PI)) angle)
(fma (* 3.08641975308642e-5 b) b (* (* -3.08641975308642e-5 a) a)))
angle
(* a a))
(* a a)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.35 \cdot 10^{+49}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot \mathsf{fma}\left(3.08641975308642 \cdot 10^{-5} \cdot b, b, \left(-3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot a\right), angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.35000000000000005e49Initial program 82.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-eval82.6
Applied rewrites82.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites51.7%
Applied rewrites53.3%
if 1.35000000000000005e49 < a Initial program 84.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6477.8
Applied rewrites77.8%
Final simplification58.3%
(FPCore (a b angle)
:precision binary64
(if (<= b 2.4e-145)
(* a a)
(fma
(* (* (* (* b b) 3.08641975308642e-5) (PI)) (PI))
(* angle angle)
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.4 \cdot 10^{-145}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\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)\\
\end{array}
\end{array}
if b < 2.40000000000000015e-145Initial program 82.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6466.6
Applied rewrites66.6%
if 2.40000000000000015e-145 < b Initial program 83.8%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval83.8
Applied rewrites83.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites56.6%
Taylor expanded in b around inf
Applied rewrites66.7%
Final simplification66.6%
(FPCore (a b angle) :precision binary64 (if (<= b 7e+108) (* a a) (* (* (* (PI) (PI)) b) (* (* (* angle angle) 3.08641975308642e-5) b))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{+108}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right) \cdot \left(\left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right)\\
\end{array}
\end{array}
if b < 7.0000000000000005e108Initial program 80.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6465.3
Applied rewrites65.3%
if 7.0000000000000005e108 < b Initial program 93.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-eval93.3
Applied rewrites93.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites66.9%
Taylor expanded in b around inf
Applied rewrites65.1%
Applied rewrites67.4%
Final simplification65.7%
(FPCore (a b angle) :precision binary64 (if (<= b 1.2e+112) (* a a) (* (* (* (* angle angle) 3.08641975308642e-5) (* b b)) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.2 \cdot 10^{+112}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(b \cdot b\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if b < 1.2e112Initial program 80.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6465.0
Applied rewrites65.0%
if 1.2e112 < b Initial program 93.2%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval93.2
Applied rewrites93.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites68.2%
Taylor expanded in b around inf
Applied rewrites66.3%
Applied rewrites66.4%
Final simplification65.3%
(FPCore (a b angle) :precision binary64 (if (<= b 1.2e+112) (* a a) (* (* (* (* (PI) (PI)) b) b) (* (* angle angle) 3.08641975308642e-5))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.2 \cdot 10^{+112}:\\
\;\;\;\;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.2e112Initial program 80.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6465.0
Applied rewrites65.0%
if 1.2e112 < b Initial program 93.2%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval93.2
Applied rewrites93.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites68.2%
Taylor expanded in b around inf
Applied rewrites66.3%
Final simplification65.3%
(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 82.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.6
Applied rewrites58.6%
herbie shell --seed 2024255
(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)))