
(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 12 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 (* (* 0.005555555555555556 (PI)) angle))) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(b \cdot 1\right) \cdot 1, b, {\left(a \cdot \sin \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)\right)}^{2}\right)
\end{array}
Initial program 80.1%
Taylor expanded in angle around 0
Applied rewrites80.4%
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f6440.7
Applied rewrites40.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 rewrites80.5%
Final simplification80.5%
(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 80.1%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites80.2%
Taylor expanded in angle around 0
Applied rewrites80.4%
Final simplification80.4%
(FPCore (a b angle) :precision binary64 (+ (pow (* b 1.0) 2.0) (pow (* (* (* (PI) angle) a) 0.005555555555555556) 2.0)))
\begin{array}{l}
\\
{\left(b \cdot 1\right)}^{2} + {\left(\left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot a\right) \cdot 0.005555555555555556\right)}^{2}
\end{array}
Initial program 80.1%
Taylor expanded in angle around 0
Applied rewrites80.4%
Taylor expanded in angle around 0
rem-square-sqrtN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
rem-square-sqrtN/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6476.5
Applied rewrites76.5%
Final simplification76.5%
(FPCore (a b angle)
:precision binary64
(if (<= b 7e-142)
(* (pow (* (* a (PI)) angle) 2.0) 3.08641975308642e-5)
(if (<= b 1.25e+147)
(fma
(* (* (* a a) 3.08641975308642e-5) (* (PI) (PI)))
(* angle angle)
(* b b))
(*
(fma (cos (* -0.011111111111111112 (* (PI) angle))) 0.5 0.5)
(* b b)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{-142}:\\
\;\;\;\;{\left(\left(a \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{+147}:\\
\;\;\;\;\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}:\\
\;\;\;\;\mathsf{fma}\left(\cos \left(-0.011111111111111112 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\right)\right), 0.5, 0.5\right) \cdot \left(b \cdot b\right)\\
\end{array}
\end{array}
if b < 7.00000000000000029e-142Initial program 79.5%
Taylor expanded in angle around 0
Applied rewrites79.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.5%
Taylor expanded in a around inf
Applied rewrites32.5%
Applied rewrites37.8%
if 7.00000000000000029e-142 < b < 1.2500000000000001e147Initial program 71.7%
Taylor expanded in angle around 0
Applied rewrites72.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites59.0%
Taylor expanded in a around inf
Applied rewrites62.4%
if 1.2500000000000001e147 < b Initial program 97.6%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites97.6%
lift-pow.f64N/A
unpow2N/A
lift-cos.f64N/A
lift-cos.f64N/A
sqr-cos-aN/A
lower-+.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6497.6
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval97.6
Applied rewrites97.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f6497.6
Applied rewrites97.6%
Final simplification51.8%
(FPCore (a b angle) :precision binary64 (fma (* (* b 1.0) 1.0) b (pow (* (* (* 0.005555555555555556 (PI)) angle) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(b \cdot 1\right) \cdot 1, b, {\left(\left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 80.1%
Taylor expanded in angle around 0
Applied rewrites80.4%
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f6440.7
Applied rewrites40.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 rewrites80.5%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6476.5
Applied rewrites76.5%
Final simplification76.5%
(FPCore (a b angle)
:precision binary64
(if (<= b 7e-142)
(* (pow (* (* a (PI)) angle) 2.0) 3.08641975308642e-5)
(if (<= b 1.25e+147)
(fma
(* (* (* a a) 3.08641975308642e-5) (* (PI) (PI)))
(* angle angle)
(* b b))
(* b b))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{-142}:\\
\;\;\;\;{\left(\left(a \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{+147}:\\
\;\;\;\;\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 b < 7.00000000000000029e-142Initial program 79.5%
Taylor expanded in angle around 0
Applied rewrites79.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.5%
Taylor expanded in a around inf
Applied rewrites32.5%
Applied rewrites37.8%
if 7.00000000000000029e-142 < b < 1.2500000000000001e147Initial program 71.7%
Taylor expanded in angle around 0
Applied rewrites72.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites59.0%
Taylor expanded in a around inf
Applied rewrites62.4%
if 1.2500000000000001e147 < b Initial program 97.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6497.6
Applied rewrites97.6%
Final simplification51.8%
(FPCore (a b angle)
:precision binary64
(if (<= b 1.25e+147)
(fma
(*
(* (* (PI) (PI)) angle)
(fma (* 3.08641975308642e-5 a) a (* (* b b) -3.08641975308642e-5)))
angle
(* b b))
(* b b)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.25 \cdot 10^{+147}:\\
\;\;\;\;\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, \left(b \cdot b\right) \cdot -3.08641975308642 \cdot 10^{-5}\right), angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 1.2500000000000001e147Initial program 77.3%
Taylor expanded in angle around 0
Applied rewrites77.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites51.4%
Applied rewrites51.0%
if 1.2500000000000001e147 < b Initial program 97.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6497.6
Applied rewrites97.6%
Final simplification57.4%
(FPCore (a b angle)
:precision binary64
(if (<= b 1.25e+147)
(fma
(* (* (* a a) 3.08641975308642e-5) (* (PI) (PI)))
(* angle angle)
(* b b))
(* b b)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.25 \cdot 10^{+147}:\\
\;\;\;\;\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 b < 1.2500000000000001e147Initial program 77.3%
Taylor expanded in angle around 0
Applied rewrites77.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites51.4%
Taylor expanded in a around inf
Applied rewrites63.9%
if 1.2500000000000001e147 < b Initial program 97.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6497.6
Applied rewrites97.6%
Final simplification68.5%
(FPCore (a b angle)
:precision binary64
(if (<= b 1.25e+147)
(fma
(* (* (* (* (PI) (PI)) 3.08641975308642e-5) a) a)
(* angle angle)
(* b b))
(* b b)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.25 \cdot 10^{+147}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot a\right) \cdot a, angle \cdot angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 1.2500000000000001e147Initial program 77.3%
Taylor expanded in angle around 0
Applied rewrites77.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites51.4%
Taylor expanded in a around inf
Applied rewrites63.9%
if 1.2500000000000001e147 < b Initial program 97.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6497.6
Applied rewrites97.6%
Final simplification68.5%
(FPCore (a b angle) :precision binary64 (if (<= b 2.05e-159) (* (* (* (* (* angle angle) 3.08641975308642e-5) a) (* (PI) (PI))) a) (* b b)))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.05 \cdot 10^{-159}:\\
\;\;\;\;\left(\left(\left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot a\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot a\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 2.05000000000000007e-159Initial program 79.8%
Taylor expanded in angle around 0
Applied rewrites79.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites49.1%
Taylor expanded in a around inf
Applied rewrites32.7%
Applied rewrites34.1%
if 2.05000000000000007e-159 < b Initial program 80.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.5
Applied rewrites62.5%
(FPCore (a b angle) :precision binary64 (if (<= b 4.7e-161) (* (* (* (* (PI) (PI)) angle) angle) (* (* a a) 3.08641975308642e-5)) (* b b)))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.7 \cdot 10^{-161}:\\
\;\;\;\;\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot angle\right) \cdot \left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 4.7000000000000004e-161Initial program 79.8%
Taylor expanded in angle around 0
Applied rewrites79.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites49.1%
Taylor expanded in a around inf
Applied rewrites32.7%
Taylor expanded in a around 0
Applied rewrites33.1%
if 4.7000000000000004e-161 < b Initial program 80.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.5
Applied rewrites62.5%
Final simplification44.8%
(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.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.5
Applied rewrites58.5%
herbie shell --seed 2024331
(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)))