
(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 11 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 (+ (pow (* 1.0 b) 2.0) (pow (* (sin (* (PI) (/ angle 180.0))) a) 2.0)))
\begin{array}{l}
\\
{\left(1 \cdot b\right)}^{2} + {\left(\sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right) \cdot a\right)}^{2}
\end{array}
Initial program 80.0%
Taylor expanded in angle around 0
Applied rewrites80.4%
Final simplification80.4%
(FPCore (a b angle) :precision binary64 (fma (* (* 1.0 b) 1.0) b (pow (* (sin (* (* 0.005555555555555556 angle) (PI))) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(1 \cdot b\right) \cdot 1, 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 80.0%
Taylor expanded in angle around 0
Applied rewrites80.4%
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 rewrites80.4%
Final simplification80.4%
(FPCore (a b angle) :precision binary64 (fma (* (* 1.0 b) 1.0) b (pow (* (sin (* (* (PI) angle) 0.005555555555555556)) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(1 \cdot b\right) \cdot 1, b, {\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 80.0%
Taylor expanded in angle around 0
Applied rewrites80.4%
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 rewrites80.4%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
lift-/.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f6480.4
Applied rewrites80.3%
Final simplification80.3%
(FPCore (a b angle)
:precision binary64
(if (<= a 2.1e+30)
(* b b)
(+
(pow (* (* (* 0.005555555555555556 (PI)) angle) a) 2.0)
(pow (* 1.0 b) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.1 \cdot 10^{+30}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot a\right)}^{2} + {\left(1 \cdot b\right)}^{2}\\
\end{array}
\end{array}
if a < 2.1e30Initial program 75.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.7
Applied rewrites62.7%
if 2.1e30 < a Initial program 95.6%
Taylor expanded in angle around 0
Applied rewrites95.6%
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.f6493.2
Applied rewrites93.2%
Final simplification69.6%
(FPCore (a b angle)
:precision binary64
(if (<= a 2.1e+30)
(* b b)
(fma
(* (* (* 3.08641975308642e-5 (* (* (PI) (PI)) a)) angle) angle)
a
(pow (* 1.0 b) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.1 \cdot 10^{+30}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot a\right)\right) \cdot angle\right) \cdot angle, a, {\left(1 \cdot b\right)}^{2}\right)\\
\end{array}
\end{array}
if a < 2.1e30Initial program 75.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.7
Applied rewrites62.7%
if 2.1e30 < a Initial program 95.6%
Taylor expanded in angle around 0
Applied rewrites95.6%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites95.6%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f6491.6
Applied rewrites91.6%
Final simplification69.2%
(FPCore (a b angle)
:precision binary64
(if (<= a 2.1e+30)
(* b b)
(if (<= a 1.3e+144)
(fma
(* (* (* (* a a) 3.08641975308642e-5) (PI)) (PI))
(* angle angle)
(* b b))
(* (* (* angle a) (* (* 3.08641975308642e-5 a) angle)) (* (PI) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.1 \cdot 10^{+30}:\\
\;\;\;\;b \cdot b\\
\mathbf{elif}\;a \leq 1.3 \cdot 10^{+144}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle \cdot angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(angle \cdot a\right) \cdot \left(\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot angle\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 2.1e30Initial program 75.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.7
Applied rewrites62.7%
if 2.1e30 < a < 1.2999999999999999e144Initial program 86.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites38.8%
Taylor expanded in a around inf
Applied rewrites78.2%
if 1.2999999999999999e144 < a Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites58.0%
Taylor expanded in a around inf
Applied rewrites83.0%
Applied rewrites92.6%
Final simplification68.5%
(FPCore (a b angle) :precision binary64 (if (<= a 4.8e+139) (* b b) (* (* (* angle a) (* (* 3.08641975308642e-5 a) angle)) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.8 \cdot 10^{+139}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(angle \cdot a\right) \cdot \left(\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot angle\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 4.80000000000000016e139Initial program 76.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.8
Applied rewrites62.8%
if 4.80000000000000016e139 < a Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites58.0%
Taylor expanded in a around inf
Applied rewrites83.0%
Applied rewrites92.6%
Final simplification67.5%
(FPCore (a b angle) :precision binary64 (if (<= a 4.8e+139) (* b b) (* (* (* (* (* angle a) angle) a) 3.08641975308642e-5) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.8 \cdot 10^{+139}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(angle \cdot a\right) \cdot angle\right) \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 4.80000000000000016e139Initial program 76.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.8
Applied rewrites62.8%
if 4.80000000000000016e139 < a Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites58.0%
Taylor expanded in a around inf
Applied rewrites83.0%
Applied rewrites92.5%
Final simplification67.4%
(FPCore (a b angle) :precision binary64 (if (<= a 4.8e+139) (* b b) (* (* (* (* (* a a) 3.08641975308642e-5) angle) angle) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.8 \cdot 10^{+139}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot angle\right) \cdot angle\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 4.80000000000000016e139Initial program 76.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.8
Applied rewrites62.8%
if 4.80000000000000016e139 < a Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites58.0%
Taylor expanded in a around inf
Applied rewrites83.0%
Taylor expanded in a around 0
Applied rewrites85.8%
(FPCore (a b angle) :precision binary64 (if (<= a 2.95e+140) (* b b) (* (* (* (* a a) (PI)) (PI)) (* (* angle angle) 3.08641975308642e-5))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.95 \cdot 10^{+140}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(a \cdot a\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right)\\
\end{array}
\end{array}
if a < 2.9500000000000001e140Initial program 76.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.8
Applied rewrites62.8%
if 2.9500000000000001e140 < a Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites58.0%
Taylor expanded in a around inf
Applied rewrites83.0%
Taylor expanded in a around 0
Applied rewrites80.5%
Final simplification65.6%
(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 80.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6457.6
Applied rewrites57.6%
herbie shell --seed 2024332
(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)))