
(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 (+ (pow (/ a (/ 1.0 (sin (* angle (/ (PI) 180.0))))) 2.0) (pow (* b (cos (/ (* (PI) angle) 180.0))) 2.0)))
\begin{array}{l}
\\
{\left(\frac{a}{\frac{1}{\sin \left(angle \cdot \frac{\mathsf{PI}\left(\right)}{180}\right)}}\right)}^{2} + {\left(b \cdot \cos \left(\frac{\mathsf{PI}\left(\right) \cdot angle}{180}\right)\right)}^{2}
\end{array}
Initial program 80.1%
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6480.1
Applied rewrites80.1%
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f6480.2
Applied rewrites80.2%
lift-*.f64N/A
lift-sin.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
associate-*r/N/A
unpow1N/A
metadata-evalN/A
pow-flipN/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-sin.f64N/A
lift-pow.f6480.2
Applied rewrites80.2%
lift-pow.f64N/A
lift-sin.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
unpow-1N/A
lower-/.f64N/A
associate-*l/N/A
*-commutativeN/A
lower-sin.f64N/A
associate-*l/N/A
lift-/.f64N/A
lift-PI.f64N/A
*-commutativeN/A
lower-*.f6480.2
Applied rewrites80.2%
Final simplification80.2%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (/ (PI) 180.0) angle))) 2.0) (pow (* b (cos (/ (* (PI) angle) 180.0))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\frac{\mathsf{PI}\left(\right)}{180} \cdot angle\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{\mathsf{PI}\left(\right) \cdot angle}{180}\right)\right)}^{2}
\end{array}
Initial program 80.1%
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6480.1
Applied rewrites80.1%
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f6480.2
Applied rewrites80.2%
lift-/.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
metadata-evalN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-/.f6480.2
Applied rewrites80.2%
Final simplification80.2%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (/ (* (PI) angle) 180.0))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right) \cdot angle}{180}\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos t\_0\right)}^{2}
\end{array}
\end{array}
Initial program 80.1%
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6480.1
Applied rewrites80.1%
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f6480.2
Applied rewrites80.2%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (/ angle 180.0) (PI)))) 2.0) (pow (* b (cos (/ (* (PI) angle) 180.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 \cos \left(\frac{\mathsf{PI}\left(\right) \cdot angle}{180}\right)\right)}^{2}
\end{array}
Initial program 80.1%
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6480.1
Applied rewrites80.1%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (* 0.005555555555555556 angle) (PI)))) 2.0) (pow (* b (cos (/ (* (PI) angle) 180.0))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{\mathsf{PI}\left(\right) \cdot angle}{180}\right)\right)}^{2}
\end{array}
Initial program 80.1%
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6480.1
Applied rewrites80.1%
Taylor expanded in angle around 0
lower-*.f6480.1
Applied rewrites80.1%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (* 0.005555555555555556 angle) (PI)))) 2.0) (pow (* b (cos (* (/ angle 180.0) (PI)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}
\end{array}
Initial program 80.1%
Taylor expanded in angle around 0
lower-*.f6480.1
Applied rewrites80.1%
(FPCore (a b angle) :precision binary64 (fma (+ 0.5 (* 0.5 (cos (* 2.0 (* (* 0.005555555555555556 angle) (PI)))))) (* b b) (pow (* (sin (* (/ angle 180.0) (PI))) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(0.5 + 0.5 \cdot \cos \left(2 \cdot \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right)\right), b \cdot b, {\left(\sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 80.1%
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
lift-pow.f64N/A
Applied rewrites72.0%
Taylor expanded in angle around 0
lower-*.f6471.9
Applied rewrites71.9%
Applied rewrites80.0%
lift-pow.f64N/A
unpow2N/A
lift-cos.f64N/A
lift-cos.f64N/A
sqr-cos-aN/A
lower-+.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6480.1
Applied rewrites80.1%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (/ (PI) 180.0) angle))) 2.0) (* b b)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\frac{\mathsf{PI}\left(\right)}{180} \cdot angle\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 80.1%
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6480.1
Applied rewrites80.1%
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f6480.2
Applied rewrites80.2%
lift-/.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
metadata-evalN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-/.f6480.2
Applied rewrites80.2%
Taylor expanded in angle around 0
pow2N/A
lift-*.f6479.9
Applied rewrites79.9%
Final simplification79.9%
(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 80.1%
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6480.1
Applied rewrites80.1%
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f6480.2
Applied rewrites80.2%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r/N/A
unpow2N/A
lower-*.f6479.9
Applied rewrites79.9%
Final simplification79.9%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* (/ angle 180.0) (PI)))) 2.0) (* b b)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 80.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6479.8
Applied rewrites79.8%
Final simplification79.8%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) angle)))
(if (<= b 2.4e-162)
(pow (* (sin (* t_0 0.005555555555555556)) a) 2.0)
(+ (* (pow (* t_0 a) 2.0) 3.08641975308642e-5) (* b b)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot angle\\
\mathbf{if}\;b \leq 2.4 \cdot 10^{-162}:\\
\;\;\;\;{\left(\sin \left(t\_0 \cdot 0.005555555555555556\right) \cdot a\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{\left(t\_0 \cdot a\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5} + b \cdot b\\
\end{array}
\end{array}
if b < 2.4000000000000002e-162Initial program 78.9%
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
lift-PI.f6446.6
Applied rewrites46.6%
if 2.4000000000000002e-162 < b Initial program 81.5%
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6481.6
Applied rewrites81.6%
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.7
Applied rewrites81.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
pow-prod-downN/A
pow-prod-downN/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6479.3
Applied rewrites79.3%
Taylor expanded in angle around 0
pow2N/A
lift-*.f6478.5
Applied rewrites78.5%
(FPCore (a b angle) :precision binary64 (if (<= a 2.4e-104) (* b b) (+ (* (pow (* (* (PI) angle) a) 2.0) 3.08641975308642e-5) (* b b))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.4 \cdot 10^{-104}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot a\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5} + b \cdot b\\
\end{array}
\end{array}
if a < 2.4000000000000001e-104Initial program 80.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6464.8
Applied rewrites64.8%
if 2.4000000000000001e-104 < a Initial program 80.2%
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6480.4
Applied rewrites80.4%
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f6480.5
Applied rewrites80.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
pow-prod-downN/A
pow-prod-downN/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6476.7
Applied rewrites76.7%
Taylor expanded in angle around 0
pow2N/A
lift-*.f6475.5
Applied rewrites75.5%
(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.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6457.1
Applied rewrites57.1%
herbie shell --seed 2025051
(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)))