
(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 10 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))))
(fma
(* (pow (cos (/ (* angle (* t_0 t_0)) -180.0)) 2.0) a)
a
(pow (* (sin (* (* 0.005555555555555556 angle) (PI))) b) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
\mathsf{fma}\left({\cos \left(\frac{angle \cdot \left(t\_0 \cdot t\_0\right)}{-180}\right)}^{2} \cdot a, a, {\left(\sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}\right)
\end{array}
\end{array}
Initial program 81.9%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites81.9%
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.f6482.0
Applied rewrites82.0%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (sqrt (PI))))
(+
(pow (* a (cos (* (* (* t_0 angle) t_0) -0.005555555555555556))) 2.0)
(pow (* b (sin (* (PI) (* angle 0.005555555555555556)))) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(a \cdot \cos \left(\left(\left(t\_0 \cdot angle\right) \cdot t\_0\right) \cdot -0.005555555555555556\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2}
\end{array}
\end{array}
Initial program 81.9%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
clear-numN/A
inv-powN/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6437.8
Applied rewrites37.8%
lift-*.f64N/A
*-commutativeN/A
mul-1-negN/A
lift-log.f64N/A
neg-logN/A
lift-/.f64N/A
lift-/.f64N/A
associate-/r*N/A
lift-*.f64N/A
clear-numN/A
log-divN/A
lower--.f64N/A
lower-log.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-log.f6437.8
Applied rewrites37.8%
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6437.8
Applied rewrites37.8%
lift-exp.f64N/A
lift--.f64N/A
exp-diffN/A
lift-log.f64N/A
rem-exp-logN/A
lift-*.f64N/A
lift-log.f64N/A
rem-exp-logN/A
*-commutativeN/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
associate-*r*N/A
lift-*.f64N/A
rem-exp-logN/A
lift-log.f64N/A
lift-exp.f64N/A
associate-*r/N/A
Applied rewrites81.9%
Final simplification81.9%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (* 0.005555555555555556 angle) (PI)))) (fma (* (pow (cos t_0) 2.0) a) a (pow (* (sin t_0) b) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\\
\mathsf{fma}\left({\cos t\_0}^{2} \cdot a, a, {\left(\sin t\_0 \cdot b\right)}^{2}\right)
\end{array}
\end{array}
Initial program 81.9%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites81.9%
Applied rewrites81.9%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (* 0.005555555555555556 angle) (PI)))) (+ (pow (* (sin t_0) b) 2.0) (pow (* (cos t_0) a) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\\
{\left(\sin t\_0 \cdot b\right)}^{2} + {\left(\cos t\_0 \cdot a\right)}^{2}
\end{array}
\end{array}
Initial program 81.9%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites81.9%
Applied rewrites81.9%
(FPCore (a b angle) :precision binary64 (fma (* (+ 0.5 (* 0.5 (cos (* 2.0 (* -0.005555555555555556 (* (PI) angle)))))) a) a (pow (* (sin (* (* 0.005555555555555556 angle) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(-0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\right)\right)\right)\right) \cdot a, a, {\left(\sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 81.9%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites81.9%
Applied rewrites81.9%
(FPCore (a b angle) :precision binary64 (fma (* 1.0 a) a (pow (* (sin (* (* 0.005555555555555556 angle) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(1 \cdot a, a, {\left(\sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 81.9%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites81.9%
Taylor expanded in angle around 0
Applied rewrites81.7%
(FPCore (a b angle) :precision binary64 (if (<= b 1.9e+70) (* a a) (* (* 3.08641975308642e-5 (* (* b angle) (* b angle))) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.9 \cdot 10^{+70}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(\left(b \cdot angle\right) \cdot \left(b \cdot angle\right)\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if b < 1.8999999999999999e70Initial program 78.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.4
Applied rewrites60.4%
if 1.8999999999999999e70 < b Initial program 94.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites50.5%
Taylor expanded in a around 0
Applied rewrites63.7%
Applied rewrites73.8%
(FPCore (a b angle) :precision binary64 (if (<= b 1.9e+70) (* a a) (* (* 3.08641975308642e-5 (* angle (* (* b angle) b))) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.9 \cdot 10^{+70}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(angle \cdot \left(\left(b \cdot angle\right) \cdot b\right)\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if b < 1.8999999999999999e70Initial program 78.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.4
Applied rewrites60.4%
if 1.8999999999999999e70 < b Initial program 94.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites50.5%
Taylor expanded in a around 0
Applied rewrites63.7%
Applied rewrites70.9%
(FPCore (a b angle) :precision binary64 (if (<= b 6.5e+125) (* a a) (* (* (* (* (* angle angle) 3.08641975308642e-5) b) b) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.5 \cdot 10^{+125}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right) \cdot b\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if b < 6.4999999999999999e125Initial program 78.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.1
Applied rewrites60.1%
if 6.4999999999999999e125 < b Initial program 96.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites54.3%
Taylor expanded in a around 0
Applied rewrites74.5%
Taylor expanded in b around 0
Applied rewrites74.5%
(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 81.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6455.4
Applied rewrites55.4%
herbie shell --seed 2024313
(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)))