
(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 12 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) (pow (* (cos (* (/ (PI) (pow angle -1.0)) 0.005555555555555556)) a) 2.0)))
\begin{array}{l}
\\
{\left(\sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2} + {\left(\cos \left(\frac{\mathsf{PI}\left(\right)}{{angle}^{-1}} \cdot 0.005555555555555556\right) \cdot a\right)}^{2}
\end{array}
Initial program 82.2%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
*-commutativeN/A
div-invN/A
times-fracN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
inv-powN/A
lower-pow.f6482.3
Applied rewrites82.3%
Final simplification82.3%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (sqrt (PI))))
(+
(pow (* (cos (* (* (* t_0 angle) t_0) 0.005555555555555556)) a) 2.0)
(pow (* (sin (* (/ angle 180.0) (PI))) b) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(\cos \left(\left(\left(t\_0 \cdot angle\right) \cdot t\_0\right) \cdot 0.005555555555555556\right) \cdot a\right)}^{2} + {\left(\sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}
\end{array}
\end{array}
Initial program 82.2%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
*-commutativeN/A
div-invN/A
times-fracN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
inv-powN/A
lower-pow.f6482.3
Applied rewrites82.3%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lift-pow.f64N/A
unpow-1N/A
remove-double-divN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6482.3
Applied rewrites82.3%
Final simplification82.3%
(FPCore (a b angle) :precision binary64 (+ (pow (* (cos (* (* angle (PI)) 0.005555555555555556)) a) 2.0) (pow (* (sin (* (/ angle 180.0) (PI))) b) 2.0)))
\begin{array}{l}
\\
{\left(\cos \left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot 0.005555555555555556\right) \cdot a\right)}^{2} + {\left(\sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}
\end{array}
Initial program 82.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
div-invN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
metadata-eval82.3
Applied rewrites82.3%
Final simplification82.3%
(FPCore (a b angle) :precision binary64 (fma (* (pow (cos (* -0.005555555555555556 (* angle (PI)))) 2.0) a) a (pow (* (sin (* (* angle 0.005555555555555556) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left({\cos \left(-0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} \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.2%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
*-commutativeN/A
div-invN/A
times-fracN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
inv-powN/A
lower-pow.f6482.3
Applied rewrites82.3%
Applied rewrites82.3%
Final simplification82.3%
(FPCore (a b angle) :precision binary64 (+ (* a a) (pow (* (sin (* (/ angle 180.0) (PI))) b) 2.0)))
\begin{array}{l}
\\
a \cdot a + {\left(\sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}
\end{array}
Initial program 82.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6482.1
Applied rewrites82.1%
Final simplification82.1%
(FPCore (a b angle)
:precision binary64
(if (<= b 3.5e-138)
(* (* a a) (pow (cos (* -0.005555555555555556 (* angle (PI)))) 2.0))
(if (<= b 8.4e+126)
(fma
(* (* (* b b) 3.08641975308642e-5) (* (PI) (PI)))
(* angle angle)
(* a a))
(* (* (* (pow (* b angle) 2.0) 3.08641975308642e-5) (PI)) (PI)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.5 \cdot 10^{-138}:\\
\;\;\;\;\left(a \cdot a\right) \cdot {\cos \left(-0.005555555555555556 \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}\\
\mathbf{elif}\;b \leq 8.4 \cdot 10^{+126}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left({\left(b \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\\
\end{array}
\end{array}
if b < 3.4999999999999999e-138Initial program 82.7%
lift-+.f64N/A
+-commutativeN/A
Applied rewrites49.9%
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-*.f6463.6
Applied rewrites63.6%
if 3.4999999999999999e-138 < b < 8.3999999999999997e126Initial program 74.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites25.9%
Taylor expanded in b around inf
Applied rewrites69.6%
if 8.3999999999999997e126 < b Initial program 92.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites29.2%
Taylor expanded in b around inf
Applied rewrites52.0%
Applied rewrites73.7%
Final simplification66.3%
(FPCore (a b angle)
:precision binary64
(if (<= b 4.5e-138)
(* a a)
(if (<= b 8.4e+126)
(fma
(* (* (* b b) 3.08641975308642e-5) (* (PI) (PI)))
(* angle angle)
(* a a))
(* (* (* (pow (* b angle) 2.0) 3.08641975308642e-5) (PI)) (PI)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.5 \cdot 10^{-138}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 8.4 \cdot 10^{+126}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left({\left(b \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\\
\end{array}
\end{array}
if b < 4.50000000000000008e-138Initial program 82.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.3
Applied rewrites63.3%
if 4.50000000000000008e-138 < b < 8.3999999999999997e126Initial program 74.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites25.9%
Taylor expanded in b around inf
Applied rewrites69.6%
if 8.3999999999999997e126 < b Initial program 92.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites29.2%
Taylor expanded in b around inf
Applied rewrites52.0%
Applied rewrites73.7%
Final simplification66.2%
(FPCore (a b angle)
:precision binary64
(if (<= b 4.5e-138)
(* a a)
(if (<= b 8.4e+126)
(fma
(* (* (* b b) 3.08641975308642e-5) (* (PI) (PI)))
(* angle angle)
(* a a))
(* (pow (* (* b angle) (PI)) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.5 \cdot 10^{-138}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 8.4 \cdot 10^{+126}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(b \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 4.50000000000000008e-138Initial program 82.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.3
Applied rewrites63.3%
if 4.50000000000000008e-138 < b < 8.3999999999999997e126Initial program 74.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites25.9%
Taylor expanded in b around inf
Applied rewrites69.6%
if 8.3999999999999997e126 < b Initial program 92.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites29.2%
Taylor expanded in b around inf
Applied rewrites52.0%
Applied rewrites73.5%
Final simplification66.1%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) (PI))))
(if (<= b 4.5e-138)
(* a a)
(if (<= b 8.4e+126)
(fma (* (* (* b b) 3.08641975308642e-5) t_0) (* angle angle) (* a a))
(* (* (* (* (* b angle) angle) b) 3.08641975308642e-5) t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;b \leq 4.5 \cdot 10^{-138}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 8.4 \cdot 10^{+126}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot t\_0, angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(b \cdot angle\right) \cdot angle\right) \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot t\_0\\
\end{array}
\end{array}
if b < 4.50000000000000008e-138Initial program 82.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.3
Applied rewrites63.3%
if 4.50000000000000008e-138 < b < 8.3999999999999997e126Initial program 74.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites25.9%
Taylor expanded in b around inf
Applied rewrites69.6%
if 8.3999999999999997e126 < b Initial program 92.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites29.2%
Taylor expanded in b around inf
Applied rewrites52.0%
Applied rewrites68.2%
Final simplification65.4%
(FPCore (a b angle) :precision binary64 (if (<= b 7.4e+126) (* a a) (* (* (* (* (* b angle) angle) b) 3.08641975308642e-5) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.4 \cdot 10^{+126}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(b \cdot angle\right) \cdot angle\right) \cdot b\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 b < 7.3999999999999996e126Initial program 80.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.3
Applied rewrites63.3%
if 7.3999999999999996e126 < b Initial program 92.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites29.2%
Taylor expanded in b around inf
Applied rewrites52.0%
Applied rewrites68.2%
Final simplification64.0%
(FPCore (a b angle) :precision binary64 (if (<= b 2.45e+128) (* a a) (* (* (* (* (* angle angle) b) b) 3.08641975308642e-5) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.45 \cdot 10^{+128}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(angle \cdot angle\right) \cdot b\right) \cdot b\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 b < 2.45000000000000009e128Initial program 80.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.0
Applied rewrites63.0%
if 2.45000000000000009e128 < b Initial program 92.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites29.9%
Taylor expanded in b around inf
Applied rewrites53.3%
Final simplification61.7%
(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.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6459.4
Applied rewrites59.4%
herbie shell --seed 2024249
(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)))