
(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}
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (/ (* (PI) angle) 180.0))) 2.0) (* b b)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\frac{\mathsf{PI}\left(\right) \cdot angle}{180}\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 81.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6481.2
Applied rewrites81.2%
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f6481.3
Applied rewrites81.3%
Final simplification81.3%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (* 0.005555555555555556 angle) (PI)))) 2.0) (* b b)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 81.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6481.2
Applied rewrites81.2%
Taylor expanded in angle around 0
lower-*.f6481.3
Applied rewrites81.3%
Final simplification81.3%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) angle)))
(if (<= angle 0.0045)
(fma
(* (* (* (PI) 0.005555555555555556) angle) a)
(* (* 0.005555555555555556 t_0) a)
(* b b))
(fma (- 0.5 (* 0.5 (cos (* 2.0 (/ t_0 180.0))))) (* a a) (* b b)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot angle\\
\mathbf{if}\;angle \leq 0.0045:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right) \cdot a, \left(0.005555555555555556 \cdot t\_0\right) \cdot a, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 - 0.5 \cdot \cos \left(2 \cdot \frac{t\_0}{180}\right), a \cdot a, b \cdot b\right)\\
\end{array}
\end{array}
if angle < 0.00449999999999999966Initial program 85.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6486.0
Applied rewrites86.0%
Taylor expanded in angle around 0
associate-*l/N/A
*-commutativeN/A
associate-*r/N/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lower-*.f6483.6
Applied rewrites83.6%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-fma.f6483.6
Applied rewrites83.5%
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6483.6
Applied rewrites83.6%
if 0.00449999999999999966 < angle Initial program 67.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6467.3
Applied rewrites67.3%
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
unpow-prod-downN/A
lower-fma.f64N/A
Applied rewrites67.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
associate-*r/N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f6467.1
Applied rewrites67.1%
Final simplification79.4%
(FPCore (a b angle)
:precision binary64
(if (<= angle 0.0045)
(fma
(* (* (* (PI) 0.005555555555555556) angle) a)
(* (* 0.005555555555555556 (* (PI) angle)) a)
(* b b))
(fma
(- 0.5 (* 0.5 (cos (* 2.0 (* (PI) (* 0.005555555555555556 angle))))))
(* a a)
(* b b))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;angle \leq 0.0045:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right) \cdot a, \left(0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\right)\right) \cdot a, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 - 0.5 \cdot \cos \left(2 \cdot \left(\mathsf{PI}\left(\right) \cdot \left(0.005555555555555556 \cdot angle\right)\right)\right), a \cdot a, b \cdot b\right)\\
\end{array}
\end{array}
if angle < 0.00449999999999999966Initial program 85.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6486.0
Applied rewrites86.0%
Taylor expanded in angle around 0
associate-*l/N/A
*-commutativeN/A
associate-*r/N/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lower-*.f6483.6
Applied rewrites83.6%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-fma.f6483.6
Applied rewrites83.5%
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6483.6
Applied rewrites83.6%
if 0.00449999999999999966 < angle Initial program 67.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6467.3
Applied rewrites67.3%
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
unpow-prod-downN/A
lower-fma.f64N/A
Applied rewrites67.3%
Taylor expanded in angle around 0
lower-*.f6467.3
Applied rewrites67.3%
lift-pow.f64N/A
unpow2N/A
lift-sin.f64N/A
lift-sin.f64N/A
sqr-sin-aN/A
lower--.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6467.0
Applied rewrites67.0%
Final simplification79.4%
(FPCore (a b angle) :precision binary64 (fma (* (* (* (PI) 0.005555555555555556) angle) a) (* (* 0.005555555555555556 (* (PI) angle)) a) (* b b)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right) \cdot a, \left(0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\right)\right) \cdot a, b \cdot b\right)
\end{array}
Initial program 81.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6481.2
Applied rewrites81.2%
Taylor expanded in angle around 0
associate-*l/N/A
*-commutativeN/A
associate-*r/N/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lower-*.f6477.9
Applied rewrites77.9%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-fma.f6477.9
Applied rewrites77.8%
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6477.9
Applied rewrites77.9%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (* (* (PI) angle) a) 0.005555555555555556))) (fma t_0 t_0 (* b b))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot a\right) \cdot 0.005555555555555556\\
\mathsf{fma}\left(t\_0, t\_0, b \cdot b\right)
\end{array}
\end{array}
Initial program 81.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6481.2
Applied rewrites81.2%
Taylor expanded in angle around 0
associate-*l/N/A
*-commutativeN/A
associate-*r/N/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lower-*.f6477.9
Applied rewrites77.9%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-fma.f6477.9
Applied rewrites77.8%
Applied rewrites77.9%
Final simplification77.9%
(FPCore (a b angle) :precision binary64 (* b b))
double code(double a, double b, double angle) {
return b * b;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = b * b
end function
public static double code(double a, double b, double angle) {
return b * b;
}
def code(a, b, angle): return b * b
function code(a, b, angle) return Float64(b * b) end
function tmp = code(a, b, angle) tmp = b * b; end
code[a_, b_, angle_] := N[(b * b), $MachinePrecision]
\begin{array}{l}
\\
b \cdot b
\end{array}
Initial program 81.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.5
Applied rewrites61.5%
herbie shell --seed 2025050
(FPCore (a b angle)
:name "ab-angle->ABCF A"
:precision binary64
:pre (TRUE)
(+ (pow (* a (sin (* (/ angle 180.0) (PI)))) 2.0) (pow (* b (cos (* (/ angle 180.0) (PI)))) 2.0)))