
(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 7 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 (* a (sin (* (* (PI) angle_m) 0.005555555555555556))) 2.0) (pow (* b (sin (fma (PI) (* 0.005555555555555556 angle_m) (/ (PI) 2.0)))) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot angle\_m\right) \cdot 0.005555555555555556\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{fma}\left(\mathsf{PI}\left(\right), 0.005555555555555556 \cdot angle\_m, \frac{\mathsf{PI}\left(\right)}{2}\right)\right)\right)}^{2}
\end{array}
Initial program 78.3%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-PI.f64N/A
lower-/.f64N/A
lift-PI.f6478.7
Applied rewrites78.7%
Taylor expanded in angle around 0
lower-*.f6478.6
Applied rewrites78.6%
Taylor expanded in angle around inf
lower-sin.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
*-commutativeN/A
lift-*.f6478.7
Applied rewrites78.7%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (fma (pow (cos (* (PI) (* 0.005555555555555556 angle_m))) 2.0) (* b b) (pow (* (sin (* (PI) (/ angle_m 180.0))) a) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\mathsf{fma}\left({\cos \left(\mathsf{PI}\left(\right) \cdot \left(0.005555555555555556 \cdot angle\_m\right)\right)}^{2}, b \cdot b, {\left(\sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle\_m}{180}\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 78.3%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-PI.f64N/A
lower-/.f64N/A
lift-PI.f6478.7
Applied rewrites78.7%
Taylor expanded in angle around 0
lower-*.f6478.6
Applied rewrites78.6%
lift-+.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
Applied rewrites78.6%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (sin (* (* (PI) angle_m) 0.005555555555555556))) 2.0) (* b b)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot angle\_m\right) \cdot 0.005555555555555556\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 78.3%
lift-pow.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
Applied rewrites34.8%
Taylor expanded in angle around inf
lower-sin.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
*-commutativeN/A
lift-*.f6434.8
Applied rewrites34.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6478.6
Applied rewrites78.6%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= b 1.2e-156)
(pow (* (sin (* (* (PI) angle_m) 0.005555555555555556)) a) 2.0)
(if (<= b 1.8e+72)
(fma
(* (pow (* (PI) a) 2.0) 3.08641975308642e-5)
(* angle_m angle_m)
(* b b))
(pow
(fma (* -1.54320987654321e-5 (* angle_m angle_m)) (* (* (PI) (PI)) b) b)
2.0))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.2 \cdot 10^{-156}:\\
\;\;\;\;{\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot angle\_m\right) \cdot 0.005555555555555556\right) \cdot a\right)}^{2}\\
\mathbf{elif}\;b \leq 1.8 \cdot 10^{+72}:\\
\;\;\;\;\mathsf{fma}\left({\left(\mathsf{PI}\left(\right) \cdot a\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}, angle\_m \cdot angle\_m, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{fma}\left(-1.54320987654321 \cdot 10^{-5} \cdot \left(angle\_m \cdot angle\_m\right), \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b, b\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 1.2e-156Initial program 75.5%
Taylor expanded in a around inf
pow-prod-downN/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6438.2
Applied rewrites38.2%
if 1.2e-156 < b < 1.80000000000000017e72Initial program 70.9%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites63.3%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
lift-*.f64N/A
lift-PI.f64N/A
lift-pow.f6464.3
Applied rewrites64.3%
if 1.80000000000000017e72 < b Initial program 91.6%
Taylor expanded in a around 0
pow-prod-downN/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6484.9
Applied rewrites84.9%
Taylor expanded in angle around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lift-PI.f64N/A
lift-PI.f6486.6
Applied rewrites86.6%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= a 4.4e-56)
(* b b)
(if (<= a 4e+153)
(fma
(* (pow (* (PI) a) 2.0) 3.08641975308642e-5)
(* angle_m angle_m)
(* b b))
(* (pow (* (* (PI) angle_m) a) 2.0) 3.08641975308642e-5))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.4 \cdot 10^{-56}:\\
\;\;\;\;b \cdot b\\
\mathbf{elif}\;a \leq 4 \cdot 10^{+153}:\\
\;\;\;\;\mathsf{fma}\left({\left(\mathsf{PI}\left(\right) \cdot a\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}, angle\_m \cdot angle\_m, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\mathsf{PI}\left(\right) \cdot angle\_m\right) \cdot a\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if a < 4.40000000000000008e-56Initial program 75.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.5
Applied rewrites63.5%
if 4.40000000000000008e-56 < a < 4e153Initial program 74.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites31.4%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
lift-*.f64N/A
lift-PI.f64N/A
lift-pow.f6466.1
Applied rewrites66.1%
if 4e153 < a Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.7%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
pow-prod-downN/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
pow-prod-downN/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-pow.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
*-commutativeN/A
lower-*.f6477.9
Applied rewrites77.9%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= a 7.5e+141) (* b b) (* (pow (* (* (PI) angle_m) a) 2.0) 3.08641975308642e-5)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.5 \cdot 10^{+141}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\mathsf{PI}\left(\right) \cdot angle\_m\right) \cdot a\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if a < 7.49999999999999937e141Initial program 74.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.4
Applied rewrites63.4%
if 7.49999999999999937e141 < a Initial program 97.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites39.7%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
pow-prod-downN/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
pow-prod-downN/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-pow.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
*-commutativeN/A
lower-*.f6477.9
Applied rewrites77.9%
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 78.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6459.1
Applied rewrites59.1%
herbie shell --seed 2025056
(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)))