
(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 (+ (pow (* (sin (* (/ 0.005555555555555556 (/ -1.0 angle)) (/ (PI) -1.0))) b) 2.0) (pow (* (cos (* (- 0.005555555555555556) (/ (PI) (/ -1.0 angle)))) a) 2.0)))
\begin{array}{l}
\\
{\left(\sin \left(\frac{0.005555555555555556}{\frac{-1}{angle}} \cdot \frac{\mathsf{PI}\left(\right)}{-1}\right) \cdot b\right)}^{2} + {\left(\cos \left(\left(-0.005555555555555556\right) \cdot \frac{\mathsf{PI}\left(\right)}{\frac{-1}{angle}}\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%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lower-neg.f64N/A
lift-pow.f64N/A
unpow-1N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6482.3
Applied rewrites82.3%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
remove-double-negN/A
lift-neg.f64N/A
neg-mul-1N/A
div-invN/A
times-fracN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
div-invN/A
lift-/.f64N/A
associate-*r/N/A
metadata-evalN/A
times-fracN/A
*-commutativeN/A
times-fracN/A
lift-neg.f64N/A
metadata-evalN/A
frac-2negN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6482.4
Applied rewrites82.4%
Final simplification82.4%
(FPCore (a b angle) :precision binary64 (+ (pow (* (sin (* (/ angle 180.0) (PI))) b) 2.0) (pow (* (cos (* (- 0.005555555555555556) (/ (PI) (/ -1.0 angle)))) 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(\left(-0.005555555555555556\right) \cdot \frac{\mathsf{PI}\left(\right)}{\frac{-1}{angle}}\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%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lower-neg.f64N/A
lift-pow.f64N/A
unpow-1N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6482.3
Applied rewrites82.3%
Final simplification82.3%
(FPCore (a b angle) :precision binary64 (+ (pow (* (sin (* (* (PI) 0.005555555555555556) angle)) b) 2.0) (pow (* (cos (* (- 0.005555555555555556) (/ (PI) (/ -1.0 angle)))) a) 2.0)))
\begin{array}{l}
\\
{\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right) \cdot b\right)}^{2} + {\left(\cos \left(\left(-0.005555555555555556\right) \cdot \frac{\mathsf{PI}\left(\right)}{\frac{-1}{angle}}\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%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lower-neg.f64N/A
lift-pow.f64N/A
unpow-1N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6482.3
Applied rewrites82.3%
lift-*.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.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 (+ (pow (* 1.0 a) 2.0) (pow (* (sin (* (/ 0.005555555555555556 (/ -1.0 angle)) (/ (PI) -1.0))) b) 2.0)))
\begin{array}{l}
\\
{\left(1 \cdot a\right)}^{2} + {\left(\sin \left(\frac{0.005555555555555556}{\frac{-1}{angle}} \cdot \frac{\mathsf{PI}\left(\right)}{-1}\right) \cdot b\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%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lower-neg.f64N/A
lift-pow.f64N/A
unpow-1N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6482.3
Applied rewrites82.3%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
remove-double-negN/A
lift-neg.f64N/A
neg-mul-1N/A
div-invN/A
times-fracN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
div-invN/A
lift-/.f64N/A
associate-*r/N/A
metadata-evalN/A
times-fracN/A
*-commutativeN/A
times-fracN/A
lift-neg.f64N/A
metadata-evalN/A
frac-2negN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6482.4
Applied rewrites82.4%
Taylor expanded in angle around 0
Applied rewrites82.1%
Final simplification82.1%
(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.2%
lift-pow.f64N/A
unpow1N/A
pow-to-expN/A
pow-expN/A
*-commutativeN/A
pow-expN/A
lower-pow.f64N/A
lower-exp.f64N/A
rem-log-expN/A
pow-to-expN/A
unpow1N/A
lower-log.f6446.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6446.2
Applied rewrites47.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6447.4
Applied rewrites47.4%
lift-+.f64N/A
+-commutativeN/A
Applied rewrites82.1%
Final simplification82.1%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) 0.005555555555555556)) (t_1 (* t_0 angle)))
(if (<= a 6e-168)
(pow (* (sin t_1) b) 2.0)
(fma t_1 (* (* (* b b) angle) t_0) (* a a)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot 0.005555555555555556\\
t_1 := t\_0 \cdot angle\\
\mathbf{if}\;a \leq 6 \cdot 10^{-168}:\\
\;\;\;\;{\left(\sin t\_1 \cdot b\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_1, \left(\left(b \cdot b\right) \cdot angle\right) \cdot t\_0, a \cdot a\right)\\
\end{array}
\end{array}
if a < 5.99999999999999983e-168Initial program 79.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites36.8%
Taylor expanded in b around inf
exp-to-powN/A
*-commutativeN/A
exp-to-powN/A
*-commutativeN/A
exp-sumN/A
distribute-lft-inN/A
*-commutativeN/A
exp-prodN/A
exp-sumN/A
rem-exp-logN/A
rem-exp-logN/A
lower-pow.f64N/A
Applied rewrites41.5%
if 5.99999999999999983e-168 < a Initial program 86.7%
lift-+.f64N/A
+-commutativeN/A
Applied rewrites58.1%
lift-log.f64N/A
lift-*.f64N/A
log-prodN/A
lift-*.f64N/A
pow2N/A
pow-to-expN/A
rem-log-expN/A
lower-fma.f64N/A
lower-log.f64N/A
lower-log.f6427.6
Applied rewrites27.6%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites79.3%
Final simplification55.3%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) 0.005555555555555556)))
(if (<= b 8.4e+126)
(fma (* t_0 angle) (* (* (* b b) angle) t_0) (* a a))
(* (pow (* (* b (PI)) angle) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot 0.005555555555555556\\
\mathbf{if}\;b \leq 8.4 \cdot 10^{+126}:\\
\;\;\;\;\mathsf{fma}\left(t\_0 \cdot angle, \left(\left(b \cdot b\right) \cdot angle\right) \cdot t\_0, 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 < 8.3999999999999997e126Initial program 80.5%
lift-+.f64N/A
+-commutativeN/A
Applied rewrites56.0%
lift-log.f64N/A
lift-*.f64N/A
log-prodN/A
lift-*.f64N/A
pow2N/A
pow-to-expN/A
rem-log-expN/A
lower-fma.f64N/A
lower-log.f64N/A
lower-log.f6418.1
Applied rewrites18.1%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites75.2%
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 rewrites45.9%
Applied rewrites73.5%
Final simplification75.0%
(FPCore (a b angle)
:precision binary64
(if (<= (/ angle 180.0) 5e-167)
(* a a)
(if (<= (/ angle 180.0) 4e+198)
(fma
(* (* (* (* (PI) (PI)) 3.08641975308642e-5) b) b)
(* angle angle)
(* a a))
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{angle}{180} \leq 5 \cdot 10^{-167}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;\frac{angle}{180} \leq 4 \cdot 10^{+198}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right) \cdot b, angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if (/.f64 angle #s(literal 180 binary64)) < 5.0000000000000002e-167 or 4.00000000000000007e198 < (/.f64 angle #s(literal 180 binary64)) Initial program 83.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6464.5
Applied rewrites64.5%
if 5.0000000000000002e-167 < (/.f64 angle #s(literal 180 binary64)) < 4.00000000000000007e198Initial program 79.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites42.3%
Taylor expanded in b around inf
Applied rewrites71.9%
Final simplification66.7%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (PI) 0.005555555555555556))) (fma (* t_0 angle) (* (* (* b b) angle) t_0) (* a a))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot 0.005555555555555556\\
\mathsf{fma}\left(t\_0 \cdot angle, \left(\left(b \cdot b\right) \cdot angle\right) \cdot t\_0, a \cdot a\right)
\end{array}
\end{array}
Initial program 82.2%
lift-+.f64N/A
+-commutativeN/A
Applied rewrites52.6%
lift-log.f64N/A
lift-*.f64N/A
log-prodN/A
lift-*.f64N/A
pow2N/A
pow-to-expN/A
rem-log-expN/A
lower-fma.f64N/A
lower-log.f64N/A
lower-log.f6421.7
Applied rewrites21.7%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites72.8%
Final simplification72.8%
(FPCore (a b angle) :precision binary64 (if (<= b 1.8e+128) (* a a) (* (* (* (PI) (PI)) b) (* (* (* angle angle) 3.08641975308642e-5) b))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.8 \cdot 10^{+128}:\\
\;\;\;\;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 < 1.80000000000000014e128Initial program 80.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.0
Applied rewrites63.0%
if 1.80000000000000014e128 < 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 rewrites47.1%
Applied rewrites53.4%
Final simplification61.7%
(FPCore (a b angle) :precision binary64 (if (<= b 5.5e+187) (* a a) (* (* (* (* (PI) (PI)) b) b) (* (* angle angle) 3.08641975308642e-5))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.5 \cdot 10^{+187}:\\
\;\;\;\;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 < 5.49999999999999997e187Initial program 80.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.5
Applied rewrites61.5%
if 5.49999999999999997e187 < b Initial program 99.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites39.0%
Taylor expanded in b around inf
Applied rewrites58.2%
Final simplification61.2%
(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)))