
(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 6 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 (+ (* a a) (pow (* b (sin (* (* angle (PI)) 0.005555555555555556))) 2.0)))
\begin{array}{l}
\\
a \cdot a + {\left(b \cdot \sin \left(\left(angle \cdot \mathsf{PI}\left(\right)\right) \cdot 0.005555555555555556\right)\right)}^{2}
\end{array}
Initial program 83.9%
Taylor expanded in angle around 0
Applied rewrites84.1%
Taylor expanded in angle around inf
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6484.2
Applied rewrites84.2%
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6484.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6484.2
Applied rewrites84.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6484.2
Applied rewrites84.2%
(FPCore (a b angle)
:precision binary64
(if (<= b 3.9e-100)
(* a a)
(if (<= b 5.4e+157)
(fma
(* (* (* (* (PI) (PI)) 3.08641975308642e-5) b) b)
(* angle angle)
(* a a))
(* (pow (* (* (PI) b) angle) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.9 \cdot 10^{-100}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 5.4 \cdot 10^{+157}:\\
\;\;\;\;\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}:\\
\;\;\;\;{\left(\left(\mathsf{PI}\left(\right) \cdot b\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 3.89999999999999977e-100Initial program 87.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6467.5
Applied rewrites67.5%
if 3.89999999999999977e-100 < b < 5.4000000000000001e157Initial program 64.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites32.1%
Taylor expanded in a around 0
Applied rewrites54.8%
if 5.4000000000000001e157 < b Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites52.2%
Taylor expanded in a around 0
Applied rewrites70.4%
Applied rewrites90.7%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) (PI))))
(if (<= b 3.9e-100)
(* a a)
(if (<= b 5.4e+157)
(fma (* (* (* t_0 3.08641975308642e-5) b) b) (* angle angle) (* a a))
(* (* t_0 b) (* b (* 3.08641975308642e-5 (* angle angle))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;b \leq 3.9 \cdot 10^{-100}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 5.4 \cdot 10^{+157}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(t\_0 \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right) \cdot b, angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 \cdot b\right) \cdot \left(b \cdot \left(3.08641975308642 \cdot 10^{-5} \cdot \left(angle \cdot angle\right)\right)\right)\\
\end{array}
\end{array}
if b < 3.89999999999999977e-100Initial program 87.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6467.5
Applied rewrites67.5%
if 3.89999999999999977e-100 < b < 5.4000000000000001e157Initial program 64.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites32.1%
Taylor expanded in a around 0
Applied rewrites54.8%
if 5.4000000000000001e157 < b Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites52.2%
Taylor expanded in a around 0
Applied rewrites70.4%
Applied rewrites82.2%
(FPCore (a b angle) :precision binary64 (if (<= b 5.4e+157) (* a a) (* (* (* (PI) (PI)) b) (* b (* 3.08641975308642e-5 (* angle angle))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.4 \cdot 10^{+157}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right) \cdot \left(b \cdot \left(3.08641975308642 \cdot 10^{-5} \cdot \left(angle \cdot angle\right)\right)\right)\\
\end{array}
\end{array}
if b < 5.4000000000000001e157Initial program 81.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.1
Applied rewrites63.1%
if 5.4000000000000001e157 < b Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites52.2%
Taylor expanded in a around 0
Applied rewrites70.4%
Applied rewrites82.2%
(FPCore (a b angle) :precision binary64 (if (<= b 2.4e+150) (* a a) (* (* (PI) (PI)) (* (* b b) (* 3.08641975308642e-5 (* angle angle))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.4 \cdot 10^{+150}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(\left(b \cdot b\right) \cdot \left(3.08641975308642 \cdot 10^{-5} \cdot \left(angle \cdot angle\right)\right)\right)\\
\end{array}
\end{array}
if b < 2.40000000000000003e150Initial program 82.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.4
Applied rewrites63.4%
if 2.40000000000000003e150 < b Initial program 95.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.5%
Taylor expanded in a around 0
Applied rewrites65.2%
Applied rewrites65.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 83.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.8
Applied rewrites58.8%
herbie shell --seed 2024337
(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)))