
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (PI) (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (PI) (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* (sin (fma (* (PI) angle_m) 0.005555555555555556 (* 0.5 (PI)))) a) 2.0) (pow (* (sin (* (* 0.005555555555555556 angle_m) (PI))) b) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(\sin \left(\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot angle\_m, 0.005555555555555556, 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot a\right)}^{2} + {\left(\sin \left(\left(0.005555555555555556 \cdot angle\_m\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}
\end{array}
Initial program 79.5%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-PI.f64N/A
lower-/.f64N/A
lift-PI.f6479.7
Applied rewrites79.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6479.7
Applied rewrites79.7%
Taylor expanded in a around 0
lower-+.f64N/A
Applied rewrites79.8%
Final simplification79.8%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= b 1.15e-50)
(pow
(* (sin (fma 0.5 (PI) (* (* (PI) angle_m) 0.005555555555555556))) a)
2.0)
(if (<= b 4.4e+153)
(fma
(* (pow (* (PI) b) 2.0) 3.08641975308642e-5)
(* angle_m angle_m)
(* a a))
(* (* (pow (* angle_m b) 2.0) (* (PI) (PI))) 3.08641975308642e-5))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.15 \cdot 10^{-50}:\\
\;\;\;\;{\left(\sin \left(\mathsf{fma}\left(0.5, \mathsf{PI}\left(\right), \left(\mathsf{PI}\left(\right) \cdot angle\_m\right) \cdot 0.005555555555555556\right)\right) \cdot a\right)}^{2}\\
\mathbf{elif}\;b \leq 4.4 \cdot 10^{+153}:\\
\;\;\;\;\mathsf{fma}\left({\left(\mathsf{PI}\left(\right) \cdot b\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}, angle\_m \cdot angle\_m, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\left({\left(angle\_m \cdot b\right)}^{2} \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 1.1500000000000001e-50Initial program 80.4%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-PI.f64N/A
lower-/.f64N/A
lift-PI.f6480.6
Applied rewrites80.6%
Taylor expanded in a around inf
pow-prod-downN/A
lower-pow.f64N/A
Applied rewrites62.6%
if 1.1500000000000001e-50 < b < 4.3999999999999999e153Initial program 67.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites23.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
lift-*.f64N/A
lift-PI.f64N/A
lift-pow.f6462.5
Applied rewrites62.5%
if 4.3999999999999999e153 < b Initial program 90.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites52.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
pow-prod-downN/A
*-commutativeN/A
lower-pow.f64N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f6480.3
Applied rewrites80.3%
lift-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
unpow-prod-downN/A
unpow-prod-downN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lift-PI.f64N/A
lift-PI.f6480.4
Applied rewrites80.4%
Final simplification64.6%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (* a a) (pow (* b (sin (* (PI) (* 0.005555555555555556 angle_m)))) 2.0)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
a \cdot a + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(0.005555555555555556 \cdot angle\_m\right)\right)\right)}^{2}
\end{array}
Initial program 79.5%
Taylor expanded in angle around 0
lower-*.f6479.6
Applied rewrites79.6%
Taylor expanded in angle around 0
sin-+PI/2-revN/A
pow2N/A
lift-*.f6479.2
Applied rewrites79.2%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= b 1.15e-50)
(pow (* (cos (* (* (PI) angle_m) 0.005555555555555556)) a) 2.0)
(if (<= b 4.4e+153)
(fma
(* (pow (* (PI) b) 2.0) 3.08641975308642e-5)
(* angle_m angle_m)
(* a a))
(* (* (pow (* angle_m b) 2.0) (* (PI) (PI))) 3.08641975308642e-5))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.15 \cdot 10^{-50}:\\
\;\;\;\;{\left(\cos \left(\left(\mathsf{PI}\left(\right) \cdot angle\_m\right) \cdot 0.005555555555555556\right) \cdot a\right)}^{2}\\
\mathbf{elif}\;b \leq 4.4 \cdot 10^{+153}:\\
\;\;\;\;\mathsf{fma}\left({\left(\mathsf{PI}\left(\right) \cdot b\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}, angle\_m \cdot angle\_m, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\left({\left(angle\_m \cdot b\right)}^{2} \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 1.1500000000000001e-50Initial program 80.4%
Taylor expanded in a around inf
pow-prod-downN/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6462.4
Applied rewrites62.4%
if 1.1500000000000001e-50 < b < 4.3999999999999999e153Initial program 67.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites23.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
lift-*.f64N/A
lift-PI.f64N/A
lift-pow.f6462.5
Applied rewrites62.5%
if 4.3999999999999999e153 < b Initial program 90.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites52.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
pow-prod-downN/A
*-commutativeN/A
lower-pow.f64N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f6480.3
Applied rewrites80.3%
lift-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
unpow-prod-downN/A
unpow-prod-downN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lift-PI.f64N/A
lift-PI.f6480.4
Applied rewrites80.4%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= b 1.65e-50)
(* a a)
(if (<= b 4.4e+153)
(fma
(* (pow (* (PI) b) 2.0) 3.08641975308642e-5)
(* angle_m angle_m)
(* a a))
(* (* (pow (* angle_m b) 2.0) (* (PI) (PI))) 3.08641975308642e-5))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.65 \cdot 10^{-50}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 4.4 \cdot 10^{+153}:\\
\;\;\;\;\mathsf{fma}\left({\left(\mathsf{PI}\left(\right) \cdot b\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}, angle\_m \cdot angle\_m, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\left({\left(angle\_m \cdot b\right)}^{2} \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 1.6499999999999999e-50Initial program 80.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.1
Applied rewrites62.1%
if 1.6499999999999999e-50 < b < 4.3999999999999999e153Initial program 67.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites23.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
lift-*.f64N/A
lift-PI.f64N/A
lift-pow.f6462.5
Applied rewrites62.5%
if 4.3999999999999999e153 < b Initial program 90.0%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites52.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
pow-prod-downN/A
*-commutativeN/A
lower-pow.f64N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f6480.3
Applied rewrites80.3%
lift-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
unpow-prod-downN/A
unpow-prod-downN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lift-PI.f64N/A
lift-PI.f6480.4
Applied rewrites80.4%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= b 2.85e+170) (* a a) (* (* (pow (* angle_m b) 2.0) (* (PI) (PI))) 3.08641975308642e-5)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.85 \cdot 10^{+170}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left({\left(angle\_m \cdot b\right)}^{2} \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 2.84999999999999984e170Initial program 77.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.6
Applied rewrites61.6%
if 2.84999999999999984e170 < b Initial program 95.9%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites57.9%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
pow-prod-downN/A
*-commutativeN/A
lower-pow.f64N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f6485.0
Applied rewrites85.0%
lift-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
unpow-prod-downN/A
unpow-prod-downN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lift-PI.f64N/A
lift-PI.f6485.0
Applied rewrites85.0%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (let* ((t_0 (* (* b (PI)) angle_m))) (if (<= b 2.85e+170) (* a a) (* t_0 (* t_0 3.08641975308642e-5)))))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := \left(b \cdot \mathsf{PI}\left(\right)\right) \cdot angle\_m\\
\mathbf{if}\;b \leq 2.85 \cdot 10^{+170}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(t\_0 \cdot 3.08641975308642 \cdot 10^{-5}\right)\\
\end{array}
\end{array}
if b < 2.84999999999999984e170Initial program 77.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.6
Applied rewrites61.6%
if 2.84999999999999984e170 < b Initial program 95.9%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites57.9%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow-prod-downN/A
pow-prod-downN/A
*-commutativeN/A
lower-pow.f64N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f6485.0
Applied rewrites85.0%
lift-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
unpow2N/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6485.0
Applied rewrites85.0%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-*.f6485.0
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6485.0
Applied rewrites85.0%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (* a a))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return a * a;
}
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 = a * a
end function
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return a * a;
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return a * a
angle_m = abs(angle) function code(a, b, angle_m) return Float64(a * a) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = a * a; end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(a * a), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
a \cdot a
\end{array}
Initial program 79.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.0
Applied rewrites58.0%
herbie shell --seed 2025073
(FPCore (a b angle)
:name "ab-angle->ABCF C"
:precision binary64
(+ (pow (* a (cos (* (PI) (/ angle 180.0)))) 2.0) (pow (* b (sin (* (PI) (/ angle 180.0)))) 2.0)))