
(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 16 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
(let* ((t_0 (sqrt (PI))) (t_1 (sqrt t_0)))
(+
(pow (* a (sin (* (* (/ angle 180.0) (* t_1 t_1)) t_0))) 2.0)
(pow (* b (cos (* (/ angle 180.0) (PI)))) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
t_1 := \sqrt{t\_0}\\
{\left(a \cdot \sin \left(\left(\frac{angle}{180} \cdot \left(t\_1 \cdot t\_1\right)\right) \cdot t\_0\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}
\end{array}
\end{array}
Initial program 77.9%
lift-*.f64N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6478.0
Applied rewrites78.0%
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6478.1
Applied rewrites78.1%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (sqrt (PI))) (t_1 (sqrt t_0)))
(+
(pow
(* a (sin (* (* (* 0.005555555555555556 angle) (* t_1 t_1)) t_0)))
2.0)
(pow (* b (cos (* -0.005555555555555556 (* (PI) angle)))) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
t_1 := \sqrt{t\_0}\\
{\left(a \cdot \sin \left(\left(\left(0.005555555555555556 \cdot angle\right) \cdot \left(t\_1 \cdot t\_1\right)\right) \cdot t\_0\right)\right)}^{2} + {\left(b \cdot \cos \left(-0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\right)\right)\right)}^{2}
\end{array}
\end{array}
Initial program 77.9%
lift-*.f64N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6478.0
Applied rewrites78.0%
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6478.1
Applied rewrites78.1%
Taylor expanded in angle around 0
Applied rewrites78.0%
Taylor expanded in angle around inf
Applied rewrites78.1%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (sqrt (PI))))
(+
(pow (* a (sin (* (* (/ angle 180.0) t_0) t_0))) 2.0)
(pow (* b (sin (fma (- (PI)) (/ angle 180.0) (/ (PI) 2.0)))) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(a \cdot \sin \left(\left(\frac{angle}{180} \cdot t\_0\right) \cdot t\_0\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{fma}\left(-\mathsf{PI}\left(\right), \frac{angle}{180}, \frac{\mathsf{PI}\left(\right)}{2}\right)\right)\right)}^{2}
\end{array}
\end{array}
Initial program 77.9%
lift-*.f64N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6478.0
Applied rewrites78.0%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
lower-/.f6478.0
Applied rewrites78.0%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (sqrt (PI))))
(+
(pow (* a (sin (* (* (* t_0 angle) 0.005555555555555556) t_0))) 2.0)
(pow (* b (cos (* (/ angle 180.0) (PI)))) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(a \cdot \sin \left(\left(\left(t\_0 \cdot angle\right) \cdot 0.005555555555555556\right) \cdot t\_0\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}
\end{array}
\end{array}
Initial program 77.9%
lift-*.f64N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6478.0
Applied rewrites78.0%
Taylor expanded in angle around 0
Applied rewrites78.0%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (/ (* (PI) angle) 180.0))) 2.0) (pow (* b (cos (* (/ angle 180.0) (PI)))) 2.0)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\frac{\mathsf{PI}\left(\right) \cdot angle}{180}\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}
\end{array}
Initial program 77.9%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6478.0
Applied rewrites78.0%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (sqrt (PI))) (t_1 (sqrt t_0))) (+ (pow (* a (sin (* (* (/ angle 180.0) (* t_1 t_1)) t_0))) 2.0) (* b b))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
t_1 := \sqrt{t\_0}\\
{\left(a \cdot \sin \left(\left(\frac{angle}{180} \cdot \left(t\_1 \cdot t\_1\right)\right) \cdot t\_0\right)\right)}^{2} + b \cdot b
\end{array}
\end{array}
Initial program 77.9%
lift-*.f64N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6478.0
Applied rewrites78.0%
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6478.1
Applied rewrites78.1%
Taylor expanded in angle around 0
Applied rewrites77.9%
Final simplification77.9%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (sqrt (PI))) (t_1 (sqrt t_0)))
(+
(pow
(* a (sin (* (* (* 0.005555555555555556 angle) (* t_1 t_1)) t_0)))
2.0)
(* b b))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
t_1 := \sqrt{t\_0}\\
{\left(a \cdot \sin \left(\left(\left(0.005555555555555556 \cdot angle\right) \cdot \left(t\_1 \cdot t\_1\right)\right) \cdot t\_0\right)\right)}^{2} + b \cdot b
\end{array}
\end{array}
Initial program 77.9%
lift-*.f64N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6478.0
Applied rewrites78.0%
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6478.1
Applied rewrites78.1%
Taylor expanded in angle around 0
Applied rewrites78.0%
Taylor expanded in angle around 0
Applied rewrites77.9%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (sqrt (PI)))) (+ (pow (* a (sin (* (* (/ angle 180.0) t_0) t_0))) 2.0) (* b b))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(a \cdot \sin \left(\left(\frac{angle}{180} \cdot t\_0\right) \cdot t\_0\right)\right)}^{2} + b \cdot b
\end{array}
\end{array}
Initial program 77.9%
lift-*.f64N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6478.0
Applied rewrites78.0%
Taylor expanded in angle around 0
Applied rewrites77.9%
Final simplification77.9%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (sqrt (PI)))) (+ (pow (* a (sin (* (* angle (/ t_0 180.0)) t_0))) 2.0) (* b b))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
{\left(a \cdot \sin \left(\left(angle \cdot \frac{t\_0}{180}\right) \cdot t\_0\right)\right)}^{2} + b \cdot b
\end{array}
\end{array}
Initial program 77.9%
lift-*.f64N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6478.0
Applied rewrites78.0%
lift-pow.f64N/A
pow-to-expN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-log.f64N/A
*-commutativeN/A
exp-prodN/A
lower-pow.f64N/A
lower-exp.f6440.0
Applied rewrites40.0%
Taylor expanded in angle around 0
Applied rewrites77.9%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6477.8
Applied rewrites77.8%
Final simplification77.8%
(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 77.9%
Taylor expanded in angle around 0
Applied rewrites77.8%
Final simplification77.8%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) (PI))))
(if (<= angle 3e-143)
(*
(fma
-3.08641975308642e-5
(-
(* (* (* angle angle) (PI)) (PI))
(* (/ (* a (* (* angle angle) a)) b) (/ t_0 b)))
1.0)
(* b b))
(fma (* (* 3.08641975308642e-5 a) (* a t_0)) (* angle angle) (* b b)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;angle \leq 3 \cdot 10^{-143}:\\
\;\;\;\;\mathsf{fma}\left(-3.08641975308642 \cdot 10^{-5}, \left(\left(angle \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right) - \frac{a \cdot \left(\left(angle \cdot angle\right) \cdot a\right)}{b} \cdot \frac{t\_0}{b}, 1\right) \cdot \left(b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot \left(a \cdot t\_0\right), angle \cdot angle, b \cdot b\right)\\
\end{array}
\end{array}
if angle < 2.99999999999999985e-143Initial program 80.1%
Taylor expanded in angle around 0
Applied rewrites42.9%
Taylor expanded in a around inf
Applied rewrites32.4%
Taylor expanded in b around inf
Applied rewrites57.0%
if 2.99999999999999985e-143 < angle Initial program 74.9%
Taylor expanded in angle around 0
Applied rewrites39.0%
Taylor expanded in a around inf
Applied rewrites65.8%
(FPCore (a b angle)
:precision binary64
(if (<= angle 2.4e-161)
(* b b)
(fma
(* (* 3.08641975308642e-5 a) (* a (* (PI) (PI))))
(* angle angle)
(* b b))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;angle \leq 2.4 \cdot 10^{-161}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(3.08641975308642 \cdot 10^{-5} \cdot a\right) \cdot \left(a \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right), angle \cdot angle, b \cdot b\right)\\
\end{array}
\end{array}
if angle < 2.39999999999999999e-161Initial program 79.6%
Taylor expanded in angle around 0
Applied rewrites61.8%
if 2.39999999999999999e-161 < angle Initial program 75.8%
Taylor expanded in angle around 0
Applied rewrites39.1%
Taylor expanded in a around inf
Applied rewrites65.9%
(FPCore (a b angle) :precision binary64 (if (<= a 2e+140) (* b b) (* (* (* (* a a) 3.08641975308642e-5) (* (* (PI) (PI)) angle)) angle)))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2 \cdot 10^{+140}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)\right) \cdot angle\\
\end{array}
\end{array}
if a < 2.00000000000000012e140Initial program 75.8%
Taylor expanded in angle around 0
Applied rewrites60.1%
if 2.00000000000000012e140 < a Initial program 90.6%
Taylor expanded in angle around 0
Applied rewrites42.5%
Taylor expanded in a around inf
Applied rewrites56.0%
Applied rewrites64.7%
(FPCore (a b angle) :precision binary64 (if (<= a 2e+140) (* b b) (* (* a (* (* angle angle) a)) (* (* (PI) (PI)) 3.08641975308642e-5))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2 \cdot 10^{+140}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(a \cdot \left(\left(angle \cdot angle\right) \cdot a\right)\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot 3.08641975308642 \cdot 10^{-5}\right)\\
\end{array}
\end{array}
if a < 2.00000000000000012e140Initial program 75.8%
Taylor expanded in angle around 0
Applied rewrites60.1%
if 2.00000000000000012e140 < a Initial program 90.6%
Taylor expanded in angle around 0
Applied rewrites42.5%
Taylor expanded in a around inf
Applied rewrites56.0%
Taylor expanded in a around inf
Applied rewrites58.3%
(FPCore (a b angle) :precision binary64 (if (<= a 2e+140) (* b b) (* (* 3.08641975308642e-5 (* a a)) (* (* (PI) (PI)) (* angle angle)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2 \cdot 10^{+140}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot a\right)\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(angle \cdot angle\right)\right)\\
\end{array}
\end{array}
if a < 2.00000000000000012e140Initial program 75.8%
Taylor expanded in angle around 0
Applied rewrites60.1%
if 2.00000000000000012e140 < a Initial program 90.6%
Taylor expanded in angle around 0
Applied rewrites42.5%
Taylor expanded in a around inf
Applied rewrites56.0%
(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 77.9%
Taylor expanded in angle around 0
Applied rewrites56.0%
herbie shell --seed 2025018
(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)))