
(FPCore (x c s) :precision binary64 (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))
double code(double x, double c, double s) {
return cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x));
}
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(x, c, s)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))
end function
public static double code(double x, double c, double s) {
return Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x));
}
def code(x, c, s): return math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))
function code(x, c, s) return Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) end
function tmp = code(x, c, s) tmp = cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x)); end
code[x_, c_, s_] := N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x c s) :precision binary64 (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))
double code(double x, double c, double s) {
return cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x));
}
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(x, c, s)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))
end function
public static double code(double x, double c, double s) {
return Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x));
}
def code(x, c, s): return math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))
function code(x, c, s) return Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) end
function tmp = code(x, c, s) tmp = cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x)); end
code[x_, c_, s_] := N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\end{array}
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c_m s_m)
:precision binary64
(let* ((t_0 (cos (* 2.0 x))))
(if (<= (/ t_0 (* (pow c_m 2.0) (* (* x (pow s_m 2.0)) x))) 0.0)
(/
(/ (- (/ (pow (cos x) 2.0) c_m) (/ (pow (sin x) 2.0) c_m)) (* s_m x))
(* (* s_m x) c_m))
(/ t_0 (pow (* (* s_m c_m) x) 2.0)))))c_m = fabs(c);
s_m = fabs(s);
assert(x < c_m && c_m < s_m);
double code(double x, double c_m, double s_m) {
double t_0 = cos((2.0 * x));
double tmp;
if ((t_0 / (pow(c_m, 2.0) * ((x * pow(s_m, 2.0)) * x))) <= 0.0) {
tmp = (((pow(cos(x), 2.0) / c_m) - (pow(sin(x), 2.0) / c_m)) / (s_m * x)) / ((s_m * x) * c_m);
} else {
tmp = t_0 / pow(((s_m * c_m) * x), 2.0);
}
return tmp;
}
c_m = private
s_m = private
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
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(x, c_m, s_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: t_0
real(8) :: tmp
t_0 = cos((2.0d0 * x))
if ((t_0 / ((c_m ** 2.0d0) * ((x * (s_m ** 2.0d0)) * x))) <= 0.0d0) then
tmp = ((((cos(x) ** 2.0d0) / c_m) - ((sin(x) ** 2.0d0) / c_m)) / (s_m * x)) / ((s_m * x) * c_m)
else
tmp = t_0 / (((s_m * c_m) * x) ** 2.0d0)
end if
code = tmp
end function
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x < c_m && c_m < s_m;
public static double code(double x, double c_m, double s_m) {
double t_0 = Math.cos((2.0 * x));
double tmp;
if ((t_0 / (Math.pow(c_m, 2.0) * ((x * Math.pow(s_m, 2.0)) * x))) <= 0.0) {
tmp = (((Math.pow(Math.cos(x), 2.0) / c_m) - (Math.pow(Math.sin(x), 2.0) / c_m)) / (s_m * x)) / ((s_m * x) * c_m);
} else {
tmp = t_0 / Math.pow(((s_m * c_m) * x), 2.0);
}
return tmp;
}
c_m = math.fabs(c) s_m = math.fabs(s) [x, c_m, s_m] = sort([x, c_m, s_m]) def code(x, c_m, s_m): t_0 = math.cos((2.0 * x)) tmp = 0 if (t_0 / (math.pow(c_m, 2.0) * ((x * math.pow(s_m, 2.0)) * x))) <= 0.0: tmp = (((math.pow(math.cos(x), 2.0) / c_m) - (math.pow(math.sin(x), 2.0) / c_m)) / (s_m * x)) / ((s_m * x) * c_m) else: tmp = t_0 / math.pow(((s_m * c_m) * x), 2.0) return tmp
c_m = abs(c) s_m = abs(s) x, c_m, s_m = sort([x, c_m, s_m]) function code(x, c_m, s_m) t_0 = cos(Float64(2.0 * x)) tmp = 0.0 if (Float64(t_0 / Float64((c_m ^ 2.0) * Float64(Float64(x * (s_m ^ 2.0)) * x))) <= 0.0) tmp = Float64(Float64(Float64(Float64((cos(x) ^ 2.0) / c_m) - Float64((sin(x) ^ 2.0) / c_m)) / Float64(s_m * x)) / Float64(Float64(s_m * x) * c_m)); else tmp = Float64(t_0 / (Float64(Float64(s_m * c_m) * x) ^ 2.0)); end return tmp end
c_m = abs(c);
s_m = abs(s);
x, c_m, s_m = num2cell(sort([x, c_m, s_m])){:}
function tmp_2 = code(x, c_m, s_m)
t_0 = cos((2.0 * x));
tmp = 0.0;
if ((t_0 / ((c_m ^ 2.0) * ((x * (s_m ^ 2.0)) * x))) <= 0.0)
tmp = ((((cos(x) ^ 2.0) / c_m) - ((sin(x) ^ 2.0) / c_m)) / (s_m * x)) / ((s_m * x) * c_m);
else
tmp = t_0 / (((s_m * c_m) * x) ^ 2.0);
end
tmp_2 = tmp;
end
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[Power[c$95$m, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s$95$m, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(N[(N[(N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision] / c$95$m), $MachinePrecision] - N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / c$95$m), $MachinePrecision]), $MachinePrecision] / N[(s$95$m * x), $MachinePrecision]), $MachinePrecision] / N[(N[(s$95$m * x), $MachinePrecision] * c$95$m), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[Power[N[(N[(s$95$m * c$95$m), $MachinePrecision] * x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x, c_m, s_m] = \mathsf{sort}([x, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := \cos \left(2 \cdot x\right)\\
\mathbf{if}\;\frac{t\_0}{{c\_m}^{2} \cdot \left(\left(x \cdot {s\_m}^{2}\right) \cdot x\right)} \leq 0:\\
\;\;\;\;\frac{\frac{\frac{{\cos x}^{2}}{c\_m} - \frac{{\sin x}^{2}}{c\_m}}{s\_m \cdot x}}{\left(s\_m \cdot x\right) \cdot c\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{{\left(\left(s\_m \cdot c\_m\right) \cdot x\right)}^{2}}\\
\end{array}
\end{array}
if (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) < 0.0Initial program 76.8%
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
pow-prod-downN/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6495.9
Applied rewrites95.9%
lift-*.f64N/A
lift-cos.f64N/A
cos-2N/A
unpow2N/A
unpow2N/A
lower--.f64N/A
lift-pow.f64N/A
lift-cos.f64N/A
lift-sin.f64N/A
lift-pow.f6495.8
Applied rewrites95.8%
lift-/.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lift-pow.f64N/A
lift-pow.f64N/A
lift-sin.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
pow2N/A
lower-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
Applied rewrites92.9%
lift--.f64N/A
lift-/.f64N/A
lift-cos.f64N/A
lift-pow.f64N/A
lift-/.f64N/A
lift-pow.f64N/A
lift-sin.f64N/A
frac-2negN/A
frac-2negN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
frac-2negN/A
associate-/r*N/A
Applied rewrites99.6%
if 0.0 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) Initial program 57.7%
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
pow-prod-downN/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c_m s_m)
:precision binary64
(let* ((t_0 (cos (* 2.0 x))) (t_1 (/ 1.0 (* (* s_m x) c_m))))
(if (<= x 2e+16)
(/ t_0 (/ 1.0 (* t_1 t_1)))
(/ t_0 (pow (* s_m (pow (* x c_m) 1.0)) 2.0)))))c_m = fabs(c);
s_m = fabs(s);
assert(x < c_m && c_m < s_m);
double code(double x, double c_m, double s_m) {
double t_0 = cos((2.0 * x));
double t_1 = 1.0 / ((s_m * x) * c_m);
double tmp;
if (x <= 2e+16) {
tmp = t_0 / (1.0 / (t_1 * t_1));
} else {
tmp = t_0 / pow((s_m * pow((x * c_m), 1.0)), 2.0);
}
return tmp;
}
c_m = private
s_m = private
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
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(x, c_m, s_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos((2.0d0 * x))
t_1 = 1.0d0 / ((s_m * x) * c_m)
if (x <= 2d+16) then
tmp = t_0 / (1.0d0 / (t_1 * t_1))
else
tmp = t_0 / ((s_m * ((x * c_m) ** 1.0d0)) ** 2.0d0)
end if
code = tmp
end function
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x < c_m && c_m < s_m;
public static double code(double x, double c_m, double s_m) {
double t_0 = Math.cos((2.0 * x));
double t_1 = 1.0 / ((s_m * x) * c_m);
double tmp;
if (x <= 2e+16) {
tmp = t_0 / (1.0 / (t_1 * t_1));
} else {
tmp = t_0 / Math.pow((s_m * Math.pow((x * c_m), 1.0)), 2.0);
}
return tmp;
}
c_m = math.fabs(c) s_m = math.fabs(s) [x, c_m, s_m] = sort([x, c_m, s_m]) def code(x, c_m, s_m): t_0 = math.cos((2.0 * x)) t_1 = 1.0 / ((s_m * x) * c_m) tmp = 0 if x <= 2e+16: tmp = t_0 / (1.0 / (t_1 * t_1)) else: tmp = t_0 / math.pow((s_m * math.pow((x * c_m), 1.0)), 2.0) return tmp
c_m = abs(c) s_m = abs(s) x, c_m, s_m = sort([x, c_m, s_m]) function code(x, c_m, s_m) t_0 = cos(Float64(2.0 * x)) t_1 = Float64(1.0 / Float64(Float64(s_m * x) * c_m)) tmp = 0.0 if (x <= 2e+16) tmp = Float64(t_0 / Float64(1.0 / Float64(t_1 * t_1))); else tmp = Float64(t_0 / (Float64(s_m * (Float64(x * c_m) ^ 1.0)) ^ 2.0)); end return tmp end
c_m = abs(c);
s_m = abs(s);
x, c_m, s_m = num2cell(sort([x, c_m, s_m])){:}
function tmp_2 = code(x, c_m, s_m)
t_0 = cos((2.0 * x));
t_1 = 1.0 / ((s_m * x) * c_m);
tmp = 0.0;
if (x <= 2e+16)
tmp = t_0 / (1.0 / (t_1 * t_1));
else
tmp = t_0 / ((s_m * ((x * c_m) ^ 1.0)) ^ 2.0);
end
tmp_2 = tmp;
end
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / N[(N[(s$95$m * x), $MachinePrecision] * c$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 2e+16], N[(t$95$0 / N[(1.0 / N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[Power[N[(s$95$m * N[Power[N[(x * c$95$m), $MachinePrecision], 1.0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x, c_m, s_m] = \mathsf{sort}([x, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := \cos \left(2 \cdot x\right)\\
t_1 := \frac{1}{\left(s\_m \cdot x\right) \cdot c\_m}\\
\mathbf{if}\;x \leq 2 \cdot 10^{+16}:\\
\;\;\;\;\frac{t\_0}{\frac{1}{t\_1 \cdot t\_1}}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{{\left(s\_m \cdot {\left(x \cdot c\_m\right)}^{1}\right)}^{2}}\\
\end{array}
\end{array}
if x < 2e16Initial program 67.3%
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
pow-prod-downN/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6497.6
Applied rewrites97.6%
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
pow-negN/A
metadata-evalN/A
pow-flipN/A
*-commutativeN/A
unpow-prod-downN/A
pow-prod-downN/A
lower-/.f64N/A
metadata-evalN/A
*-commutativeN/A
pow-prod-downN/A
unpow-prod-downN/A
unpow2N/A
times-fracN/A
lower-*.f64N/A
Applied rewrites97.6%
if 2e16 < x Initial program 64.8%
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
pow-prod-downN/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6498.7
Applied rewrites98.7%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
unpow1N/A
associate-*l*N/A
unpow-prod-downN/A
unpow1N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-*.f6498.6
Applied rewrites98.6%
c_m = (fabs.f64 c) s_m = (fabs.f64 s) NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function. (FPCore (x c_m s_m) :precision binary64 (/ (cos (* 2.0 x)) (pow (* (* s_m c_m) x) 2.0)))
c_m = fabs(c);
s_m = fabs(s);
assert(x < c_m && c_m < s_m);
double code(double x, double c_m, double s_m) {
return cos((2.0 * x)) / pow(((s_m * c_m) * x), 2.0);
}
c_m = private
s_m = private
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
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(x, c_m, s_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
code = cos((2.0d0 * x)) / (((s_m * c_m) * x) ** 2.0d0)
end function
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x < c_m && c_m < s_m;
public static double code(double x, double c_m, double s_m) {
return Math.cos((2.0 * x)) / Math.pow(((s_m * c_m) * x), 2.0);
}
c_m = math.fabs(c) s_m = math.fabs(s) [x, c_m, s_m] = sort([x, c_m, s_m]) def code(x, c_m, s_m): return math.cos((2.0 * x)) / math.pow(((s_m * c_m) * x), 2.0)
c_m = abs(c) s_m = abs(s) x, c_m, s_m = sort([x, c_m, s_m]) function code(x, c_m, s_m) return Float64(cos(Float64(2.0 * x)) / (Float64(Float64(s_m * c_m) * x) ^ 2.0)) end
c_m = abs(c);
s_m = abs(s);
x, c_m, s_m = num2cell(sort([x, c_m, s_m])){:}
function tmp = code(x, c_m, s_m)
tmp = cos((2.0 * x)) / (((s_m * c_m) * x) ^ 2.0);
end
c_m = N[Abs[c], $MachinePrecision] s_m = N[Abs[s], $MachinePrecision] NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function. code[x_, c$95$m_, s$95$m_] := N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[Power[N[(N[(s$95$m * c$95$m), $MachinePrecision] * x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x, c_m, s_m] = \mathsf{sort}([x, c_m, s_m])\\
\\
\frac{\cos \left(2 \cdot x\right)}{{\left(\left(s\_m \cdot c\_m\right) \cdot x\right)}^{2}}
\end{array}
Initial program 66.6%
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
pow-prod-downN/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6497.9
Applied rewrites97.9%
c_m = (fabs.f64 c) s_m = (fabs.f64 s) NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function. (FPCore (x c_m s_m) :precision binary64 (let* ((t_0 (/ 1.0 (* (* s_m x) c_m)))) (/ (cos (* 2.0 x)) (/ 1.0 (* t_0 t_0)))))
c_m = fabs(c);
s_m = fabs(s);
assert(x < c_m && c_m < s_m);
double code(double x, double c_m, double s_m) {
double t_0 = 1.0 / ((s_m * x) * c_m);
return cos((2.0 * x)) / (1.0 / (t_0 * t_0));
}
c_m = private
s_m = private
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
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(x, c_m, s_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: t_0
t_0 = 1.0d0 / ((s_m * x) * c_m)
code = cos((2.0d0 * x)) / (1.0d0 / (t_0 * t_0))
end function
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x < c_m && c_m < s_m;
public static double code(double x, double c_m, double s_m) {
double t_0 = 1.0 / ((s_m * x) * c_m);
return Math.cos((2.0 * x)) / (1.0 / (t_0 * t_0));
}
c_m = math.fabs(c) s_m = math.fabs(s) [x, c_m, s_m] = sort([x, c_m, s_m]) def code(x, c_m, s_m): t_0 = 1.0 / ((s_m * x) * c_m) return math.cos((2.0 * x)) / (1.0 / (t_0 * t_0))
c_m = abs(c) s_m = abs(s) x, c_m, s_m = sort([x, c_m, s_m]) function code(x, c_m, s_m) t_0 = Float64(1.0 / Float64(Float64(s_m * x) * c_m)) return Float64(cos(Float64(2.0 * x)) / Float64(1.0 / Float64(t_0 * t_0))) end
c_m = abs(c);
s_m = abs(s);
x, c_m, s_m = num2cell(sort([x, c_m, s_m])){:}
function tmp = code(x, c_m, s_m)
t_0 = 1.0 / ((s_m * x) * c_m);
tmp = cos((2.0 * x)) / (1.0 / (t_0 * t_0));
end
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(1.0 / N[(N[(s$95$m * x), $MachinePrecision] * c$95$m), $MachinePrecision]), $MachinePrecision]}, N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x, c_m, s_m] = \mathsf{sort}([x, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := \frac{1}{\left(s\_m \cdot x\right) \cdot c\_m}\\
\frac{\cos \left(2 \cdot x\right)}{\frac{1}{t\_0 \cdot t\_0}}
\end{array}
\end{array}
Initial program 66.6%
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
pow-prod-downN/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6497.9
Applied rewrites97.9%
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
metadata-evalN/A
pow-negN/A
metadata-evalN/A
pow-flipN/A
*-commutativeN/A
unpow-prod-downN/A
pow-prod-downN/A
lower-/.f64N/A
metadata-evalN/A
*-commutativeN/A
pow-prod-downN/A
unpow-prod-downN/A
unpow2N/A
times-fracN/A
lower-*.f64N/A
Applied rewrites97.4%
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c_m s_m)
:precision binary64
(let* ((t_0 (* (* s_m x) c_m))
(t_1 (* t_0 t_0))
(t_2 (cos (* 2.0 x)))
(t_3 (/ t_2 (* (* (* (* (* s_m s_m) x) x) c_m) c_m)))
(t_4 (/ t_2 (* (pow c_m 2.0) (* (* x (pow s_m 2.0)) x))))
(t_5 (- (/ (pow (cos x) 2.0) t_1) (/ (pow (sin x) 2.0) t_1))))
(if (<= t_4 (- INFINITY))
t_3
(if (<= t_4 4e+243) t_5 (if (<= t_4 INFINITY) t_3 t_5)))))c_m = fabs(c);
s_m = fabs(s);
assert(x < c_m && c_m < s_m);
double code(double x, double c_m, double s_m) {
double t_0 = (s_m * x) * c_m;
double t_1 = t_0 * t_0;
double t_2 = cos((2.0 * x));
double t_3 = t_2 / (((((s_m * s_m) * x) * x) * c_m) * c_m);
double t_4 = t_2 / (pow(c_m, 2.0) * ((x * pow(s_m, 2.0)) * x));
double t_5 = (pow(cos(x), 2.0) / t_1) - (pow(sin(x), 2.0) / t_1);
double tmp;
if (t_4 <= -((double) INFINITY)) {
tmp = t_3;
} else if (t_4 <= 4e+243) {
tmp = t_5;
} else if (t_4 <= ((double) INFINITY)) {
tmp = t_3;
} else {
tmp = t_5;
}
return tmp;
}
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x < c_m && c_m < s_m;
public static double code(double x, double c_m, double s_m) {
double t_0 = (s_m * x) * c_m;
double t_1 = t_0 * t_0;
double t_2 = Math.cos((2.0 * x));
double t_3 = t_2 / (((((s_m * s_m) * x) * x) * c_m) * c_m);
double t_4 = t_2 / (Math.pow(c_m, 2.0) * ((x * Math.pow(s_m, 2.0)) * x));
double t_5 = (Math.pow(Math.cos(x), 2.0) / t_1) - (Math.pow(Math.sin(x), 2.0) / t_1);
double tmp;
if (t_4 <= -Double.POSITIVE_INFINITY) {
tmp = t_3;
} else if (t_4 <= 4e+243) {
tmp = t_5;
} else if (t_4 <= Double.POSITIVE_INFINITY) {
tmp = t_3;
} else {
tmp = t_5;
}
return tmp;
}
c_m = math.fabs(c) s_m = math.fabs(s) [x, c_m, s_m] = sort([x, c_m, s_m]) def code(x, c_m, s_m): t_0 = (s_m * x) * c_m t_1 = t_0 * t_0 t_2 = math.cos((2.0 * x)) t_3 = t_2 / (((((s_m * s_m) * x) * x) * c_m) * c_m) t_4 = t_2 / (math.pow(c_m, 2.0) * ((x * math.pow(s_m, 2.0)) * x)) t_5 = (math.pow(math.cos(x), 2.0) / t_1) - (math.pow(math.sin(x), 2.0) / t_1) tmp = 0 if t_4 <= -math.inf: tmp = t_3 elif t_4 <= 4e+243: tmp = t_5 elif t_4 <= math.inf: tmp = t_3 else: tmp = t_5 return tmp
c_m = abs(c) s_m = abs(s) x, c_m, s_m = sort([x, c_m, s_m]) function code(x, c_m, s_m) t_0 = Float64(Float64(s_m * x) * c_m) t_1 = Float64(t_0 * t_0) t_2 = cos(Float64(2.0 * x)) t_3 = Float64(t_2 / Float64(Float64(Float64(Float64(Float64(s_m * s_m) * x) * x) * c_m) * c_m)) t_4 = Float64(t_2 / Float64((c_m ^ 2.0) * Float64(Float64(x * (s_m ^ 2.0)) * x))) t_5 = Float64(Float64((cos(x) ^ 2.0) / t_1) - Float64((sin(x) ^ 2.0) / t_1)) tmp = 0.0 if (t_4 <= Float64(-Inf)) tmp = t_3; elseif (t_4 <= 4e+243) tmp = t_5; elseif (t_4 <= Inf) tmp = t_3; else tmp = t_5; end return tmp end
c_m = abs(c);
s_m = abs(s);
x, c_m, s_m = num2cell(sort([x, c_m, s_m])){:}
function tmp_2 = code(x, c_m, s_m)
t_0 = (s_m * x) * c_m;
t_1 = t_0 * t_0;
t_2 = cos((2.0 * x));
t_3 = t_2 / (((((s_m * s_m) * x) * x) * c_m) * c_m);
t_4 = t_2 / ((c_m ^ 2.0) * ((x * (s_m ^ 2.0)) * x));
t_5 = ((cos(x) ^ 2.0) / t_1) - ((sin(x) ^ 2.0) / t_1);
tmp = 0.0;
if (t_4 <= -Inf)
tmp = t_3;
elseif (t_4 <= 4e+243)
tmp = t_5;
elseif (t_4 <= Inf)
tmp = t_3;
else
tmp = t_5;
end
tmp_2 = tmp;
end
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(N[(s$95$m * x), $MachinePrecision] * c$95$m), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 / N[(N[(N[(N[(N[(s$95$m * s$95$m), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * c$95$m), $MachinePrecision] * c$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(t$95$2 / N[(N[Power[c$95$m, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s$95$m, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[(N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision] / t$95$1), $MachinePrecision] - N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, (-Infinity)], t$95$3, If[LessEqual[t$95$4, 4e+243], t$95$5, If[LessEqual[t$95$4, Infinity], t$95$3, t$95$5]]]]]]]]]
\begin{array}{l}
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x, c_m, s_m] = \mathsf{sort}([x, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := \left(s\_m \cdot x\right) \cdot c\_m\\
t_1 := t\_0 \cdot t\_0\\
t_2 := \cos \left(2 \cdot x\right)\\
t_3 := \frac{t\_2}{\left(\left(\left(\left(s\_m \cdot s\_m\right) \cdot x\right) \cdot x\right) \cdot c\_m\right) \cdot c\_m}\\
t_4 := \frac{t\_2}{{c\_m}^{2} \cdot \left(\left(x \cdot {s\_m}^{2}\right) \cdot x\right)}\\
t_5 := \frac{{\cos x}^{2}}{t\_1} - \frac{{\sin x}^{2}}{t\_1}\\
\mathbf{if}\;t\_4 \leq -\infty:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_4 \leq 4 \cdot 10^{+243}:\\
\;\;\;\;t\_5\\
\mathbf{elif}\;t\_4 \leq \infty:\\
\;\;\;\;t\_3\\
\mathbf{else}:\\
\;\;\;\;t\_5\\
\end{array}
\end{array}
if (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) < -inf.0 or 4.0000000000000003e243 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) < +inf.0Initial program 78.5%
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6482.5
Applied rewrites82.5%
if -inf.0 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) < 4.0000000000000003e243 or +inf.0 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) Initial program 59.8%
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
pow-prod-downN/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6498.5
Applied rewrites98.5%
Applied rewrites89.2%
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c_m s_m)
:precision binary64
(let* ((t_0 (* (* s_m x) c_m))
(t_1 (* t_0 t_0))
(t_2 (cos (* 2.0 x)))
(t_3 (/ t_2 (* (* (* (* c_m c_m) x) (* s_m s_m)) x)))
(t_4 (/ t_2 (* (pow c_m 2.0) (* (* x (pow s_m 2.0)) x))))
(t_5 (- (/ (pow (cos x) 2.0) t_1) (/ (pow (sin x) 2.0) t_1))))
(if (<= t_4 (- INFINITY))
t_3
(if (<= t_4 5e+283) t_5 (if (<= t_4 INFINITY) t_3 t_5)))))c_m = fabs(c);
s_m = fabs(s);
assert(x < c_m && c_m < s_m);
double code(double x, double c_m, double s_m) {
double t_0 = (s_m * x) * c_m;
double t_1 = t_0 * t_0;
double t_2 = cos((2.0 * x));
double t_3 = t_2 / ((((c_m * c_m) * x) * (s_m * s_m)) * x);
double t_4 = t_2 / (pow(c_m, 2.0) * ((x * pow(s_m, 2.0)) * x));
double t_5 = (pow(cos(x), 2.0) / t_1) - (pow(sin(x), 2.0) / t_1);
double tmp;
if (t_4 <= -((double) INFINITY)) {
tmp = t_3;
} else if (t_4 <= 5e+283) {
tmp = t_5;
} else if (t_4 <= ((double) INFINITY)) {
tmp = t_3;
} else {
tmp = t_5;
}
return tmp;
}
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x < c_m && c_m < s_m;
public static double code(double x, double c_m, double s_m) {
double t_0 = (s_m * x) * c_m;
double t_1 = t_0 * t_0;
double t_2 = Math.cos((2.0 * x));
double t_3 = t_2 / ((((c_m * c_m) * x) * (s_m * s_m)) * x);
double t_4 = t_2 / (Math.pow(c_m, 2.0) * ((x * Math.pow(s_m, 2.0)) * x));
double t_5 = (Math.pow(Math.cos(x), 2.0) / t_1) - (Math.pow(Math.sin(x), 2.0) / t_1);
double tmp;
if (t_4 <= -Double.POSITIVE_INFINITY) {
tmp = t_3;
} else if (t_4 <= 5e+283) {
tmp = t_5;
} else if (t_4 <= Double.POSITIVE_INFINITY) {
tmp = t_3;
} else {
tmp = t_5;
}
return tmp;
}
c_m = math.fabs(c) s_m = math.fabs(s) [x, c_m, s_m] = sort([x, c_m, s_m]) def code(x, c_m, s_m): t_0 = (s_m * x) * c_m t_1 = t_0 * t_0 t_2 = math.cos((2.0 * x)) t_3 = t_2 / ((((c_m * c_m) * x) * (s_m * s_m)) * x) t_4 = t_2 / (math.pow(c_m, 2.0) * ((x * math.pow(s_m, 2.0)) * x)) t_5 = (math.pow(math.cos(x), 2.0) / t_1) - (math.pow(math.sin(x), 2.0) / t_1) tmp = 0 if t_4 <= -math.inf: tmp = t_3 elif t_4 <= 5e+283: tmp = t_5 elif t_4 <= math.inf: tmp = t_3 else: tmp = t_5 return tmp
c_m = abs(c) s_m = abs(s) x, c_m, s_m = sort([x, c_m, s_m]) function code(x, c_m, s_m) t_0 = Float64(Float64(s_m * x) * c_m) t_1 = Float64(t_0 * t_0) t_2 = cos(Float64(2.0 * x)) t_3 = Float64(t_2 / Float64(Float64(Float64(Float64(c_m * c_m) * x) * Float64(s_m * s_m)) * x)) t_4 = Float64(t_2 / Float64((c_m ^ 2.0) * Float64(Float64(x * (s_m ^ 2.0)) * x))) t_5 = Float64(Float64((cos(x) ^ 2.0) / t_1) - Float64((sin(x) ^ 2.0) / t_1)) tmp = 0.0 if (t_4 <= Float64(-Inf)) tmp = t_3; elseif (t_4 <= 5e+283) tmp = t_5; elseif (t_4 <= Inf) tmp = t_3; else tmp = t_5; end return tmp end
c_m = abs(c);
s_m = abs(s);
x, c_m, s_m = num2cell(sort([x, c_m, s_m])){:}
function tmp_2 = code(x, c_m, s_m)
t_0 = (s_m * x) * c_m;
t_1 = t_0 * t_0;
t_2 = cos((2.0 * x));
t_3 = t_2 / ((((c_m * c_m) * x) * (s_m * s_m)) * x);
t_4 = t_2 / ((c_m ^ 2.0) * ((x * (s_m ^ 2.0)) * x));
t_5 = ((cos(x) ^ 2.0) / t_1) - ((sin(x) ^ 2.0) / t_1);
tmp = 0.0;
if (t_4 <= -Inf)
tmp = t_3;
elseif (t_4 <= 5e+283)
tmp = t_5;
elseif (t_4 <= Inf)
tmp = t_3;
else
tmp = t_5;
end
tmp_2 = tmp;
end
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(N[(s$95$m * x), $MachinePrecision] * c$95$m), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 / N[(N[(N[(N[(c$95$m * c$95$m), $MachinePrecision] * x), $MachinePrecision] * N[(s$95$m * s$95$m), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(t$95$2 / N[(N[Power[c$95$m, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s$95$m, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[(N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision] / t$95$1), $MachinePrecision] - N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, (-Infinity)], t$95$3, If[LessEqual[t$95$4, 5e+283], t$95$5, If[LessEqual[t$95$4, Infinity], t$95$3, t$95$5]]]]]]]]]
\begin{array}{l}
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x, c_m, s_m] = \mathsf{sort}([x, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := \left(s\_m \cdot x\right) \cdot c\_m\\
t_1 := t\_0 \cdot t\_0\\
t_2 := \cos \left(2 \cdot x\right)\\
t_3 := \frac{t\_2}{\left(\left(\left(c\_m \cdot c\_m\right) \cdot x\right) \cdot \left(s\_m \cdot s\_m\right)\right) \cdot x}\\
t_4 := \frac{t\_2}{{c\_m}^{2} \cdot \left(\left(x \cdot {s\_m}^{2}\right) \cdot x\right)}\\
t_5 := \frac{{\cos x}^{2}}{t\_1} - \frac{{\sin x}^{2}}{t\_1}\\
\mathbf{if}\;t\_4 \leq -\infty:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_4 \leq 5 \cdot 10^{+283}:\\
\;\;\;\;t\_5\\
\mathbf{elif}\;t\_4 \leq \infty:\\
\;\;\;\;t\_3\\
\mathbf{else}:\\
\;\;\;\;t\_5\\
\end{array}
\end{array}
if (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) < -inf.0 or 5.0000000000000004e283 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) < +inf.0Initial program 78.3%
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6483.3
Applied rewrites83.3%
if -inf.0 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) < 5.0000000000000004e283 or +inf.0 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) Initial program 60.1%
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
pow-prod-downN/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6498.5
Applied rewrites98.5%
Applied rewrites89.3%
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c_m s_m)
:precision binary64
(let* ((t_0 (/ (cos (* 2.0 x)) (* (pow c_m 2.0) (* (* x (pow s_m 2.0)) x))))
(t_1 (* (* s_m x) c_m))
(t_2 (* t_1 t_1))
(t_3 (- (/ (pow (cos x) 2.0) t_2) (/ (pow (sin x) 2.0) t_2))))
(if (<= t_0 4e+243)
t_3
(if (<= t_0 INFINITY)
(/ (/ (sin (fma x 2.0 (/ PI 2.0))) (pow (* c_m s_m) 2.0)) (* x x))
t_3))))c_m = fabs(c);
s_m = fabs(s);
assert(x < c_m && c_m < s_m);
double code(double x, double c_m, double s_m) {
double t_0 = cos((2.0 * x)) / (pow(c_m, 2.0) * ((x * pow(s_m, 2.0)) * x));
double t_1 = (s_m * x) * c_m;
double t_2 = t_1 * t_1;
double t_3 = (pow(cos(x), 2.0) / t_2) - (pow(sin(x), 2.0) / t_2);
double tmp;
if (t_0 <= 4e+243) {
tmp = t_3;
} else if (t_0 <= ((double) INFINITY)) {
tmp = (sin(fma(x, 2.0, (((double) M_PI) / 2.0))) / pow((c_m * s_m), 2.0)) / (x * x);
} else {
tmp = t_3;
}
return tmp;
}
c_m = abs(c) s_m = abs(s) x, c_m, s_m = sort([x, c_m, s_m]) function code(x, c_m, s_m) t_0 = Float64(cos(Float64(2.0 * x)) / Float64((c_m ^ 2.0) * Float64(Float64(x * (s_m ^ 2.0)) * x))) t_1 = Float64(Float64(s_m * x) * c_m) t_2 = Float64(t_1 * t_1) t_3 = Float64(Float64((cos(x) ^ 2.0) / t_2) - Float64((sin(x) ^ 2.0) / t_2)) tmp = 0.0 if (t_0 <= 4e+243) tmp = t_3; elseif (t_0 <= Inf) tmp = Float64(Float64(sin(fma(x, 2.0, Float64(pi / 2.0))) / (Float64(c_m * s_m) ^ 2.0)) / Float64(x * x)); else tmp = t_3; end return tmp end
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c$95$m, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s$95$m, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(s$95$m * x), $MachinePrecision] * c$95$m), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision] / t$95$2), $MachinePrecision] - N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / t$95$2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 4e+243], t$95$3, If[LessEqual[t$95$0, Infinity], N[(N[(N[Sin[N[(x * 2.0 + N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Power[N[(c$95$m * s$95$m), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]
\begin{array}{l}
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x, c_m, s_m] = \mathsf{sort}([x, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := \frac{\cos \left(2 \cdot x\right)}{{c\_m}^{2} \cdot \left(\left(x \cdot {s\_m}^{2}\right) \cdot x\right)}\\
t_1 := \left(s\_m \cdot x\right) \cdot c\_m\\
t_2 := t\_1 \cdot t\_1\\
t_3 := \frac{{\cos x}^{2}}{t\_2} - \frac{{\sin x}^{2}}{t\_2}\\
\mathbf{if}\;t\_0 \leq 4 \cdot 10^{+243}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\frac{\frac{\sin \left(\mathsf{fma}\left(x, 2, \frac{\pi}{2}\right)\right)}{{\left(c\_m \cdot s\_m\right)}^{2}}}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
\end{array}
if (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) < 4.0000000000000003e243 or +inf.0 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) Initial program 59.9%
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
pow-prod-downN/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6497.1
Applied rewrites97.1%
Applied rewrites84.2%
if 4.0000000000000003e243 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) < +inf.0Initial program 83.3%
lift-/.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
cos-2N/A
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
div-subN/A
Applied rewrites5.4%
Taylor expanded in x around inf
Applied rewrites82.9%
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c_m s_m)
:precision binary64
(let* ((t_0 (pow (* c_m x) 1.0)) (t_1 (* t_0 t_0)))
(if (<= x 2.7e+93)
(/ (/ (sin (fma x 2.0 (/ PI 2.0))) (pow (* c_m s_m) 2.0)) (* x x))
(-
(/ (/ (pow (cos x) 2.0) t_1) (* s_m s_m))
(/ (/ (pow (sin x) 2.0) t_1) (* s_m s_m))))))c_m = fabs(c);
s_m = fabs(s);
assert(x < c_m && c_m < s_m);
double code(double x, double c_m, double s_m) {
double t_0 = pow((c_m * x), 1.0);
double t_1 = t_0 * t_0;
double tmp;
if (x <= 2.7e+93) {
tmp = (sin(fma(x, 2.0, (((double) M_PI) / 2.0))) / pow((c_m * s_m), 2.0)) / (x * x);
} else {
tmp = ((pow(cos(x), 2.0) / t_1) / (s_m * s_m)) - ((pow(sin(x), 2.0) / t_1) / (s_m * s_m));
}
return tmp;
}
c_m = abs(c) s_m = abs(s) x, c_m, s_m = sort([x, c_m, s_m]) function code(x, c_m, s_m) t_0 = Float64(c_m * x) ^ 1.0 t_1 = Float64(t_0 * t_0) tmp = 0.0 if (x <= 2.7e+93) tmp = Float64(Float64(sin(fma(x, 2.0, Float64(pi / 2.0))) / (Float64(c_m * s_m) ^ 2.0)) / Float64(x * x)); else tmp = Float64(Float64(Float64((cos(x) ^ 2.0) / t_1) / Float64(s_m * s_m)) - Float64(Float64((sin(x) ^ 2.0) / t_1) / Float64(s_m * s_m))); end return tmp end
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[Power[N[(c$95$m * x), $MachinePrecision], 1.0], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * t$95$0), $MachinePrecision]}, If[LessEqual[x, 2.7e+93], N[(N[(N[Sin[N[(x * 2.0 + N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Power[N[(c$95$m * s$95$m), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision] / t$95$1), $MachinePrecision] / N[(s$95$m * s$95$m), $MachinePrecision]), $MachinePrecision] - N[(N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / t$95$1), $MachinePrecision] / N[(s$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x, c_m, s_m] = \mathsf{sort}([x, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := {\left(c\_m \cdot x\right)}^{1}\\
t_1 := t\_0 \cdot t\_0\\
\mathbf{if}\;x \leq 2.7 \cdot 10^{+93}:\\
\;\;\;\;\frac{\frac{\sin \left(\mathsf{fma}\left(x, 2, \frac{\pi}{2}\right)\right)}{{\left(c\_m \cdot s\_m\right)}^{2}}}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{{\cos x}^{2}}{t\_1}}{s\_m \cdot s\_m} - \frac{\frac{{\sin x}^{2}}{t\_1}}{s\_m \cdot s\_m}\\
\end{array}
\end{array}
if x < 2.6999999999999999e93Initial program 68.3%
lift-/.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
cos-2N/A
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
div-subN/A
Applied rewrites39.6%
Taylor expanded in x around inf
Applied rewrites74.0%
if 2.6999999999999999e93 < x Initial program 59.6%
lift-/.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
cos-2N/A
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
div-subN/A
Applied rewrites57.4%
Taylor expanded in s around 0
Applied rewrites69.3%
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c_m s_m)
:precision binary64
(let* ((t_0 (pow (* c_m x) 1.0)) (t_1 (* t_0 t_0)))
(-
(/ (/ (pow (cos x) 2.0) t_1) (* s_m s_m))
(/ (/ (pow (sin x) 2.0) t_1) (* s_m s_m)))))c_m = fabs(c);
s_m = fabs(s);
assert(x < c_m && c_m < s_m);
double code(double x, double c_m, double s_m) {
double t_0 = pow((c_m * x), 1.0);
double t_1 = t_0 * t_0;
return ((pow(cos(x), 2.0) / t_1) / (s_m * s_m)) - ((pow(sin(x), 2.0) / t_1) / (s_m * s_m));
}
c_m = private
s_m = private
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
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(x, c_m, s_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: t_0
real(8) :: t_1
t_0 = (c_m * x) ** 1.0d0
t_1 = t_0 * t_0
code = (((cos(x) ** 2.0d0) / t_1) / (s_m * s_m)) - (((sin(x) ** 2.0d0) / t_1) / (s_m * s_m))
end function
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x < c_m && c_m < s_m;
public static double code(double x, double c_m, double s_m) {
double t_0 = Math.pow((c_m * x), 1.0);
double t_1 = t_0 * t_0;
return ((Math.pow(Math.cos(x), 2.0) / t_1) / (s_m * s_m)) - ((Math.pow(Math.sin(x), 2.0) / t_1) / (s_m * s_m));
}
c_m = math.fabs(c) s_m = math.fabs(s) [x, c_m, s_m] = sort([x, c_m, s_m]) def code(x, c_m, s_m): t_0 = math.pow((c_m * x), 1.0) t_1 = t_0 * t_0 return ((math.pow(math.cos(x), 2.0) / t_1) / (s_m * s_m)) - ((math.pow(math.sin(x), 2.0) / t_1) / (s_m * s_m))
c_m = abs(c) s_m = abs(s) x, c_m, s_m = sort([x, c_m, s_m]) function code(x, c_m, s_m) t_0 = Float64(c_m * x) ^ 1.0 t_1 = Float64(t_0 * t_0) return Float64(Float64(Float64((cos(x) ^ 2.0) / t_1) / Float64(s_m * s_m)) - Float64(Float64((sin(x) ^ 2.0) / t_1) / Float64(s_m * s_m))) end
c_m = abs(c);
s_m = abs(s);
x, c_m, s_m = num2cell(sort([x, c_m, s_m])){:}
function tmp = code(x, c_m, s_m)
t_0 = (c_m * x) ^ 1.0;
t_1 = t_0 * t_0;
tmp = (((cos(x) ^ 2.0) / t_1) / (s_m * s_m)) - (((sin(x) ^ 2.0) / t_1) / (s_m * s_m));
end
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[Power[N[(c$95$m * x), $MachinePrecision], 1.0], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * t$95$0), $MachinePrecision]}, N[(N[(N[(N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision] / t$95$1), $MachinePrecision] / N[(s$95$m * s$95$m), $MachinePrecision]), $MachinePrecision] - N[(N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / t$95$1), $MachinePrecision] / N[(s$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x, c_m, s_m] = \mathsf{sort}([x, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := {\left(c\_m \cdot x\right)}^{1}\\
t_1 := t\_0 \cdot t\_0\\
\frac{\frac{{\cos x}^{2}}{t\_1}}{s\_m \cdot s\_m} - \frac{\frac{{\sin x}^{2}}{t\_1}}{s\_m \cdot s\_m}
\end{array}
\end{array}
Initial program 66.6%
lift-/.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
cos-2N/A
lift-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
div-subN/A
Applied rewrites42.9%
Taylor expanded in s around 0
Applied rewrites47.1%
herbie shell --seed 2025065
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))