
(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 14 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}
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(+
(pow (* (cos (* (/ angle_m 180.0) (PI))) b) 2.0)
(pow
(*
(sin (* (* (PI) (* 0.005555555555555556 (sqrt angle_m))) (sqrt angle_m)))
a)
2.0)))\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(\cos \left(\frac{angle\_m}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2} + {\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot \left(0.005555555555555556 \cdot \sqrt{angle\_m}\right)\right) \cdot \sqrt{angle\_m}\right) \cdot a\right)}^{2}
\end{array}
Initial program 75.3%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6475.3
Applied rewrites75.3%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
metadata-evalN/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
rem-square-sqrtN/A
unpow1/2N/A
lift-pow.f64N/A
unpow1/2N/A
lift-pow.f64N/A
associate-*l*N/A
lift-*.f64N/A
lower-*.f6436.3
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6436.4
lift-pow.f64N/A
unpow1/2N/A
lower-sqrt.f6436.4
lift-pow.f64N/A
unpow1/2N/A
lower-sqrt.f6436.4
Applied rewrites36.4%
Final simplification36.4%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(+
(pow (* 1.0 b) 2.0)
(pow
(*
(sin (* (* (PI) (* 0.005555555555555556 (sqrt angle_m))) (sqrt angle_m)))
a)
2.0)))\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(1 \cdot b\right)}^{2} + {\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot \left(0.005555555555555556 \cdot \sqrt{angle\_m}\right)\right) \cdot \sqrt{angle\_m}\right) \cdot a\right)}^{2}
\end{array}
Initial program 75.3%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6475.3
Applied rewrites75.3%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
metadata-evalN/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
rem-square-sqrtN/A
unpow1/2N/A
lift-pow.f64N/A
unpow1/2N/A
lift-pow.f64N/A
associate-*l*N/A
lift-*.f64N/A
lower-*.f6436.3
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6436.4
lift-pow.f64N/A
unpow1/2N/A
lower-sqrt.f6436.4
lift-pow.f64N/A
unpow1/2N/A
lower-sqrt.f6436.4
Applied rewrites36.4%
Taylor expanded in angle around 0
Applied rewrites36.3%
Final simplification36.3%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(let* ((t_0 (* (PI) angle_m)))
(if (<= a 4e+152)
(fma
(* (pow (- (sin (* -0.005555555555555556 t_0))) 2.0) a)
a
(pow (* 1.0 b) 2.0))
(fma
(* (* (* 3.08641975308642e-5 (* (* (PI) (PI)) a)) angle_m) angle_m)
a
(pow (* (cos (/ t_0 -180.0)) b) 2.0)))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot angle\_m\\
\mathbf{if}\;a \leq 4 \cdot 10^{+152}:\\
\;\;\;\;\mathsf{fma}\left({\left(-\sin \left(-0.005555555555555556 \cdot t\_0\right)\right)}^{2} \cdot a, a, {\left(1 \cdot b\right)}^{2}\right)\\
\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\_m\right) \cdot angle\_m, a, {\left(\cos \left(\frac{t\_0}{-180}\right) \cdot b\right)}^{2}\right)\\
\end{array}
\end{array}
if a < 4.0000000000000002e152Initial program 72.0%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites70.2%
lift-sin.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
lift-PI.f64N/A
lift-PI.f64N/A
associate-*l/N/A
*-commutativeN/A
lift-*.f64N/A
frac-2negN/A
neg-sub0N/A
metadata-evalN/A
div-subN/A
metadata-evalN/A
lift-/.f64N/A
neg-sub0N/A
sin-negN/A
lower-neg.f64N/A
lower-sin.f6470.3
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
Applied rewrites70.3%
Taylor expanded in angle around 0
Applied rewrites70.2%
if 4.0000000000000002e152 < a Initial program 96.8%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites82.7%
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.f6496.8
Applied rewrites96.8%
Final simplification73.8%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= a 4e+152)
(fma
(* (pow (sin (* (* 0.005555555555555556 angle_m) (PI))) 2.0) a)
a
(pow (* 1.0 b) 2.0))
(fma
(* (* (* 3.08641975308642e-5 (* (* (PI) (PI)) a)) angle_m) angle_m)
a
(pow (* (cos (/ (* (PI) angle_m) -180.0)) b) 2.0))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4 \cdot 10^{+152}:\\
\;\;\;\;\mathsf{fma}\left({\sin \left(\left(0.005555555555555556 \cdot angle\_m\right) \cdot \mathsf{PI}\left(\right)\right)}^{2} \cdot a, a, {\left(1 \cdot b\right)}^{2}\right)\\
\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\_m\right) \cdot angle\_m, a, {\left(\cos \left(\frac{\mathsf{PI}\left(\right) \cdot angle\_m}{-180}\right) \cdot b\right)}^{2}\right)\\
\end{array}
\end{array}
if a < 4.0000000000000002e152Initial program 72.0%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites70.2%
Taylor expanded in angle around 0
Applied rewrites70.2%
if 4.0000000000000002e152 < a Initial program 96.8%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites82.7%
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.f6496.8
Applied rewrites96.8%
Final simplification73.7%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* (sin (/ (* (PI) angle_m) 180.0)) a) 2.0) (pow (* 1.0 b) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(\sin \left(\frac{\mathsf{PI}\left(\right) \cdot angle\_m}{180}\right) \cdot a\right)}^{2} + {\left(1 \cdot b\right)}^{2}
\end{array}
Initial program 75.3%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6475.3
Applied rewrites75.3%
Taylor expanded in angle around 0
Applied rewrites75.3%
Final simplification75.3%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* (sin (* (/ angle_m 180.0) (PI))) a) 2.0) (pow (* 1.0 b) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(\sin \left(\frac{angle\_m}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot a\right)}^{2} + {\left(1 \cdot b\right)}^{2}
\end{array}
Initial program 75.3%
Taylor expanded in angle around 0
Applied rewrites75.2%
Final simplification75.2%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= a 7.4e-116)
(* b b)
(fma
(* (* (* 3.08641975308642e-5 (* (* (PI) (PI)) a)) angle_m) angle_m)
a
(pow (* (cos (/ (* (PI) angle_m) -180.0)) b) 2.0))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.4 \cdot 10^{-116}:\\
\;\;\;\;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\_m\right) \cdot angle\_m, a, {\left(\cos \left(\frac{\mathsf{PI}\left(\right) \cdot angle\_m}{-180}\right) \cdot b\right)}^{2}\right)\\
\end{array}
\end{array}
if a < 7.4000000000000005e-116Initial program 73.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.0
Applied rewrites58.0%
if 7.4000000000000005e-116 < a Initial program 79.8%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites74.4%
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.f6476.3
Applied rewrites76.3%
Final simplification64.1%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= a 1.45e+104) (* (pow (cos (* (* (PI) 0.005555555555555556) angle_m)) 2.0) (* b b)) (* (pow (* (* (PI) a) angle_m) 2.0) 3.08641975308642e-5)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.45 \cdot 10^{+104}:\\
\;\;\;\;{\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\_m\right)}^{2} \cdot \left(b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\mathsf{PI}\left(\right) \cdot a\right) \cdot angle\_m\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if a < 1.4499999999999999e104Initial program 73.0%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f6459.3
Applied rewrites59.3%
if 1.4499999999999999e104 < a Initial program 87.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites47.5%
Taylor expanded in b around 0
Applied rewrites57.2%
Applied rewrites74.3%
Final simplification61.7%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= a 1.45e+104) (* (pow (cos (* -0.005555555555555556 (* (PI) angle_m))) 2.0) (* b b)) (* (pow (* (* (PI) a) angle_m) 2.0) 3.08641975308642e-5)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.45 \cdot 10^{+104}:\\
\;\;\;\;{\cos \left(-0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\_m\right)\right)}^{2} \cdot \left(b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\mathsf{PI}\left(\right) \cdot a\right) \cdot angle\_m\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if a < 1.4499999999999999e104Initial program 73.0%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites71.2%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f6459.3
Applied rewrites59.3%
if 1.4499999999999999e104 < a Initial program 87.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites47.5%
Taylor expanded in b around 0
Applied rewrites57.2%
Applied rewrites74.3%
Final simplification61.7%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= a 1.45e+104) (* b b) (* (pow (* (* (PI) a) angle_m) 2.0) 3.08641975308642e-5)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.45 \cdot 10^{+104}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\mathsf{PI}\left(\right) \cdot a\right) \cdot angle\_m\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if a < 1.4499999999999999e104Initial program 73.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6459.2
Applied rewrites59.2%
if 1.4499999999999999e104 < a Initial program 87.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites47.5%
Taylor expanded in b around 0
Applied rewrites57.2%
Applied rewrites74.3%
Final simplification61.6%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= b 4.8e+24)
(fma
(*
(* (* (PI) (PI)) angle_m)
(fma (* 3.08641975308642e-5 a) a (* -3.08641975308642e-5 (* b b))))
angle_m
(* b b))
(* b b)))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.8 \cdot 10^{+24}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\_m\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\_m, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 4.8000000000000001e24Initial program 74.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.0%
Applied rewrites46.1%
if 4.8000000000000001e24 < b Initial program 79.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6475.9
Applied rewrites75.9%
Final simplification52.0%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(let* ((t_0 (* (PI) (PI))))
(if (<= a 1.45e-60)
(* b b)
(if (<= a 2.8e+151)
(fma
(* (* (* a a) 3.08641975308642e-5) t_0)
(* angle_m angle_m)
(* b b))
(* (* (* (* (* angle_m angle_m) a) a) 3.08641975308642e-5) t_0)))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;a \leq 1.45 \cdot 10^{-60}:\\
\;\;\;\;b \cdot b\\
\mathbf{elif}\;a \leq 2.8 \cdot 10^{+151}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot t\_0, angle\_m \cdot angle\_m, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(angle\_m \cdot angle\_m\right) \cdot a\right) \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot t\_0\\
\end{array}
\end{array}
if a < 1.45e-60Initial program 72.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.1
Applied rewrites58.1%
if 1.45e-60 < a < 2.79999999999999987e151Initial program 69.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites31.0%
Taylor expanded in b around 0
Applied rewrites63.2%
if 2.79999999999999987e151 < a Initial program 96.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites50.4%
Taylor expanded in b around 0
Applied rewrites65.0%
Taylor expanded in b around 0
Applied rewrites71.8%
Final simplification60.7%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= a 6e+105) (* b b) (* (* (* (* (* angle_m angle_m) a) a) 3.08641975308642e-5) (* (PI) (PI)))))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 6 \cdot 10^{+105}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(angle\_m \cdot angle\_m\right) \cdot a\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 < 6.0000000000000001e105Initial program 73.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6459.2
Applied rewrites59.2%
if 6.0000000000000001e105 < a Initial program 87.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites47.5%
Taylor expanded in b around 0
Applied rewrites57.2%
Taylor expanded in b around 0
Applied rewrites62.9%
Final simplification59.8%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (* b b))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return b * b;
}
angle_m = abs(angle)
real(8) function code(a, b, angle_m)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle_m
code = b * b
end function
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return b * b;
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return b * b
angle_m = abs(angle) function code(a, b, angle_m) return Float64(b * b) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = b * b; end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(b * b), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
b \cdot b
\end{array}
Initial program 75.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6454.3
Applied rewrites54.3%
herbie shell --seed 2024254
(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)))