
(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
(let* ((t_0 (* (PI) angle_m)))
(if (<= angle_m 6.5e-25)
(fma
(* (* 0.005555555555555556 a) t_0)
(* 0.005555555555555556 (* t_0 a))
(* b b))
(fma
(* (- 0.5 (* 0.5 (cos (* 2.0 (* (PI) (/ angle_m 180.0)))))) a)
a
(* b b)))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot angle\_m\\
\mathbf{if}\;angle\_m \leq 6.5 \cdot 10^{-25}:\\
\;\;\;\;\mathsf{fma}\left(\left(0.005555555555555556 \cdot a\right) \cdot t\_0, 0.005555555555555556 \cdot \left(t\_0 \cdot a\right), b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(0.5 - 0.5 \cdot \cos \left(2 \cdot \left(\mathsf{PI}\left(\right) \cdot \frac{angle\_m}{180}\right)\right)\right) \cdot a, a, b \cdot b\right)\\
\end{array}
\end{array}
if angle < 6.5e-25Initial program 85.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6486.0
Applied rewrites86.0%
Taylor expanded in angle around 0
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6480.1
Applied rewrites80.1%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-fma.f6480.1
Applied rewrites80.1%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
lower-*.f6480.2
Applied rewrites80.2%
if 6.5e-25 < angle Initial program 58.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.3
Applied rewrites62.3%
lift-+.f64N/A
Applied rewrites62.3%
lift-pow.f64N/A
lift-sin.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
unpow2N/A
sqr-sin-aN/A
lower--.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-PI.f6462.3
Applied rewrites62.3%
Final simplification75.1%
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 77.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6479.2
Applied rewrites79.2%
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f6479.3
Applied rewrites79.3%
Final simplification79.3%
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 77.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6479.2
Applied rewrites79.2%
Final simplification79.2%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(let* ((t_0 (* (PI) angle_m)))
(if (<= a 1.6e-48)
(* b b)
(fma
(* (* 0.005555555555555556 a) t_0)
(* 0.005555555555555556 (* t_0 a))
(* b b)))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot angle\_m\\
\mathbf{if}\;a \leq 1.6 \cdot 10^{-48}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(0.005555555555555556 \cdot a\right) \cdot t\_0, 0.005555555555555556 \cdot \left(t\_0 \cdot a\right), b \cdot b\right)\\
\end{array}
\end{array}
if a < 1.5999999999999999e-48Initial program 76.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.9
Applied rewrites58.9%
if 1.5999999999999999e-48 < a Initial program 82.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6483.6
Applied rewrites83.6%
Taylor expanded in angle around 0
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6481.4
Applied rewrites81.4%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-fma.f6481.4
Applied rewrites81.4%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
lower-*.f6481.4
Applied rewrites81.4%
Final simplification65.6%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= a 1.6e-48)
(* b b)
(fma
(* 0.005555555555555556 (* (* (PI) angle_m) a))
(* 0.005555555555555556 (* (* a angle_m) (PI)))
(* b b))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.6 \cdot 10^{-48}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.005555555555555556 \cdot \left(\left(\mathsf{PI}\left(\right) \cdot angle\_m\right) \cdot a\right), 0.005555555555555556 \cdot \left(\left(a \cdot angle\_m\right) \cdot \mathsf{PI}\left(\right)\right), b \cdot b\right)\\
\end{array}
\end{array}
if a < 1.5999999999999999e-48Initial program 76.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.9
Applied rewrites58.9%
if 1.5999999999999999e-48 < a Initial program 82.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6483.6
Applied rewrites83.6%
Taylor expanded in angle around 0
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6481.4
Applied rewrites81.4%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-fma.f6481.4
Applied rewrites81.4%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6481.4
Applied rewrites81.4%
Final simplification65.6%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (let* ((t_0 (* (* (* (PI) angle_m) 0.005555555555555556) a))) (if (<= a 1.6e-48) (* b b) (fma t_0 t_0 (* b b)))))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := \left(\left(\mathsf{PI}\left(\right) \cdot angle\_m\right) \cdot 0.005555555555555556\right) \cdot a\\
\mathbf{if}\;a \leq 1.6 \cdot 10^{-48}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, t\_0, b \cdot b\right)\\
\end{array}
\end{array}
if a < 1.5999999999999999e-48Initial program 76.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.9
Applied rewrites58.9%
if 1.5999999999999999e-48 < a Initial program 82.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6483.6
Applied rewrites83.6%
Taylor expanded in angle around 0
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6481.4
Applied rewrites81.4%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-fma.f6481.4
Applied rewrites81.4%
Applied rewrites81.4%
Final simplification65.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 77.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6457.5
Applied rewrites57.5%
herbie shell --seed 2025038
(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)))