
(FPCore (F B x) :precision binary64 (+ (- (* x (/ 1.0 (tan B)))) (* (/ F (sin B)) (pow (+ (+ (* F F) 2.0) (* 2.0 x)) (- (/ 1.0 2.0))))))
double code(double F, double B, double x) {
return -(x * (1.0 / tan(B))) + ((F / sin(B)) * pow((((F * F) + 2.0) + (2.0 * x)), -(1.0 / 2.0)));
}
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(f, b, x)
use fmin_fmax_functions
real(8), intent (in) :: f
real(8), intent (in) :: b
real(8), intent (in) :: x
code = -(x * (1.0d0 / tan(b))) + ((f / sin(b)) * ((((f * f) + 2.0d0) + (2.0d0 * x)) ** -(1.0d0 / 2.0d0)))
end function
public static double code(double F, double B, double x) {
return -(x * (1.0 / Math.tan(B))) + ((F / Math.sin(B)) * Math.pow((((F * F) + 2.0) + (2.0 * x)), -(1.0 / 2.0)));
}
def code(F, B, x): return -(x * (1.0 / math.tan(B))) + ((F / math.sin(B)) * math.pow((((F * F) + 2.0) + (2.0 * x)), -(1.0 / 2.0)))
function code(F, B, x) return Float64(Float64(-Float64(x * Float64(1.0 / tan(B)))) + Float64(Float64(F / sin(B)) * (Float64(Float64(Float64(F * F) + 2.0) + Float64(2.0 * x)) ^ Float64(-Float64(1.0 / 2.0))))) end
function tmp = code(F, B, x) tmp = -(x * (1.0 / tan(B))) + ((F / sin(B)) * ((((F * F) + 2.0) + (2.0 * x)) ^ -(1.0 / 2.0))); end
code[F_, B_, x_] := N[((-N[(x * N[(1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]) + N[(N[(F / N[Sin[B], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(N[(F * F), $MachinePrecision] + 2.0), $MachinePrecision] + N[(2.0 * x), $MachinePrecision]), $MachinePrecision], (-N[(1.0 / 2.0), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-x \cdot \frac{1}{\tan B}\right) + \frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (F B x) :precision binary64 (+ (- (* x (/ 1.0 (tan B)))) (* (/ F (sin B)) (pow (+ (+ (* F F) 2.0) (* 2.0 x)) (- (/ 1.0 2.0))))))
double code(double F, double B, double x) {
return -(x * (1.0 / tan(B))) + ((F / sin(B)) * pow((((F * F) + 2.0) + (2.0 * x)), -(1.0 / 2.0)));
}
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(f, b, x)
use fmin_fmax_functions
real(8), intent (in) :: f
real(8), intent (in) :: b
real(8), intent (in) :: x
code = -(x * (1.0d0 / tan(b))) + ((f / sin(b)) * ((((f * f) + 2.0d0) + (2.0d0 * x)) ** -(1.0d0 / 2.0d0)))
end function
public static double code(double F, double B, double x) {
return -(x * (1.0 / Math.tan(B))) + ((F / Math.sin(B)) * Math.pow((((F * F) + 2.0) + (2.0 * x)), -(1.0 / 2.0)));
}
def code(F, B, x): return -(x * (1.0 / math.tan(B))) + ((F / math.sin(B)) * math.pow((((F * F) + 2.0) + (2.0 * x)), -(1.0 / 2.0)))
function code(F, B, x) return Float64(Float64(-Float64(x * Float64(1.0 / tan(B)))) + Float64(Float64(F / sin(B)) * (Float64(Float64(Float64(F * F) + 2.0) + Float64(2.0 * x)) ^ Float64(-Float64(1.0 / 2.0))))) end
function tmp = code(F, B, x) tmp = -(x * (1.0 / tan(B))) + ((F / sin(B)) * ((((F * F) + 2.0) + (2.0 * x)) ^ -(1.0 / 2.0))); end
code[F_, B_, x_] := N[((-N[(x * N[(1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]) + N[(N[(F / N[Sin[B], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(N[(F * F), $MachinePrecision] + 2.0), $MachinePrecision] + N[(2.0 * x), $MachinePrecision]), $MachinePrecision], (-N[(1.0 / 2.0), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-x \cdot \frac{1}{\tan B}\right) + \frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}
\end{array}
(FPCore (F B x)
:precision binary64
(let* ((t_0 (* (cos B) x)))
(if (<= F -1.5e+63)
(fma (pow (sin B) -1.0) -1.0 (/ (* -1.0 t_0) (sin B)))
(if (<= F 5.7e+100)
(+
(* -1.0 (/ x (tan B)))
(/
(* F (pow (fma (pow F 1.0) (pow F 1.0) (fma 2.0 x 2.0)) -0.5))
(sin B)))
(/ (- 1.0 t_0) (sin B))))))
double code(double F, double B, double x) {
double t_0 = cos(B) * x;
double tmp;
if (F <= -1.5e+63) {
tmp = fma(pow(sin(B), -1.0), -1.0, ((-1.0 * t_0) / sin(B)));
} else if (F <= 5.7e+100) {
tmp = (-1.0 * (x / tan(B))) + ((F * pow(fma(pow(F, 1.0), pow(F, 1.0), fma(2.0, x, 2.0)), -0.5)) / sin(B));
} else {
tmp = (1.0 - t_0) / sin(B);
}
return tmp;
}
function code(F, B, x) t_0 = Float64(cos(B) * x) tmp = 0.0 if (F <= -1.5e+63) tmp = fma((sin(B) ^ -1.0), -1.0, Float64(Float64(-1.0 * t_0) / sin(B))); elseif (F <= 5.7e+100) tmp = Float64(Float64(-1.0 * Float64(x / tan(B))) + Float64(Float64(F * (fma((F ^ 1.0), (F ^ 1.0), fma(2.0, x, 2.0)) ^ -0.5)) / sin(B))); else tmp = Float64(Float64(1.0 - t_0) / sin(B)); end return tmp end
code[F_, B_, x_] := Block[{t$95$0 = N[(N[Cos[B], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[F, -1.5e+63], N[(N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision] * -1.0 + N[(N[(-1.0 * t$95$0), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[F, 5.7e+100], N[(N[(-1.0 * N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(F * N[Power[N[(N[Power[F, 1.0], $MachinePrecision] * N[Power[F, 1.0], $MachinePrecision] + N[(2.0 * x + 2.0), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - t$95$0), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos B \cdot x\\
\mathbf{if}\;F \leq -1.5 \cdot 10^{+63}:\\
\;\;\;\;\mathsf{fma}\left({\sin B}^{-1}, -1, \frac{-1 \cdot t\_0}{\sin B}\right)\\
\mathbf{elif}\;F \leq 5.7 \cdot 10^{+100}:\\
\;\;\;\;-1 \cdot \frac{x}{\tan B} + \frac{F \cdot {\left(\mathsf{fma}\left({F}^{1}, {F}^{1}, \mathsf{fma}\left(2, x, 2\right)\right)\right)}^{-0.5}}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - t\_0}{\sin B}\\
\end{array}
\end{array}
if F < -1.5e63Initial program 47.3%
Taylor expanded in F around -inf
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f64N/A
inv-powN/A
lower-pow.f64N/A
lift-sin.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lift-sin.f6499.9
Applied rewrites99.9%
if -1.5e63 < F < 5.69999999999999984e100Initial program 99.5%
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
lift-pow.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
Applied rewrites99.5%
lift-*.f64N/A
lift-/.f64N/A
lift-tan.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
lift-tan.f6499.7
Applied rewrites99.7%
if 5.69999999999999984e100 < F Initial program 55.9%
Taylor expanded in F around inf
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lift-sin.f6499.6
Applied rewrites99.6%
Final simplification99.8%
(FPCore (F B x)
:precision binary64
(let* ((t_0 (* (cos B) x)))
(if (<= F -1e+62)
(fma (pow (sin B) -1.0) -1.0 (/ (* -1.0 t_0) (sin B)))
(if (<= F 5.2e+100)
(+
(* -1.0 (/ x (tan B)))
(*
(/ F (sin B))
(pow (+ (+ (* F F) 2.0) (* 2.0 x)) (* -1.0 (/ 1.0 2.0)))))
(/ (- 1.0 t_0) (sin B))))))
double code(double F, double B, double x) {
double t_0 = cos(B) * x;
double tmp;
if (F <= -1e+62) {
tmp = fma(pow(sin(B), -1.0), -1.0, ((-1.0 * t_0) / sin(B)));
} else if (F <= 5.2e+100) {
tmp = (-1.0 * (x / tan(B))) + ((F / sin(B)) * pow((((F * F) + 2.0) + (2.0 * x)), (-1.0 * (1.0 / 2.0))));
} else {
tmp = (1.0 - t_0) / sin(B);
}
return tmp;
}
function code(F, B, x) t_0 = Float64(cos(B) * x) tmp = 0.0 if (F <= -1e+62) tmp = fma((sin(B) ^ -1.0), -1.0, Float64(Float64(-1.0 * t_0) / sin(B))); elseif (F <= 5.2e+100) tmp = Float64(Float64(-1.0 * Float64(x / tan(B))) + Float64(Float64(F / sin(B)) * (Float64(Float64(Float64(F * F) + 2.0) + Float64(2.0 * x)) ^ Float64(-1.0 * Float64(1.0 / 2.0))))); else tmp = Float64(Float64(1.0 - t_0) / sin(B)); end return tmp end
code[F_, B_, x_] := Block[{t$95$0 = N[(N[Cos[B], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[F, -1e+62], N[(N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision] * -1.0 + N[(N[(-1.0 * t$95$0), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[F, 5.2e+100], N[(N[(-1.0 * N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(F / N[Sin[B], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(N[(F * F), $MachinePrecision] + 2.0), $MachinePrecision] + N[(2.0 * x), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(1.0 / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - t$95$0), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos B \cdot x\\
\mathbf{if}\;F \leq -1 \cdot 10^{+62}:\\
\;\;\;\;\mathsf{fma}\left({\sin B}^{-1}, -1, \frac{-1 \cdot t\_0}{\sin B}\right)\\
\mathbf{elif}\;F \leq 5.2 \cdot 10^{+100}:\\
\;\;\;\;-1 \cdot \frac{x}{\tan B} + \frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-1 \cdot \frac{1}{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - t\_0}{\sin B}\\
\end{array}
\end{array}
if F < -1.00000000000000004e62Initial program 47.3%
Taylor expanded in F around -inf
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f64N/A
inv-powN/A
lower-pow.f64N/A
lift-sin.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lift-sin.f6499.9
Applied rewrites99.9%
if -1.00000000000000004e62 < F < 5.2000000000000003e100Initial program 99.5%
lift-*.f64N/A
lift-/.f64N/A
lift-tan.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
lift-tan.f6499.7
Applied rewrites99.7%
if 5.2000000000000003e100 < F Initial program 55.9%
Taylor expanded in F around inf
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lift-sin.f6499.6
Applied rewrites99.6%
Final simplification99.7%
(FPCore (F B x)
:precision binary64
(let* ((t_0 (* (cos B) x)))
(if (<= F -5e+24)
(fma (pow (sin B) -1.0) -1.0 (/ (* -1.0 t_0) (sin B)))
(if (<= F 5.5e+100)
(+
(* -1.0 (* x (/ 1.0 (tan B))))
(/
(* F (pow (fma (pow F 1.0) (pow F 1.0) (fma 2.0 x 2.0)) -0.5))
(sin B)))
(/ (- 1.0 t_0) (sin B))))))
double code(double F, double B, double x) {
double t_0 = cos(B) * x;
double tmp;
if (F <= -5e+24) {
tmp = fma(pow(sin(B), -1.0), -1.0, ((-1.0 * t_0) / sin(B)));
} else if (F <= 5.5e+100) {
tmp = (-1.0 * (x * (1.0 / tan(B)))) + ((F * pow(fma(pow(F, 1.0), pow(F, 1.0), fma(2.0, x, 2.0)), -0.5)) / sin(B));
} else {
tmp = (1.0 - t_0) / sin(B);
}
return tmp;
}
function code(F, B, x) t_0 = Float64(cos(B) * x) tmp = 0.0 if (F <= -5e+24) tmp = fma((sin(B) ^ -1.0), -1.0, Float64(Float64(-1.0 * t_0) / sin(B))); elseif (F <= 5.5e+100) tmp = Float64(Float64(-1.0 * Float64(x * Float64(1.0 / tan(B)))) + Float64(Float64(F * (fma((F ^ 1.0), (F ^ 1.0), fma(2.0, x, 2.0)) ^ -0.5)) / sin(B))); else tmp = Float64(Float64(1.0 - t_0) / sin(B)); end return tmp end
code[F_, B_, x_] := Block[{t$95$0 = N[(N[Cos[B], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[F, -5e+24], N[(N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision] * -1.0 + N[(N[(-1.0 * t$95$0), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[F, 5.5e+100], N[(N[(-1.0 * N[(x * N[(1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(F * N[Power[N[(N[Power[F, 1.0], $MachinePrecision] * N[Power[F, 1.0], $MachinePrecision] + N[(2.0 * x + 2.0), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - t$95$0), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos B \cdot x\\
\mathbf{if}\;F \leq -5 \cdot 10^{+24}:\\
\;\;\;\;\mathsf{fma}\left({\sin B}^{-1}, -1, \frac{-1 \cdot t\_0}{\sin B}\right)\\
\mathbf{elif}\;F \leq 5.5 \cdot 10^{+100}:\\
\;\;\;\;-1 \cdot \left(x \cdot \frac{1}{\tan B}\right) + \frac{F \cdot {\left(\mathsf{fma}\left({F}^{1}, {F}^{1}, \mathsf{fma}\left(2, x, 2\right)\right)\right)}^{-0.5}}{\sin B}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - t\_0}{\sin B}\\
\end{array}
\end{array}
if F < -5.00000000000000045e24Initial program 57.2%
Taylor expanded in F around -inf
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f64N/A
inv-powN/A
lower-pow.f64N/A
lift-sin.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lift-sin.f6499.8
Applied rewrites99.8%
if -5.00000000000000045e24 < F < 5.5000000000000002e100Initial program 99.5%
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
lift-pow.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
Applied rewrites99.6%
if 5.5000000000000002e100 < F Initial program 55.9%
Taylor expanded in F around inf
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lift-sin.f6499.6
Applied rewrites99.6%
Final simplification99.6%
(FPCore (F B x)
:precision binary64
(let* ((t_0 (* (cos B) x)))
(if (<= F -1e+62)
(fma (pow (sin B) -1.0) -1.0 (/ (* -1.0 t_0) (sin B)))
(if (<= F 5.2e+100)
(+
(* -1.0 (* x (/ 1.0 (tan B))))
(*
(/ F (sin B))
(pow (+ (+ (* F F) 2.0) (* 2.0 x)) (* -1.0 (/ 1.0 2.0)))))
(/ (- 1.0 t_0) (sin B))))))
double code(double F, double B, double x) {
double t_0 = cos(B) * x;
double tmp;
if (F <= -1e+62) {
tmp = fma(pow(sin(B), -1.0), -1.0, ((-1.0 * t_0) / sin(B)));
} else if (F <= 5.2e+100) {
tmp = (-1.0 * (x * (1.0 / tan(B)))) + ((F / sin(B)) * pow((((F * F) + 2.0) + (2.0 * x)), (-1.0 * (1.0 / 2.0))));
} else {
tmp = (1.0 - t_0) / sin(B);
}
return tmp;
}
function code(F, B, x) t_0 = Float64(cos(B) * x) tmp = 0.0 if (F <= -1e+62) tmp = fma((sin(B) ^ -1.0), -1.0, Float64(Float64(-1.0 * t_0) / sin(B))); elseif (F <= 5.2e+100) tmp = Float64(Float64(-1.0 * Float64(x * Float64(1.0 / tan(B)))) + Float64(Float64(F / sin(B)) * (Float64(Float64(Float64(F * F) + 2.0) + Float64(2.0 * x)) ^ Float64(-1.0 * Float64(1.0 / 2.0))))); else tmp = Float64(Float64(1.0 - t_0) / sin(B)); end return tmp end
code[F_, B_, x_] := Block[{t$95$0 = N[(N[Cos[B], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[F, -1e+62], N[(N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision] * -1.0 + N[(N[(-1.0 * t$95$0), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[F, 5.2e+100], N[(N[(-1.0 * N[(x * N[(1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(F / N[Sin[B], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(N[(F * F), $MachinePrecision] + 2.0), $MachinePrecision] + N[(2.0 * x), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(1.0 / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - t$95$0), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos B \cdot x\\
\mathbf{if}\;F \leq -1 \cdot 10^{+62}:\\
\;\;\;\;\mathsf{fma}\left({\sin B}^{-1}, -1, \frac{-1 \cdot t\_0}{\sin B}\right)\\
\mathbf{elif}\;F \leq 5.2 \cdot 10^{+100}:\\
\;\;\;\;-1 \cdot \left(x \cdot \frac{1}{\tan B}\right) + \frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-1 \cdot \frac{1}{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - t\_0}{\sin B}\\
\end{array}
\end{array}
if F < -1.00000000000000004e62Initial program 47.3%
Taylor expanded in F around -inf
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f64N/A
inv-powN/A
lower-pow.f64N/A
lift-sin.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lift-sin.f6499.9
Applied rewrites99.9%
if -1.00000000000000004e62 < F < 5.2000000000000003e100Initial program 99.5%
if 5.2000000000000003e100 < F Initial program 55.9%
Taylor expanded in F around inf
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lift-sin.f6499.6
Applied rewrites99.6%
Final simplification99.6%
(FPCore (F B x)
:precision binary64
(let* ((t_0 (* (cos B) x)))
(if (<= F -2.6e+19)
(fma (pow (sin B) -1.0) -1.0 (/ (* -1.0 t_0) (sin B)))
(if (<= F 200000000.0)
(+
(* (* -1.0 x) (/ (cos B) (sin B)))
(*
(/ F (sin B))
(pow (+ (+ (* F F) 2.0) (* 2.0 x)) (* -1.0 (/ 1.0 2.0)))))
(/ (- 1.0 t_0) (sin B))))))
double code(double F, double B, double x) {
double t_0 = cos(B) * x;
double tmp;
if (F <= -2.6e+19) {
tmp = fma(pow(sin(B), -1.0), -1.0, ((-1.0 * t_0) / sin(B)));
} else if (F <= 200000000.0) {
tmp = ((-1.0 * x) * (cos(B) / sin(B))) + ((F / sin(B)) * pow((((F * F) + 2.0) + (2.0 * x)), (-1.0 * (1.0 / 2.0))));
} else {
tmp = (1.0 - t_0) / sin(B);
}
return tmp;
}
function code(F, B, x) t_0 = Float64(cos(B) * x) tmp = 0.0 if (F <= -2.6e+19) tmp = fma((sin(B) ^ -1.0), -1.0, Float64(Float64(-1.0 * t_0) / sin(B))); elseif (F <= 200000000.0) tmp = Float64(Float64(Float64(-1.0 * x) * Float64(cos(B) / sin(B))) + Float64(Float64(F / sin(B)) * (Float64(Float64(Float64(F * F) + 2.0) + Float64(2.0 * x)) ^ Float64(-1.0 * Float64(1.0 / 2.0))))); else tmp = Float64(Float64(1.0 - t_0) / sin(B)); end return tmp end
code[F_, B_, x_] := Block[{t$95$0 = N[(N[Cos[B], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[F, -2.6e+19], N[(N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision] * -1.0 + N[(N[(-1.0 * t$95$0), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[F, 200000000.0], N[(N[(N[(-1.0 * x), $MachinePrecision] * N[(N[Cos[B], $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(F / N[Sin[B], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(N[(F * F), $MachinePrecision] + 2.0), $MachinePrecision] + N[(2.0 * x), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(1.0 / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - t$95$0), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos B \cdot x\\
\mathbf{if}\;F \leq -2.6 \cdot 10^{+19}:\\
\;\;\;\;\mathsf{fma}\left({\sin B}^{-1}, -1, \frac{-1 \cdot t\_0}{\sin B}\right)\\
\mathbf{elif}\;F \leq 200000000:\\
\;\;\;\;\left(-1 \cdot x\right) \cdot \frac{\cos B}{\sin B} + \frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-1 \cdot \frac{1}{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - t\_0}{\sin B}\\
\end{array}
\end{array}
if F < -2.6e19Initial program 57.2%
Taylor expanded in F around -inf
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f64N/A
inv-powN/A
lower-pow.f64N/A
lift-sin.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lift-sin.f6499.8
Applied rewrites99.8%
if -2.6e19 < F < 2e8Initial program 99.5%
Taylor expanded in B around inf
lower-/.f64N/A
lower-cos.f64N/A
lift-sin.f6499.5
Applied rewrites99.5%
if 2e8 < F Initial program 70.0%
Taylor expanded in F around inf
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lift-sin.f6499.6
Applied rewrites99.6%
Final simplification99.6%
(FPCore (F B x)
:precision binary64
(let* ((t_0 (* (cos B) x)))
(if (<= F 8e-204)
(fma (pow (sin B) -1.0) -1.0 (/ (* -1.0 t_0) (sin B)))
(/ (- 1.0 t_0) (sin B)))))
double code(double F, double B, double x) {
double t_0 = cos(B) * x;
double tmp;
if (F <= 8e-204) {
tmp = fma(pow(sin(B), -1.0), -1.0, ((-1.0 * t_0) / sin(B)));
} else {
tmp = (1.0 - t_0) / sin(B);
}
return tmp;
}
function code(F, B, x) t_0 = Float64(cos(B) * x) tmp = 0.0 if (F <= 8e-204) tmp = fma((sin(B) ^ -1.0), -1.0, Float64(Float64(-1.0 * t_0) / sin(B))); else tmp = Float64(Float64(1.0 - t_0) / sin(B)); end return tmp end
code[F_, B_, x_] := Block[{t$95$0 = N[(N[Cos[B], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[F, 8e-204], N[(N[Power[N[Sin[B], $MachinePrecision], -1.0], $MachinePrecision] * -1.0 + N[(N[(-1.0 * t$95$0), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - t$95$0), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos B \cdot x\\
\mathbf{if}\;F \leq 8 \cdot 10^{-204}:\\
\;\;\;\;\mathsf{fma}\left({\sin B}^{-1}, -1, \frac{-1 \cdot t\_0}{\sin B}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - t\_0}{\sin B}\\
\end{array}
\end{array}
if F < 8.00000000000000001e-204Initial program 78.4%
Taylor expanded in F around -inf
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f64N/A
inv-powN/A
lower-pow.f64N/A
lift-sin.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lift-sin.f6471.5
Applied rewrites71.5%
if 8.00000000000000001e-204 < F Initial program 81.7%
Taylor expanded in F around inf
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lift-sin.f6478.4
Applied rewrites78.4%
(FPCore (F B x) :precision binary64 (/ (- 1.0 (* (cos B) x)) (sin B)))
double code(double F, double B, double x) {
return (1.0 - (cos(B) * x)) / sin(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(f, b, x)
use fmin_fmax_functions
real(8), intent (in) :: f
real(8), intent (in) :: b
real(8), intent (in) :: x
code = (1.0d0 - (cos(b) * x)) / sin(b)
end function
public static double code(double F, double B, double x) {
return (1.0 - (Math.cos(B) * x)) / Math.sin(B);
}
def code(F, B, x): return (1.0 - (math.cos(B) * x)) / math.sin(B)
function code(F, B, x) return Float64(Float64(1.0 - Float64(cos(B) * x)) / sin(B)) end
function tmp = code(F, B, x) tmp = (1.0 - (cos(B) * x)) / sin(B); end
code[F_, B_, x_] := N[(N[(1.0 - N[(N[Cos[B], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - \cos B \cdot x}{\sin B}
\end{array}
Initial program 79.8%
Taylor expanded in F around inf
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lift-sin.f6460.9
Applied rewrites60.9%
herbie shell --seed 2025066
(FPCore (F B x)
:name "VandenBroeck and Keller, Equation (23)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (* (/ F (sin B)) (pow (+ (+ (* F F) 2.0) (* 2.0 x)) (- (/ 1.0 2.0))))))