
(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 9 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}
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (sqrt (PI))))
(+
(pow (* a (cos (* (* t_0 t_0) (/ angle 180.0)))) 2.0)
(pow (* b (sin (* (PI) (/ angle 180.0)))) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(a \cdot \cos \left(\left(t\_0 \cdot t\_0\right) \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}
\end{array}
\end{array}
Initial program 83.4%
lift-PI.f64N/A
add-sqr-sqrtN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6483.4
Applied rewrites83.4%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (fma (/ angle 180.0) (PI) (/ (PI) 2.0)))) 2.0) (pow (* b (sin (* (PI) (/ angle 180.0)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\mathsf{fma}\left(\frac{angle}{180}, \mathsf{PI}\left(\right), \frac{\mathsf{PI}\left(\right)}{2}\right)\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right)}^{2}
\end{array}
Initial program 83.4%
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-/.f6483.4
Applied rewrites83.4%
(FPCore (a b angle) :precision binary64 (fma (* (- 0.5 (* 0.5 (cos (* 2.0 (fma (/ angle 180.0) (PI) (/ (PI) -2.0)))))) a) a (pow (* (sin (* (/ angle 180.0) (PI))) b) 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 a, a, {\left(\sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 83.4%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites83.4%
Applied rewrites83.4%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (/ angle 180.0) (PI)))) (fma (* (- 0.5 (* -0.5 (cos (* 2.0 t_0)))) a) a (pow (* (sin t_0) b) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \mathsf{PI}\left(\right)\\
\mathsf{fma}\left(\left(0.5 - -0.5 \cdot \cos \left(2 \cdot t\_0\right)\right) \cdot a, a, {\left(\sin t\_0 \cdot b\right)}^{2}\right)
\end{array}
\end{array}
Initial program 83.4%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites83.4%
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-cos.f64N/A
sqr-cos-aN/A
cos-2N/A
cos-sumN/A
fp-cancel-sign-sub-invN/A
Applied rewrites83.4%
(FPCore (a b angle) :precision binary64 (fma (* (/ 2.0 2.0) a) a (pow (* (sin (* (/ angle 180.0) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{2}{2} \cdot a, a, {\left(\sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 83.4%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites83.4%
Applied rewrites74.9%
Taylor expanded in angle around 0
Applied rewrites83.1%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.5e+74)
(fma
(*
(fma (* 3.08641975308642e-5 b) b (* (* -3.08641975308642e-5 a) a))
(* (* (PI) (PI)) angle))
angle
(* a a))
(* a a)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.5 \cdot 10^{+74}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(3.08641975308642 \cdot 10^{-5} \cdot b, b, \left(-3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot a\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right), angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.5e74Initial program 81.4%
lift-PI.f64N/A
add-sqr-sqrtN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6481.5
Applied rewrites81.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites49.3%
Applied rewrites53.0%
if 1.5e74 < a Initial program 89.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6488.7
Applied rewrites88.7%
Final simplification61.2%
(FPCore (a b angle)
:precision binary64
(if (<= b 2.8e-95)
(* a a)
(fma
(* (* (PI) (PI)) (* 3.08641975308642e-5 (* b b)))
(* angle angle)
(* a a))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.8 \cdot 10^{-95}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(3.08641975308642 \cdot 10^{-5} \cdot \left(b \cdot b\right)\right), angle \cdot angle, a \cdot a\right)\\
\end{array}
\end{array}
if b < 2.7999999999999999e-95Initial program 83.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6467.8
Applied rewrites67.8%
if 2.7999999999999999e-95 < b Initial program 83.4%
lift-PI.f64N/A
add-sqr-sqrtN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6483.4
Applied rewrites83.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites43.0%
Taylor expanded in a around 0
Applied rewrites72.1%
Final simplification69.3%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) b)))
(if (<= b 8.5e+147)
(* a a)
(* (* 3.08641975308642e-5 (* angle angle)) (* t_0 t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot b\\
\mathbf{if}\;b \leq 8.5 \cdot 10^{+147}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(angle \cdot angle\right)\right) \cdot \left(t\_0 \cdot t\_0\right)\\
\end{array}
\end{array}
if b < 8.5000000000000007e147Initial program 81.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6464.5
Applied rewrites64.5%
if 8.5000000000000007e147 < b Initial program 97.2%
lift-PI.f64N/A
add-sqr-sqrtN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6497.2
Applied rewrites97.2%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites45.9%
Taylor expanded in a around 0
Applied rewrites83.0%
Final simplification67.0%
(FPCore (a b angle) :precision binary64 (* a a))
double code(double a, double b, double angle) {
return a * a;
}
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 = a * a
end function
public static double code(double a, double b, double angle) {
return a * a;
}
def code(a, b, angle): return a * a
function code(a, b, angle) return Float64(a * a) end
function tmp = code(a, b, angle) tmp = a * a; end
code[a_, b_, angle_] := N[(a * a), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a
\end{array}
Initial program 83.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6462.2
Applied rewrites62.2%
Final simplification62.2%
herbie shell --seed 2024351
(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)))