
(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 (let* ((t_0 (* (* 0.005555555555555556 (PI)) angle))) (+ (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 \mathsf{PI}\left(\right)\right) \cdot angle\\
{\left(\sin t\_0 \cdot b\right)}^{2} + {\left(\cos t\_0 \cdot a\right)}^{2}
\end{array}
\end{array}
Initial program 80.3%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
clear-numN/A
lower-/.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6480.4
Applied rewrites80.4%
lift-/.f64N/A
lift-/.f64N/A
clear-numN/A
lift-/.f64N/A
associate-/r/N/A
lower-*.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6480.4
Applied rewrites80.4%
Applied rewrites80.5%
(FPCore (a b angle) :precision binary64 (fma (+ 0.5 (* 0.5 (cos (* 2.0 (* angle (* (PI) 0.005555555555555556)))))) (* a a) (pow (* (sin (* (* 0.005555555555555556 angle) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(angle \cdot \left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right)\right)\right), a \cdot 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 80.3%
lift-+.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
lower-fma.f64N/A
Applied rewrites80.3%
lift-pow.f64N/A
lift-cos.f64N/A
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
distribute-frac-negN/A
div-invN/A
lift-*.f64N/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
cos-negN/A
lift-cos.f64N/A
unpow2N/A
lift-cos.f64N/A
lift-cos.f64N/A
sqr-cos-aN/A
Applied rewrites80.3%
(FPCore (a b angle) :precision binary64 (+ (pow (* a 1.0) 2.0) (pow (* b (sin (* (PI) (/ angle 180.0)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot 1\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}
\end{array}
Initial program 80.3%
Taylor expanded in angle around 0
Applied rewrites80.3%
(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, a \cdot 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 80.3%
lift-+.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
lower-fma.f64N/A
Applied rewrites80.3%
Taylor expanded in angle around 0
Applied rewrites80.2%
(FPCore (a b angle)
:precision binary64
(if (<= b 2e-61)
(* a a)
(if (<= b 9.8e+143)
(fma
(* (* (PI) (PI)) (* 3.08641975308642e-5 (* b b)))
(* angle angle)
(* a a))
(* (pow (* (* b (PI)) angle) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2 \cdot 10^{-61}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 9.8 \cdot 10^{+143}:\\
\;\;\;\;\mathsf{fma}\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(3.08641975308642 \cdot 10^{-5} \cdot \left(b \cdot b\right)\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.0000000000000001e-61Initial program 78.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.8
Applied rewrites62.8%
if 2.0000000000000001e-61 < b < 9.79999999999999971e143Initial program 75.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
clear-numN/A
lower-/.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6475.2
Applied rewrites75.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites50.3%
Taylor expanded in a around 0
Applied rewrites70.6%
if 9.79999999999999971e143 < b Initial program 97.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
clear-numN/A
lower-/.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6497.2
Applied rewrites97.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites58.6%
Taylor expanded in a around 0
Applied rewrites73.7%
Applied rewrites94.5%
Final simplification68.3%
(FPCore (a b angle)
:precision binary64
(if (<= b 2e-61)
(* a a)
(fma
(* (* (PI) (PI)) (* 3.08641975308642e-5 (* b b)))
(* angle angle)
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2 \cdot 10^{-61}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(3.08641975308642 \cdot 10^{-5} \cdot \left(b \cdot b\right)\right), angle \cdot angle, a \cdot a\right)\\
\end{array}
\end{array}
if b < 2.0000000000000001e-61Initial program 78.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.8
Applied rewrites62.8%
if 2.0000000000000001e-61 < b Initial program 84.3%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
clear-numN/A
lower-/.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6484.3
Applied rewrites84.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites53.7%
Taylor expanded in a around 0
Applied rewrites71.9%
Final simplification65.7%
(FPCore (a b angle)
:precision binary64
(if (<= b 2e-61)
(* a a)
(fma
(* (* (* (* (PI) (PI)) 3.08641975308642e-5) b) b)
(* angle angle)
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2 \cdot 10^{-61}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\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)\\
\end{array}
\end{array}
if b < 2.0000000000000001e-61Initial program 78.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.8
Applied rewrites62.8%
if 2.0000000000000001e-61 < b Initial program 84.3%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
clear-numN/A
lower-/.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6484.3
Applied rewrites84.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites53.7%
Taylor expanded in a around 0
Applied rewrites71.8%
Final simplification65.6%
(FPCore (a b angle) :precision binary64 (if (<= b 2.8e+149) (* a a) (* (* (* (* (* angle angle) 3.08641975308642e-5) b) (* (PI) (PI))) b)))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.8 \cdot 10^{+149}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot b\\
\end{array}
\end{array}
if b < 2.7999999999999999e149Initial program 77.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.9
Applied rewrites61.9%
if 2.7999999999999999e149 < b Initial program 97.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
clear-numN/A
lower-/.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6497.2
Applied rewrites97.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites58.6%
Taylor expanded in a around 0
Applied rewrites73.7%
Applied rewrites82.8%
Final simplification64.6%
(FPCore (a b angle) :precision binary64 (if (<= b 2.8e+149) (* a a) (* (* (* (* angle angle) 3.08641975308642e-5) b) (* (* (PI) (PI)) b))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.8 \cdot 10^{+149}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)\\
\end{array}
\end{array}
if b < 2.7999999999999999e149Initial program 77.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.9
Applied rewrites61.9%
if 2.7999999999999999e149 < b Initial program 97.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
clear-numN/A
lower-/.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6497.2
Applied rewrites97.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites58.6%
Taylor expanded in a around 0
Applied rewrites73.7%
Applied rewrites82.8%
Final simplification64.6%
(FPCore (a b angle) :precision binary64 (if (<= b 2.8e+149) (* a a) (* (* (* 3.08641975308642e-5 angle) angle) (* (* (* (PI) (PI)) b) b))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.8 \cdot 10^{+149}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(3.08641975308642 \cdot 10^{-5} \cdot angle\right) \cdot angle\right) \cdot \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right) \cdot b\right)\\
\end{array}
\end{array}
if b < 2.7999999999999999e149Initial program 77.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.9
Applied rewrites61.9%
if 2.7999999999999999e149 < b Initial program 97.2%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
clear-numN/A
lower-/.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6497.2
Applied rewrites97.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites58.6%
Taylor expanded in a around 0
Applied rewrites73.7%
Applied rewrites73.7%
Final simplification63.4%
(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.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6456.3
Applied rewrites56.3%
Final simplification56.3%
herbie shell --seed 2024324
(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)))