
(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 6 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 (sin (* (* 0.005555555555555556 angle) (PI)))) 2.0) (* b b)))
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 80.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6481.6
Applied rewrites81.6%
Taylor expanded in angle around 0
lower-*.f6481.6
Applied rewrites81.6%
(FPCore (a b angle)
:precision binary64
(if (<= a 2.15e-104)
(* b b)
(+
(* (* (pow (* a angle) 2.0) (* (PI) (PI))) 3.08641975308642e-5)
(* b b))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.15 \cdot 10^{-104}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left({\left(a \cdot angle\right)}^{2} \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot 3.08641975308642 \cdot 10^{-5} + b \cdot b\\
\end{array}
\end{array}
if a < 2.15000000000000005e-104Initial program 78.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6459.0
Applied rewrites59.0%
if 2.15000000000000005e-104 < a Initial program 83.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6483.6
Applied rewrites83.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
pow-prod-downN/A
pow-prod-downN/A
*-commutativeN/A
*-commutativeN/A
lower-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6480.4
Applied rewrites80.4%
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
unpow-prod-downN/A
pow-prod-downN/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.5
Applied rewrites80.5%
(FPCore (a b angle) :precision binary64 (if (<= a 2.15e-104) (* b b) (+ (* (pow (* (* a angle) (PI)) 2.0) 3.08641975308642e-5) (* b b))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.15 \cdot 10^{-104}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(a \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5} + b \cdot b\\
\end{array}
\end{array}
if a < 2.15000000000000005e-104Initial program 78.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6459.0
Applied rewrites59.0%
if 2.15000000000000005e-104 < a Initial program 83.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6483.6
Applied rewrites83.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
pow-prod-downN/A
pow-prod-downN/A
*-commutativeN/A
*-commutativeN/A
lower-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6480.4
Applied rewrites80.4%
lift-*.f64N/A
*-commutativeN/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f6480.5
Applied rewrites80.5%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (* (PI) angle) a)))
(if (<= a 2.15e-104)
(* b b)
(+ (* (* t_0 t_0) 3.08641975308642e-5) (* b b)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot a\\
\mathbf{if}\;a \leq 2.15 \cdot 10^{-104}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 \cdot t\_0\right) \cdot 3.08641975308642 \cdot 10^{-5} + b \cdot b\\
\end{array}
\end{array}
if a < 2.15000000000000005e-104Initial program 78.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6459.0
Applied rewrites59.0%
if 2.15000000000000005e-104 < a Initial program 83.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6483.6
Applied rewrites83.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
pow-prod-downN/A
pow-prod-downN/A
*-commutativeN/A
*-commutativeN/A
lower-pow.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f6480.4
Applied rewrites80.4%
lift-pow.f64N/A
unpow2N/A
lower-*.f6480.4
Applied rewrites80.4%
(FPCore (a b angle) :precision binary64 (if (<= a 9.2e+164) (* b b) (* (* (/ b a) (/ b a)) (* a a))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 9.2e+164) {
tmp = b * b;
} else {
tmp = ((b / a) * (b / a)) * (a * a);
}
return tmp;
}
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
real(8) :: tmp
if (a <= 9.2d+164) then
tmp = b * b
else
tmp = ((b / a) * (b / a)) * (a * a)
end if
code = tmp
end function
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 9.2e+164) {
tmp = b * b;
} else {
tmp = ((b / a) * (b / a)) * (a * a);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 9.2e+164: tmp = b * b else: tmp = ((b / a) * (b / a)) * (a * a) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 9.2e+164) tmp = Float64(b * b); else tmp = Float64(Float64(Float64(b / a) * Float64(b / a)) * Float64(a * a)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 9.2e+164) tmp = b * b; else tmp = ((b / a) * (b / a)) * (a * a); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 9.2e+164], N[(b * b), $MachinePrecision], N[(N[(N[(b / a), $MachinePrecision] * N[(b / a), $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 9.2 \cdot 10^{+164}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{b}{a} \cdot \frac{b}{a}\right) \cdot \left(a \cdot a\right)\\
\end{array}
\end{array}
if a < 9.1999999999999998e164Initial program 77.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.4
Applied rewrites58.4%
if 9.1999999999999998e164 < a Initial program 99.8%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites56.6%
Taylor expanded in angle around 0
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f640.0
Applied rewrites0.0%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6435.9
Applied rewrites35.9%
(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.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6454.9
Applied rewrites54.9%
herbie shell --seed 2025073
(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)))