
(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
(let* ((t_0 (* angle_m (PI))) (t_1 (* t_0 -0.005555555555555556)))
(+
(pow (* a (sin (* (/ angle_m 180.0) (PI)))) 2.0)
(pow
(*
b
(/
(fma
(+
(sin (fma 0.005555555555555556 t_0 (* (PI) -0.5)))
(cos (* 0.005555555555555556 (* (PI) angle_m))))
2.0
(* 2.0 (+ (sin (- (* 0.5 (PI)) t_1)) (sin (fma 0.5 (PI) t_1)))))
4.0))
2.0))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := angle\_m \cdot \mathsf{PI}\left(\right)\\
t_1 := t\_0 \cdot -0.005555555555555556\\
{\left(a \cdot \sin \left(\frac{angle\_m}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {\left(b \cdot \frac{\mathsf{fma}\left(\sin \left(\mathsf{fma}\left(0.005555555555555556, t\_0, \mathsf{PI}\left(\right) \cdot -0.5\right)\right) + \cos \left(0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\_m\right)\right), 2, 2 \cdot \left(\sin \left(0.5 \cdot \mathsf{PI}\left(\right) - t\_1\right) + \sin \left(\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right), t\_1\right)\right)\right)\right)}{4}\right)}^{2}
\end{array}
\end{array}
Initial program 82.8%
lift-cos.f64N/A
cos-neg-revN/A
cos-neg-revN/A
sin-+PI/2-revN/A
remove-double-negN/A
add-cube-cbrtN/A
associate-/l*N/A
fp-cancel-sign-sub-invN/A
sin-diffN/A
lower--.f64N/A
Applied rewrites82.8%
Applied rewrites82.8%
Taylor expanded in angle around inf
cos-neg-revN/A
sin-+PI/2-revN/A
distribute-lft-neg-inN/A
metadata-evalN/A
sin-+PI/2-revN/A
lower-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6482.8
Applied rewrites82.8%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(let* ((t_0 (* angle_m (PI))))
(+
(pow (* a (sin (* (/ angle_m 180.0) (PI)))) 2.0)
(pow
(*
b
(/
(fma
(+
(sin (fma 0.005555555555555556 t_0 (* (PI) -0.5)))
(cos (* 0.005555555555555556 (* (PI) angle_m))))
2.0
(*
2.0
(+
(sin (fma (* (PI) 0.005555555555555556) angle_m (* 0.5 (PI))))
(sin (fma 0.5 (PI) (* t_0 -0.005555555555555556))))))
4.0))
2.0))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := angle\_m \cdot \mathsf{PI}\left(\right)\\
{\left(a \cdot \sin \left(\frac{angle\_m}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {\left(b \cdot \frac{\mathsf{fma}\left(\sin \left(\mathsf{fma}\left(0.005555555555555556, t\_0, \mathsf{PI}\left(\right) \cdot -0.5\right)\right) + \cos \left(0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\_m\right)\right), 2, 2 \cdot \left(\sin \left(\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556, angle\_m, 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) + \sin \left(\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right), t\_0 \cdot -0.005555555555555556\right)\right)\right)\right)}{4}\right)}^{2}
\end{array}
\end{array}
Initial program 82.8%
lift-cos.f64N/A
cos-neg-revN/A
cos-neg-revN/A
sin-+PI/2-revN/A
remove-double-negN/A
add-cube-cbrtN/A
associate-/l*N/A
fp-cancel-sign-sub-invN/A
sin-diffN/A
lower--.f64N/A
Applied rewrites82.8%
Applied rewrites82.8%
Taylor expanded in angle around inf
cos-neg-revN/A
sin-+PI/2-revN/A
distribute-lft-neg-inN/A
metadata-evalN/A
sin-+PI/2-revN/A
lower-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6482.8
Applied rewrites82.8%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6482.7
Applied rewrites82.7%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(let* ((t_0 (sin (* (/ angle_m 180.0) (PI)))))
(fma
(* (* t_0 a) t_0)
a
(pow (* (cos (/ (* angle_m (PI)) -180.0)) b) 2.0))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := \sin \left(\frac{angle\_m}{180} \cdot \mathsf{PI}\left(\right)\right)\\
\mathsf{fma}\left(\left(t\_0 \cdot a\right) \cdot t\_0, a, {\left(\cos \left(\frac{angle\_m \cdot \mathsf{PI}\left(\right)}{-180}\right) \cdot b\right)}^{2}\right)
\end{array}
\end{array}
Initial program 82.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6482.8
Applied rewrites82.8%
Applied rewrites82.8%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (let* ((t_0 (* (PI) (/ angle_m 180.0)))) (fma (pow (cos t_0) 2.0) (* b b) (pow (* (sin t_0) a) 2.0))))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle\_m}{180}\\
\mathsf{fma}\left({\cos t\_0}^{2}, b \cdot b, {\left(\sin t\_0 \cdot a\right)}^{2}\right)
\end{array}
\end{array}
Initial program 82.8%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
lower-fma.f64N/A
lower-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6482.8
Applied rewrites82.8%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (let* ((t_0 (* (/ angle_m 180.0) (PI)))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := \frac{angle\_m}{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}
Initial program 82.8%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (sin (* 0.005555555555555556 (* (PI) angle_m)))) 2.0) (pow (* b (cos (* (/ angle_m 180.0) (PI)))) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \sin \left(0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\_m\right)\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{angle\_m}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}
\end{array}
Initial program 82.8%
lift-*.f64N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
sqr-neg-revN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
lower-sqrt.f6482.7
Applied rewrites82.7%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-neg-revN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
*-commutativeN/A
lift-/.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
associate-*r*N/A
Applied rewrites82.7%
Taylor expanded in angle around 0
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6482.8
Applied rewrites82.8%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (sin (* (* (PI) 0.005555555555555556) angle_m))) 2.0) (pow (* b (cos (* (/ angle_m 180.0) (PI)))) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\_m\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{angle\_m}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}
\end{array}
Initial program 82.8%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
lower-sin.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6482.8
Applied rewrites82.8%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (sin (* (* 0.005555555555555556 (PI)) angle_m))) 2.0) (pow (* b (cos (/ (* (PI) angle_m) 180.0))) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \sin \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\_m\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{\mathsf{PI}\left(\right) \cdot angle\_m}{180}\right)\right)}^{2}
\end{array}
Initial program 82.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6482.8
Applied rewrites82.8%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
lower-sin.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6482.8
Applied rewrites82.8%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (let* ((t_0 (sin (* (/ angle_m 180.0) (PI))))) (fma (* (* t_0 a) t_0) a (pow (* 1.0 b) 2.0))))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := \sin \left(\frac{angle\_m}{180} \cdot \mathsf{PI}\left(\right)\right)\\
\mathsf{fma}\left(\left(t\_0 \cdot a\right) \cdot t\_0, a, {\left(1 \cdot b\right)}^{2}\right)
\end{array}
\end{array}
Initial program 82.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6482.8
Applied rewrites82.8%
Applied rewrites82.8%
Taylor expanded in angle around 0
Applied rewrites82.6%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (sin (* (/ angle_m 180.0) (PI)))) 2.0) (pow (* b 1.0) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \sin \left(\frac{angle\_m}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {\left(b \cdot 1\right)}^{2}
\end{array}
Initial program 82.8%
Taylor expanded in angle around 0
Applied rewrites82.6%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= a 1.9e-57)
(* (pow (cos (* 0.005555555555555556 (* (PI) angle_m))) 2.0) (* b b))
(fma
(* (* 3.08641975308642e-5 (* (* a angle_m) angle_m)) (* (PI) (PI)))
a
(pow (* (cos (/ (* angle_m (PI)) -180.0)) b) 2.0))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.9 \cdot 10^{-57}:\\
\;\;\;\;{\cos \left(0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\_m\right)\right)}^{2} \cdot \left(b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(\left(a \cdot angle\_m\right) \cdot angle\_m\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), a, {\left(\cos \left(\frac{angle\_m \cdot \mathsf{PI}\left(\right)}{-180}\right) \cdot b\right)}^{2}\right)\\
\end{array}
\end{array}
if a < 1.8999999999999999e-57Initial program 81.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites46.0%
Taylor expanded in a around 0
*-commutativeN/A
unpow2N/A
associate-*l*N/A
sin-+PI/2-revN/A
metadata-evalN/A
distribute-lft-neg-inN/A
sin-+PI/2-revN/A
cos-neg-revN/A
sin-+PI/2-revN/A
metadata-evalN/A
distribute-lft-neg-inN/A
sin-+PI/2-revN/A
cos-neg-revN/A
Applied rewrites64.9%
if 1.8999999999999999e-57 < a Initial program 86.0%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6486.1
Applied rewrites86.1%
Applied rewrites86.1%
Taylor expanded in angle around 0
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f6483.8
Applied rewrites83.8%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= b 3.4e+26)
(fma
(* (* (- b a) (+ b a)) (* (* (* (PI) (PI)) -3.08641975308642e-5) angle_m))
angle_m
(* b b))
(* b b)))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.4 \cdot 10^{+26}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(b - a\right) \cdot \left(b + a\right)\right) \cdot \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -3.08641975308642 \cdot 10^{-5}\right) \cdot angle\_m\right), angle\_m, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 3.4000000000000003e26Initial program 84.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites49.2%
Applied rewrites55.8%
if 3.4000000000000003e26 < b Initial program 78.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6470.1
Applied rewrites70.1%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= a 9.4e+120) (* b b) (* (* 3.08641975308642e-5 (* (* (* a a) angle_m) angle_m)) (* (PI) (PI)))))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 9.4 \cdot 10^{+120}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(\left(\left(a \cdot a\right) \cdot angle\_m\right) \cdot angle\_m\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 9.39999999999999987e120Initial program 80.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6464.7
Applied rewrites64.7%
if 9.39999999999999987e120 < a Initial program 94.9%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites38.7%
Taylor expanded in a around inf
Applied rewrites55.4%
Taylor expanded in a around 0
Applied rewrites66.6%
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 = private
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, angle_m)
use fmin_fmax_functions
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 82.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.7
Applied rewrites60.7%
herbie shell --seed 2024354
(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)))