
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (/ angle 180.0) (PI)))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \mathsf{PI}\left(\right)\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos 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 (* (/ angle 180.0) (PI)))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \mathsf{PI}\left(\right)\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos t\_0\right)}^{2}
\end{array}
\end{array}
(FPCore (a b angle) :precision binary64 (fma (* (* b 1.0) 1.0) b (pow (* a (sin (* (* (PI) angle) 0.005555555555555556))) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(b \cdot 1\right) \cdot 1, b, {\left(a \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right)\right)}^{2}\right)
\end{array}
Initial program 75.5%
Taylor expanded in angle around 0
Applied rewrites75.6%
lift-/.f64N/A
clear-numN/A
lift-/.f64N/A
lower-/.f6475.7
Applied rewrites75.7%
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*l/N/A
*-commutativeN/A
lift-*.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6475.7
Applied rewrites75.7%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites75.7%
Final simplification75.7%
(FPCore (a b angle)
:precision binary64
(if (<= a 4.8e-33)
(* b b)
(+
(pow (* b 1.0) 2.0)
(pow (* (* (* (PI) 0.005555555555555556) angle) a) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.8 \cdot 10^{-33}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(b \cdot 1\right)}^{2} + {\left(\left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right) \cdot a\right)}^{2}\\
\end{array}
\end{array}
if a < 4.8e-33Initial program 72.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6455.7
Applied rewrites55.7%
if 4.8e-33 < a Initial program 82.9%
Taylor expanded in angle around 0
Applied rewrites82.2%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6478.9
Applied rewrites78.9%
Final simplification62.2%
(FPCore (a b angle)
:precision binary64
(if (<= a 4.8e-33)
(* b b)
(+
(pow (* (* (* a (PI)) 0.005555555555555556) angle) 2.0)
(pow (* b 1.0) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.8 \cdot 10^{-33}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\left(a \cdot \mathsf{PI}\left(\right)\right) \cdot 0.005555555555555556\right) \cdot angle\right)}^{2} + {\left(b \cdot 1\right)}^{2}\\
\end{array}
\end{array}
if a < 4.8e-33Initial program 72.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6455.7
Applied rewrites55.7%
if 4.8e-33 < a Initial program 82.9%
Taylor expanded in angle around 0
Applied rewrites82.2%
lift-/.f64N/A
clear-numN/A
lift-/.f64N/A
lower-/.f6482.2
Applied rewrites82.2%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6479.0
Applied rewrites79.0%
Final simplification62.2%
(FPCore (a b angle) :precision binary64 (fma (* 1.0 b) b (pow (* (sin (* (* 0.005555555555555556 angle) (PI))) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(1 \cdot b, b, {\left(\sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 75.5%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites69.5%
Applied rewrites75.6%
Taylor expanded in angle around 0
Applied rewrites75.7%
Final simplification75.7%
(FPCore (a b angle)
:precision binary64
(if (<= a 4.8e-33)
(* b b)
(+
(* (* (PI) (PI)) (* (* (* (* angle angle) a) a) 3.08641975308642e-5))
(pow (* b 1.0) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.8 \cdot 10^{-33}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(\left(\left(\left(angle \cdot angle\right) \cdot a\right) \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) + {\left(b \cdot 1\right)}^{2}\\
\end{array}
\end{array}
if a < 4.8e-33Initial program 72.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6455.7
Applied rewrites55.7%
if 4.8e-33 < a Initial program 82.9%
Taylor expanded in angle around 0
Applied rewrites82.2%
Taylor expanded in angle around 0
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f6470.6
Applied rewrites70.6%
Final simplification59.9%
(FPCore (a b angle)
:precision binary64
(if (<= a 4.8e-33)
(* b b)
(if (<= a 1.75e+143)
(fma
(* (* (* a a) 3.08641975308642e-5) (* (PI) (PI)))
(* angle angle)
(* b b))
(* (pow (* (* a (PI)) angle) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.8 \cdot 10^{-33}:\\
\;\;\;\;b \cdot b\\
\mathbf{elif}\;a \leq 1.75 \cdot 10^{+143}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), angle \cdot angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(a \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if a < 4.8e-33Initial program 72.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6455.7
Applied rewrites55.7%
if 4.8e-33 < a < 1.75000000000000004e143Initial program 74.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.6%
Taylor expanded in a around inf
Applied rewrites64.3%
if 1.75000000000000004e143 < a Initial program 94.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites14.7%
Taylor expanded in a around inf
Applied rewrites40.6%
Applied rewrites60.1%
Final simplification57.6%
(FPCore (a b angle)
:precision binary64
(if (<= (/ angle 180.0) 4e-163)
(* b b)
(if (<= (/ angle 180.0) 1e+166)
(fma
(* (* (* a a) 3.08641975308642e-5) (* (PI) (PI)))
(* angle angle)
(* b b))
(* b b))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{angle}{180} \leq 4 \cdot 10^{-163}:\\
\;\;\;\;b \cdot b\\
\mathbf{elif}\;\frac{angle}{180} \leq 10^{+166}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), angle \cdot angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if (/.f64 angle #s(literal 180 binary64)) < 3.99999999999999969e-163 or 9.9999999999999994e165 < (/.f64 angle #s(literal 180 binary64)) Initial program 77.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6453.8
Applied rewrites53.8%
if 3.99999999999999969e-163 < (/.f64 angle #s(literal 180 binary64)) < 9.9999999999999994e165Initial program 69.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites26.7%
Taylor expanded in a around inf
Applied rewrites63.5%
Final simplification56.1%
(FPCore (a b angle)
:precision binary64
(if (<= b 0.028)
(fma
(*
(* (* (PI) (PI)) angle)
(fma (* 3.08641975308642e-5 a) a (* -3.08641975308642e-5 (* b b))))
angle
(* b b))
(* b b)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.028:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot \mathsf{fma}\left(3.08641975308642 \cdot 10^{-5} \cdot a, a, -3.08641975308642 \cdot 10^{-5} \cdot \left(b \cdot b\right)\right), angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 0.0280000000000000006Initial program 72.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites36.1%
Applied rewrites42.4%
if 0.0280000000000000006 < b Initial program 86.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6476.4
Applied rewrites76.4%
Final simplification50.1%
(FPCore (a b angle) :precision binary64 (if (<= b 6.6e-105) (* (* (PI) (PI)) (* (* (* (* angle angle) a) a) 3.08641975308642e-5)) (* b b)))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.6 \cdot 10^{-105}:\\
\;\;\;\;\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(\left(\left(\left(angle \cdot angle\right) \cdot a\right) \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 6.5999999999999997e-105Initial program 74.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites35.0%
Taylor expanded in a around inf
Applied rewrites31.6%
Taylor expanded in a around 0
Applied rewrites33.2%
if 6.5999999999999997e-105 < b Initial program 77.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.2
Applied rewrites63.2%
Final simplification43.1%
(FPCore (a b angle) :precision binary64 (* b b))
double code(double a, double b, double angle) {
return b * b;
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = b * b
end function
public static double code(double a, double b, double angle) {
return b * b;
}
def code(a, b, angle): return b * b
function code(a, b, angle) return Float64(b * b) end
function tmp = code(a, b, angle) tmp = b * b; end
code[a_, b_, angle_] := N[(b * b), $MachinePrecision]
\begin{array}{l}
\\
b \cdot b
\end{array}
Initial program 75.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6453.6
Applied rewrites53.6%
herbie shell --seed 2024296
(FPCore (a b angle)
:name "ab-angle->ABCF A"
:precision binary64
(+ (pow (* a (sin (* (/ angle 180.0) (PI)))) 2.0) (pow (* b (cos (* (/ angle 180.0) (PI)))) 2.0)))