
(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 9 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 (/ 1.0 (pow (* (PI) angle_m) -0.5))))
(+
(pow (* a (sin (/ (* t_0 t_0) 180.0))) 2.0)
(pow (* b (cos (* (* 0.005555555555555556 angle_m) (PI)))) 2.0))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := \frac{1}{{\left(\mathsf{PI}\left(\right) \cdot angle\_m\right)}^{-0.5}}\\
{\left(a \cdot \sin \left(\frac{t\_0 \cdot t\_0}{180}\right)\right)}^{2} + {\left(b \cdot \cos \left(\left(0.005555555555555556 \cdot angle\_m\right) \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}
\end{array}
\end{array}
Initial program 79.2%
Taylor expanded in angle around 0
lower-*.f6479.2
Applied rewrites79.2%
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6479.2
Applied rewrites79.2%
*-commutativeN/A
unpow1N/A
metadata-evalN/A
pow-negN/A
lower-/.f64N/A
lower-pow.f64N/A
lower-*.f64N/A
lower-PI.f6479.2
Applied rewrites79.2%
metadata-evalN/A
sqr-powN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
metadata-eval40.4
Applied rewrites40.4%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (sin (/ (* (PI) angle_m) 180.0))) 2.0) (pow (* b (cos (* (* 0.005555555555555556 angle_m) (PI)))) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \sin \left(\frac{\mathsf{PI}\left(\right) \cdot angle\_m}{180}\right)\right)}^{2} + {\left(b \cdot \cos \left(\left(0.005555555555555556 \cdot angle\_m\right) \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}
\end{array}
Initial program 79.2%
Taylor expanded in angle around 0
lower-*.f6479.2
Applied rewrites79.2%
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6479.2
Applied rewrites79.2%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (let* ((t_0 (* (* 0.005555555555555556 angle_m) (PI)))) (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 := \left(0.005555555555555556 \cdot angle\_m\right) \cdot \mathsf{PI}\left(\right)\\
\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 79.2%
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
lower-/.f6439.3
Applied rewrites39.3%
Applied rewrites79.2%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (fma (+ 0.5 (* 0.5 (cos (* 2.0 (* (* 0.005555555555555556 angle_m) (PI)))))) (* b b) (pow (* (sin (* (PI) (/ angle_m 180.0))) a) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\mathsf{fma}\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(0.005555555555555556 \cdot angle\_m\right) \cdot \mathsf{PI}\left(\right)\right)\right), 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 79.2%
Taylor expanded in angle around 0
lower-*.f6479.2
Applied rewrites79.2%
+-commutativeN/A
*-commutativeN/A
unpow-prod-downN/A
lower-fma.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
Applied rewrites79.2%
unpow2N/A
sqr-cos-aN/A
lower-+.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
Applied rewrites79.2%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (sin (/ (* (PI) angle_m) 180.0))) 2.0) (* b b)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \sin \left(\frac{\mathsf{PI}\left(\right) \cdot angle\_m}{180}\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 79.2%
Taylor expanded in angle around 0
lower-*.f6479.2
Applied rewrites79.2%
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6479.2
Applied rewrites79.2%
Taylor expanded in angle around 0
*-commutativeN/A
*-commutativeN/A
pow2N/A
lower-*.f6479.1
Applied rewrites79.1%
Final simplification79.1%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (sin (* (/ angle_m 180.0) (PI)))) 2.0) (* b b)))
\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} + b \cdot b
\end{array}
Initial program 79.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6479.1
Applied rewrites79.1%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= b 7.8e-150) (pow (* (sin (* (* (PI) angle_m) 0.005555555555555556)) a) 2.0) (+ (pow (* (* (* angle_m (PI)) a) 0.005555555555555556) 2.0) (* b b))))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.8 \cdot 10^{-150}:\\
\;\;\;\;{\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot angle\_m\right) \cdot 0.005555555555555556\right) \cdot a\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\left(angle\_m \cdot \mathsf{PI}\left(\right)\right) \cdot a\right) \cdot 0.005555555555555556\right)}^{2} + b \cdot b\\
\end{array}
\end{array}
if b < 7.8000000000000004e-150Initial program 81.2%
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
lower-PI.f6447.5
Applied rewrites47.5%
if 7.8000000000000004e-150 < b Initial program 76.1%
Taylor expanded in angle around 0
lower-*.f6476.0
Applied rewrites76.0%
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6476.2
Applied rewrites76.2%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r/N/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6473.1
Applied rewrites73.1%
Taylor expanded in angle around 0
*-commutativeN/A
*-commutativeN/A
exp-to-powN/A
pow2N/A
lower-*.f6473.2
Applied rewrites73.2%
Final simplification57.6%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= a 3.6e-61) (* b b) (+ (pow (* (* (* angle_m (PI)) a) 0.005555555555555556) 2.0) (* b b))))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3.6 \cdot 10^{-61}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\left(angle\_m \cdot \mathsf{PI}\left(\right)\right) \cdot a\right) \cdot 0.005555555555555556\right)}^{2} + b \cdot b\\
\end{array}
\end{array}
if a < 3.60000000000000014e-61Initial program 79.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.7
Applied rewrites58.7%
if 3.60000000000000014e-61 < a Initial program 79.5%
Taylor expanded in angle around 0
lower-*.f6479.5
Applied rewrites79.5%
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6479.6
Applied rewrites79.6%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r/N/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6476.3
Applied rewrites76.3%
Taylor expanded in angle around 0
*-commutativeN/A
*-commutativeN/A
exp-to-powN/A
pow2N/A
lower-*.f6475.7
Applied rewrites75.7%
Final simplification62.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 79.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6455.0
Applied rewrites55.0%
herbie shell --seed 2025044
(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)))