
(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 14 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 (* (/ angle 180.0) (cbrt (* (* (PI) (PI)) (PI)))))) 2.0) (pow (* b (sin (* (PI) (fma 0.005555555555555556 angle 0.5)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\frac{angle}{180} \cdot \sqrt[3]{\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(0.005555555555555556, angle, 0.5\right)\right)\right)}^{2}
\end{array}
Initial program 82.2%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
remove-double-negN/A
remove-double-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-PI.f64N/A
lower-/.f6482.3
Applied rewrites82.3%
lift-PI.f64N/A
add-cbrt-cubeN/A
lower-cbrt.f64N/A
rem-cube-cbrtN/A
add-cbrt-cubeN/A
lift-PI.f64N/A
lower-pow.f6482.3
Applied rewrites82.3%
lift-pow.f64N/A
unpow3N/A
lift-*.f64N/A
lower-*.f6482.3
Applied rewrites82.3%
Taylor expanded in angle around inf
lower-sin.f64N/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-PI.f64N/A
lower-fma.f6482.3
Applied rewrites82.3%
Final simplification82.3%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (/ angle 180.0) (PI)))) 2.0) (pow (* b (sin (* (PI) (fma 0.005555555555555556 angle 0.5)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(0.005555555555555556, angle, 0.5\right)\right)\right)}^{2}
\end{array}
Initial program 82.2%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
remove-double-negN/A
remove-double-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-PI.f64N/A
lower-/.f6482.3
Applied rewrites82.3%
Taylor expanded in angle around inf
lower-sin.f64N/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-PI.f64N/A
lower-fma.f6482.3
Applied rewrites82.3%
Final simplification82.3%
(FPCore (a b angle) :precision binary64 (fma (* (- 0.5 (* 0.5 (cos (* 2.0 (fma (/ angle -180.0) (PI) (/ (PI) 2.0)))))) b) b (pow (* (sin (* (PI) (/ angle 180.0))) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(0.5 - 0.5 \cdot \cos \left(2 \cdot \mathsf{fma}\left(\frac{angle}{-180}, \mathsf{PI}\left(\right), \frac{\mathsf{PI}\left(\right)}{2}\right)\right)\right) \cdot b, b, {\left(\sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 82.2%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites82.1%
Applied rewrites82.3%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* angle (PI))))
(fma
(- 0.5 (* 0.5 (cos (* 2.0 (fma t_0 -0.005555555555555556 (/ (PI) 2.0))))))
(* b b)
(pow (* (sin (* 0.005555555555555556 t_0)) a) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := angle \cdot \mathsf{PI}\left(\right)\\
\mathsf{fma}\left(0.5 - 0.5 \cdot \cos \left(2 \cdot \mathsf{fma}\left(t\_0, -0.005555555555555556, \frac{\mathsf{PI}\left(\right)}{2}\right)\right), b \cdot b, {\left(\sin \left(0.005555555555555556 \cdot t\_0\right) \cdot a\right)}^{2}\right)
\end{array}
\end{array}
Initial program 82.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6456.6
Applied rewrites56.6%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites71.3%
Applied rewrites71.4%
Applied rewrites82.2%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (/ angle 180.0) (PI)))) 2.0) (pow (* b 1.0) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {\left(b \cdot 1\right)}^{2}
\end{array}
Initial program 82.2%
Taylor expanded in angle around 0
Applied rewrites81.0%
(FPCore (a b angle)
:precision binary64
(if (<= angle 7e-146)
(* b b)
(fma
1.0
(* b b)
(* (pow (sin (* (* (PI) angle) 0.005555555555555556)) 2.0) (* a a)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;angle \leq 7 \cdot 10^{-146}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, b \cdot b, {\sin \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right)}^{2} \cdot \left(a \cdot a\right)\right)\\
\end{array}
\end{array}
if angle < 7.0000000000000003e-146Initial program 83.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6456.1
Applied rewrites56.1%
if 7.0000000000000003e-146 < angle Initial program 80.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6457.4
Applied rewrites57.4%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites79.4%
Taylor expanded in angle around 0
Applied rewrites77.7%
(FPCore (a b angle) :precision binary64 (fma (* 1.0 b) b (pow (* (sin (* (PI) (/ angle 180.0))) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(1 \cdot b, b, {\left(\sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 82.2%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites82.1%
Taylor expanded in angle around 0
Applied rewrites81.0%
(FPCore (a b angle)
:precision binary64
(if (<= b 1.16e+91)
(fma
(* (* (- b a) (+ b a)) (* (* (* (PI) (PI)) -3.08641975308642e-5) angle))
angle
(* b b))
(* (pow (sin (* (PI) (fma 0.005555555555555556 angle 0.5))) 2.0) (* b b))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.16 \cdot 10^{+91}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(b - a\right) \cdot \left(b + a\right)\right) \cdot \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -3.08641975308642 \cdot 10^{-5}\right) \cdot angle\right), angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;{\sin \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(0.005555555555555556, angle, 0.5\right)\right)}^{2} \cdot \left(b \cdot b\right)\\
\end{array}
\end{array}
if b < 1.1600000000000001e91Initial program 80.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.5%
Applied rewrites51.1%
if 1.1600000000000001e91 < b Initial program 90.6%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
remove-double-negN/A
remove-double-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-PI.f64N/A
lower-/.f6491.1
Applied rewrites91.1%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-PI.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6483.7
Applied rewrites83.7%
Final simplification57.5%
(FPCore (a b angle)
:precision binary64
(if (<= b 1.16e+91)
(fma
(* (* (- b a) (+ b a)) (* (* (* (PI) (PI)) -3.08641975308642e-5) angle))
angle
(* b b))
(* (pow (cos (* -0.005555555555555556 (* (PI) angle))) 2.0) (* b b))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.16 \cdot 10^{+91}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(b - a\right) \cdot \left(b + a\right)\right) \cdot \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -3.08641975308642 \cdot 10^{-5}\right) \cdot angle\right), angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;{\cos \left(-0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\right)\right)}^{2} \cdot \left(b \cdot b\right)\\
\end{array}
\end{array}
if b < 1.1600000000000001e91Initial program 80.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.5%
Applied rewrites51.1%
if 1.1600000000000001e91 < b Initial program 90.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6481.7
Applied rewrites81.7%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f6483.2
Applied rewrites83.2%
(FPCore (a b angle)
:precision binary64
(if (<= b 8.8e-163)
(* (* (* (* (* a a) 3.08641975308642e-5) angle) (* angle (PI))) (PI))
(if (<= b 9.8e+122)
(fma
(* (* (* 3.08641975308642e-5 (* (PI) (PI))) a) a)
(* angle angle)
(* b b))
(* b b))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8.8 \cdot 10^{-163}:\\
\;\;\;\;\left(\left(\left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot angle\right) \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{elif}\;b \leq 9.8 \cdot 10^{+122}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot a\right) \cdot a, angle \cdot angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 8.80000000000000044e-163Initial program 80.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites39.4%
Taylor expanded in a around inf
Applied rewrites34.0%
Applied rewrites40.0%
if 8.80000000000000044e-163 < b < 9.7999999999999995e122Initial program 79.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites57.0%
Taylor expanded in a around inf
Applied rewrites58.2%
if 9.7999999999999995e122 < b Initial program 90.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6486.8
Applied rewrites86.8%
(FPCore (a b angle)
:precision binary64
(if (<= b 7e+122)
(fma
(* (* (- b a) (+ b a)) (* (* (* (PI) (PI)) -3.08641975308642e-5) angle))
angle
(* b b))
(* b b)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{+122}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(b - a\right) \cdot \left(b + a\right)\right) \cdot \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -3.08641975308642 \cdot 10^{-5}\right) \cdot angle\right), angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 7.00000000000000028e122Initial program 80.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.7%
Applied rewrites51.1%
if 7.00000000000000028e122 < b Initial program 90.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6486.8
Applied rewrites86.8%
(FPCore (a b angle) :precision binary64 (if (<= a 1.1e+160) (* b b) (* (* (* (* (* a a) 3.08641975308642e-5) angle) (* angle (PI))) (PI))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.1 \cdot 10^{+160}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot angle\right) \cdot \left(angle \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \mathsf{PI}\left(\right)\\
\end{array}
\end{array}
if a < 1.09999999999999996e160Initial program 79.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.2
Applied rewrites62.2%
if 1.09999999999999996e160 < a Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites60.8%
Taylor expanded in a around inf
Applied rewrites69.9%
Applied rewrites76.7%
(FPCore (a b angle) :precision binary64 (if (<= a 1.25e+160) (* b b) (* (* 3.08641975308642e-5 (* a a)) (* (* (* angle angle) (PI)) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.25 \cdot 10^{+160}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot a\right)\right) \cdot \left(\left(\left(angle \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 1.25e160Initial program 79.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.2
Applied rewrites62.2%
if 1.25e160 < a Initial program 99.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites60.8%
Taylor expanded in a around inf
Applied rewrites69.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 82.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6456.6
Applied rewrites56.6%
herbie shell --seed 2025005
(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)))