
(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 8 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}
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= angle_m 1.95e-13)
(+
(* (* (pow (* a angle_m) 2.0) (* (PI) (PI))) 3.08641975308642e-5)
(pow b 2.0))
(fma
(pow (sin (* (PI) (* 0.005555555555555556 angle_m))) 2.0)
(* a a)
(* b b))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;angle\_m \leq 1.95 \cdot 10^{-13}:\\
\;\;\;\;\left({\left(a \cdot angle\_m\right)}^{2} \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot 3.08641975308642 \cdot 10^{-5} + {b}^{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\sin \left(\mathsf{PI}\left(\right) \cdot \left(0.005555555555555556 \cdot angle\_m\right)\right)}^{2}, a \cdot a, b \cdot b\right)\\
\end{array}
\end{array}
if angle < 1.95000000000000002e-13Initial program 87.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
lower-*.f64N/A
lift-PI.f6485.3
Applied rewrites85.3%
lift-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
unpow-prod-downN/A
*-commutativeN/A
pow-prod-downN/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.4
Applied rewrites85.4%
Taylor expanded in angle around 0
lift-/.f64N/A
*-commutativeN/A
lift-/.f6485.3
unpow185.3
metadata-eval85.3
pow-flip85.3
Applied rewrites85.3%
if 1.95000000000000002e-13 < angle Initial program 62.5%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.9
Applied rewrites62.9%
lift-+.f64N/A
Applied rewrites62.9%
Taylor expanded in angle around 0
lower-*.f6463.3
Applied rewrites63.3%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= angle_m 7.4e-10)
(+
(* (* (pow (* a angle_m) 2.0) (* (PI) (PI))) 3.08641975308642e-5)
(pow b 2.0))
(fma
(- 0.5 (* 0.5 (cos (* 2.0 (* (/ angle_m 180.0) (PI))))))
(* a a)
(* b b))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;angle\_m \leq 7.4 \cdot 10^{-10}:\\
\;\;\;\;\left({\left(a \cdot angle\_m\right)}^{2} \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot 3.08641975308642 \cdot 10^{-5} + {b}^{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 - 0.5 \cdot \cos \left(2 \cdot \left(\frac{angle\_m}{180} \cdot \mathsf{PI}\left(\right)\right)\right), a \cdot a, b \cdot b\right)\\
\end{array}
\end{array}
if angle < 7.4000000000000003e-10Initial program 87.8%
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
lower-*.f64N/A
lift-PI.f6485.4
Applied rewrites85.4%
lift-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
unpow-prod-downN/A
*-commutativeN/A
pow-prod-downN/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.5
Applied rewrites85.5%
Taylor expanded in angle around 0
lift-/.f64N/A
*-commutativeN/A
lift-/.f6485.4
unpow185.4
metadata-eval85.4
pow-flip85.4
Applied rewrites85.4%
if 7.4000000000000003e-10 < angle Initial program 61.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.8
Applied rewrites61.8%
lift-+.f64N/A
Applied rewrites61.8%
lift-pow.f64N/A
lift-sin.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
unpow2N/A
lift-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
sqr-sin-aN/A
lower--.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6461.8
Applied rewrites61.8%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (sin (/ (* (PI) angle_m) 180.0))) 2.0) (* b b)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \sin \left(\frac{\mathsf{PI}\left(\right) \cdot angle\_m}{180}\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 81.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6481.1
Applied rewrites81.1%
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f6481.2
Applied rewrites81.2%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (sin (* (/ angle_m 180.0) (PI)))) 2.0) (* b b)))
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \sin \left(\frac{angle\_m}{180} \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.1
Applied rewrites81.1%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= angle_m 7.4e-10)
(+ (pow (* (* (* angle_m a) (PI)) 0.005555555555555556) 2.0) (* b b))
(fma
(- 0.5 (* 0.5 (cos (* 2.0 (* (/ angle_m 180.0) (PI))))))
(* a a)
(* b b))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;angle\_m \leq 7.4 \cdot 10^{-10}:\\
\;\;\;\;{\left(\left(\left(angle\_m \cdot a\right) \cdot \mathsf{PI}\left(\right)\right) \cdot 0.005555555555555556\right)}^{2} + b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 - 0.5 \cdot \cos \left(2 \cdot \left(\frac{angle\_m}{180} \cdot \mathsf{PI}\left(\right)\right)\right), a \cdot a, b \cdot b\right)\\
\end{array}
\end{array}
if angle < 7.4000000000000003e-10Initial program 87.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6487.8
Applied rewrites87.8%
Taylor expanded in angle around 0
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6485.4
Applied rewrites85.4%
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6485.4
Applied rewrites85.4%
if 7.4000000000000003e-10 < angle Initial program 61.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6461.8
Applied rewrites61.8%
lift-+.f64N/A
Applied rewrites61.8%
lift-pow.f64N/A
lift-sin.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
unpow2N/A
lift-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
sqr-sin-aN/A
lower--.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6461.8
Applied rewrites61.8%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= a 2.45e-123) (* b b) (+ (pow (* (* (* angle_m a) (PI)) 0.005555555555555556) 2.0) (* b b))))
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.45 \cdot 10^{-123}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(\left(angle\_m \cdot a\right) \cdot \mathsf{PI}\left(\right)\right) \cdot 0.005555555555555556\right)}^{2} + b \cdot b\\
\end{array}
\end{array}
if a < 2.4499999999999999e-123Initial program 80.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6464.3
Applied rewrites64.3%
if 2.4499999999999999e-123 < a Initial program 81.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6481.4
Applied rewrites81.4%
Taylor expanded in angle around 0
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6478.7
Applied rewrites78.7%
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6478.7
Applied rewrites78.7%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= a 2.45e-123)
(* b b)
(fma
(* 0.005555555555555556 (* (* (PI) angle_m) a))
(* 0.005555555555555556 (* (* a angle_m) (PI)))
(* b b))))\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.45 \cdot 10^{-123}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.005555555555555556 \cdot \left(\left(\mathsf{PI}\left(\right) \cdot angle\_m\right) \cdot a\right), 0.005555555555555556 \cdot \left(\left(a \cdot angle\_m\right) \cdot \mathsf{PI}\left(\right)\right), b \cdot b\right)\\
\end{array}
\end{array}
if a < 2.4499999999999999e-123Initial program 80.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6464.3
Applied rewrites64.3%
if 2.4499999999999999e-123 < a Initial program 81.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6481.4
Applied rewrites81.4%
Taylor expanded in angle around 0
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6478.7
Applied rewrites78.7%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-fma.f6478.7
Applied rewrites78.7%
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6478.7
Applied rewrites78.7%
Final simplification69.7%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (* b b))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return b * b;
}
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 = b * b
end function
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return b * b;
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return b * b
angle_m = abs(angle) function code(a, b, angle_m) return Float64(b * b) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = b * b; end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(b * b), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
b \cdot b
\end{array}
Initial program 81.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6456.6
Applied rewrites56.6%
herbie shell --seed 2025045
(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)))