
(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 13 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
(let* ((t_0 (pow (PI) 0.08333333333333333)))
(+
(pow (* a (sin (* (* (PI) 0.005555555555555556) angle))) 2.0)
(pow
(*
b
(cos (/ (* t_0 (* t_0 (* (pow (PI) 0.8333333333333334) angle))) 180.0)))
2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\mathsf{PI}\left(\right)}^{0.08333333333333333}\\
{\left(a \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{t\_0 \cdot \left(t\_0 \cdot \left({\mathsf{PI}\left(\right)}^{0.8333333333333334} \cdot angle\right)\right)}{180}\right)\right)}^{2}
\end{array}
\end{array}
Initial program 80.4%
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.f6480.5
Applied rewrites80.5%
Applied rewrites80.5%
lift-*.f64N/A
lift-pow.f64N/A
sqr-powN/A
associate-*l*N/A
lower-*.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f64N/A
metadata-eval80.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6480.5
Applied rewrites80.5%
(FPCore (a b angle)
:precision binary64
(+
(pow (* a (sin (* (* (PI) 0.005555555555555556) angle))) 2.0)
(pow
(*
b
(cos
(/
(*
(pow (PI) 0.16666666666666666)
(* angle (pow (PI) 0.8333333333333334)))
180.0)))
2.0)))\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{{\mathsf{PI}\left(\right)}^{0.16666666666666666} \cdot \left(angle \cdot {\mathsf{PI}\left(\right)}^{0.8333333333333334}\right)}{180}\right)\right)}^{2}
\end{array}
Initial program 80.4%
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.f6480.5
Applied rewrites80.5%
Applied rewrites80.5%
(FPCore (a b angle) :precision binary64 (fma (* (pow (cos (* (/ angle 180.0) (PI))) 2.0) b) b (pow (* (sin (* (* 0.005555555555555556 (PI)) angle)) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left({\cos \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)}^{2} \cdot b, b, {\left(\sin \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 80.4%
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.f6480.5
Applied rewrites80.5%
Applied rewrites80.5%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (* (PI) 0.005555555555555556) angle))) 2.0) (pow (* b (cos (* (/ angle 180.0) (PI)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}
\end{array}
Initial program 80.4%
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.f6480.5
Applied rewrites80.5%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (* (PI) 0.005555555555555556) angle))) 2.0) (pow (* b (cos (* -0.005555555555555556 (* (PI) angle)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)\right)}^{2} + {\left(b \cdot \cos \left(-0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\right)\right)\right)}^{2}
\end{array}
Initial program 80.4%
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.f6480.5
Applied rewrites80.5%
Applied rewrites80.5%
lift-*.f64N/A
lift-pow.f64N/A
sqr-powN/A
associate-*l*N/A
lower-*.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f64N/A
metadata-eval80.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6480.5
Applied rewrites80.5%
Taylor expanded in angle around inf
cos-neg-revN/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6480.3
Applied rewrites80.3%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (* (PI) 0.005555555555555556) angle))) 2.0) (pow (* b 1.0) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)\right)}^{2} + {\left(b \cdot 1\right)}^{2}
\end{array}
Initial program 80.4%
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.f6480.5
Applied rewrites80.5%
Taylor expanded in angle around 0
Applied rewrites79.6%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) (PI))))
(if (<= b 1.05e-128)
(* (* (* (* 3.08641975308642e-5 a) angle) (* a angle)) t_0)
(fma
(* (* 3.08641975308642e-5 (* (* angle angle) a)) t_0)
a
(pow (* (cos (* (PI) (/ angle 180.0))) b) 2.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;b \leq 1.05 \cdot 10^{-128}:\\
\;\;\;\;\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot angle\right) \cdot \left(a \cdot angle\right)\right) \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(\left(angle \cdot angle\right) \cdot a\right)\right) \cdot t\_0, a, {\left(\cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right) \cdot b\right)}^{2}\right)\\
\end{array}
\end{array}
if b < 1.0500000000000001e-128Initial program 80.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.3%
Taylor expanded in a around inf
Applied rewrites43.0%
Applied rewrites48.1%
if 1.0500000000000001e-128 < b Initial program 80.0%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites76.4%
Taylor expanded in angle around 0
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f6474.2
Applied rewrites74.2%
(FPCore (a b angle) :precision binary64 (if (<= a 2.9e+72) (* (pow (cos (* (* (PI) 0.005555555555555556) angle)) 2.0) (* b b)) (* (* (* (* 3.08641975308642e-5 a) angle) (* a angle)) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.9 \cdot 10^{+72}:\\
\;\;\;\;{\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right)}^{2} \cdot \left(b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot angle\right) \cdot \left(a \cdot angle\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 2.90000000000000017e72Initial program 77.5%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f6462.4
Applied rewrites62.4%
if 2.90000000000000017e72 < a Initial program 90.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.4%
Taylor expanded in a around inf
Applied rewrites61.7%
Applied rewrites74.1%
(FPCore (a b angle) :precision binary64 (if (<= a 2.9e+72) (* b b) (* (* (* (* 3.08641975308642e-5 a) angle) (* a angle)) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.9 \cdot 10^{+72}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot angle\right) \cdot \left(a \cdot angle\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 2.90000000000000017e72Initial program 77.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.5
Applied rewrites61.5%
if 2.90000000000000017e72 < a Initial program 90.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.4%
Taylor expanded in a around inf
Applied rewrites61.7%
Applied rewrites74.1%
(FPCore (a b angle) :precision binary64 (if (<= a 2.9e+72) (* b b) (* (* 3.08641975308642e-5 (* (* a angle) (* a angle))) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.9 \cdot 10^{+72}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(\left(a \cdot angle\right) \cdot \left(a \cdot angle\right)\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 2.90000000000000017e72Initial program 77.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.5
Applied rewrites61.5%
if 2.90000000000000017e72 < a Initial program 90.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.4%
Taylor expanded in a around inf
Applied rewrites61.7%
Applied rewrites74.0%
(FPCore (a b angle) :precision binary64 (if (<= a 2.9e+72) (* b b) (* (* 3.08641975308642e-5 (* a (* (* a angle) angle))) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.9 \cdot 10^{+72}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot \left(\left(a \cdot angle\right) \cdot angle\right)\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 2.90000000000000017e72Initial program 77.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.5
Applied rewrites61.5%
if 2.90000000000000017e72 < a Initial program 90.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.4%
Taylor expanded in a around inf
Applied rewrites61.7%
Applied rewrites70.6%
(FPCore (a b angle) :precision binary64 (if (<= a 2.9e+72) (* b b) (* (* 3.08641975308642e-5 (* (* (* a a) angle) angle)) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.9 \cdot 10^{+72}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(\left(\left(a \cdot a\right) \cdot angle\right) \cdot angle\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 2.90000000000000017e72Initial program 77.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.5
Applied rewrites61.5%
if 2.90000000000000017e72 < a Initial program 90.8%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.4%
Taylor expanded in a around inf
Applied rewrites61.7%
Taylor expanded in a around 0
Applied rewrites66.8%
(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 80.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6454.4
Applied rewrites54.4%
herbie shell --seed 2024360
(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)))