
(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 13 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}
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
:precision binary64
(let* ((t_0 (* (* s_m x) c)) (t_1 (cos (* 2.0 x))) (t_2 (* (* c s_m) x)))
(if (<= (/ t_1 (* (pow c 2.0) (* (* x (pow s_m 2.0)) x))) INFINITY)
(/ t_1 (* t_0 t_0))
(/ (cos (+ x x)) (* t_2 t_2)))))s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
double t_0 = (s_m * x) * c;
double t_1 = cos((2.0 * x));
double t_2 = (c * s_m) * x;
double tmp;
if ((t_1 / (pow(c, 2.0) * ((x * pow(s_m, 2.0)) * x))) <= ((double) INFINITY)) {
tmp = t_1 / (t_0 * t_0);
} else {
tmp = cos((x + x)) / (t_2 * t_2);
}
return tmp;
}
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
double t_0 = (s_m * x) * c;
double t_1 = Math.cos((2.0 * x));
double t_2 = (c * s_m) * x;
double tmp;
if ((t_1 / (Math.pow(c, 2.0) * ((x * Math.pow(s_m, 2.0)) * x))) <= Double.POSITIVE_INFINITY) {
tmp = t_1 / (t_0 * t_0);
} else {
tmp = Math.cos((x + x)) / (t_2 * t_2);
}
return tmp;
}
s_m = math.fabs(s) [x, c, s_m] = sort([x, c, s_m]) def code(x, c, s_m): t_0 = (s_m * x) * c t_1 = math.cos((2.0 * x)) t_2 = (c * s_m) * x tmp = 0 if (t_1 / (math.pow(c, 2.0) * ((x * math.pow(s_m, 2.0)) * x))) <= math.inf: tmp = t_1 / (t_0 * t_0) else: tmp = math.cos((x + x)) / (t_2 * t_2) return tmp
s_m = abs(s) x, c, s_m = sort([x, c, s_m]) function code(x, c, s_m) t_0 = Float64(Float64(s_m * x) * c) t_1 = cos(Float64(2.0 * x)) t_2 = Float64(Float64(c * s_m) * x) tmp = 0.0 if (Float64(t_1 / Float64((c ^ 2.0) * Float64(Float64(x * (s_m ^ 2.0)) * x))) <= Inf) tmp = Float64(t_1 / Float64(t_0 * t_0)); else tmp = Float64(cos(Float64(x + x)) / Float64(t_2 * t_2)); end return tmp end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp_2 = code(x, c, s_m)
t_0 = (s_m * x) * c;
t_1 = cos((2.0 * x));
t_2 = (c * s_m) * x;
tmp = 0.0;
if ((t_1 / ((c ^ 2.0) * ((x * (s_m ^ 2.0)) * x))) <= Inf)
tmp = t_1 / (t_0 * t_0);
else
tmp = cos((x + x)) / (t_2 * t_2);
end
tmp_2 = tmp;
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(s$95$m * x), $MachinePrecision] * c), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[N[(t$95$1 / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s$95$m, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(t$95$1 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(s\_m \cdot x\right) \cdot c\\
t_1 := \cos \left(2 \cdot x\right)\\
t_2 := \left(c \cdot s\_m\right) \cdot x\\
\mathbf{if}\;\frac{t\_1}{{c}^{2} \cdot \left(\left(x \cdot {s\_m}^{2}\right) \cdot x\right)} \leq \infty:\\
\;\;\;\;\frac{t\_1}{t\_0 \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(x + x\right)}{t\_2 \cdot t\_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))) < +inf.0Initial program 84.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-*.f6497.3
Applied rewrites97.3%
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
unpow-prod-downN/A
lift-*.f64N/A
unpow-prod-downN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
unpow-prod-downN/A
pow2N/A
sqr-neg-revN/A
pow2N/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6499.3
Applied rewrites99.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))) Initial program 0.0%
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-*.f6496.5
Applied rewrites96.5%
lift-pow.f64N/A
unpow2N/A
lower-*.f6496.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6496.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6496.4
Applied rewrites96.4%
lift-*.f64N/A
count-2-revN/A
lower-+.f6496.4
Applied rewrites96.4%
Final simplification98.5%
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
:precision binary64
(let* ((t_0 (* (* c s_m) x)) (t_1 (/ (/ -1.0 c) (* s_m x))))
(if (<=
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s_m 2.0)) x)))
-4e-119)
(/ (- (* -2.0 (* x x)) -1.0) (* t_0 t_0))
(* t_1 t_1))))s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
double t_0 = (c * s_m) * x;
double t_1 = (-1.0 / c) / (s_m * x);
double tmp;
if ((cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s_m, 2.0)) * x))) <= -4e-119) {
tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0);
} else {
tmp = t_1 * t_1;
}
return tmp;
}
s_m = private
NOTE: x, c, 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, s_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s_m
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (c * s_m) * x
t_1 = ((-1.0d0) / c) / (s_m * x)
if ((cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s_m ** 2.0d0)) * x))) <= (-4d-119)) then
tmp = (((-2.0d0) * (x * x)) - (-1.0d0)) / (t_0 * t_0)
else
tmp = t_1 * t_1
end if
code = tmp
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
double t_0 = (c * s_m) * x;
double t_1 = (-1.0 / c) / (s_m * x);
double tmp;
if ((Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s_m, 2.0)) * x))) <= -4e-119) {
tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0);
} else {
tmp = t_1 * t_1;
}
return tmp;
}
s_m = math.fabs(s) [x, c, s_m] = sort([x, c, s_m]) def code(x, c, s_m): t_0 = (c * s_m) * x t_1 = (-1.0 / c) / (s_m * x) tmp = 0 if (math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s_m, 2.0)) * x))) <= -4e-119: tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0) else: tmp = t_1 * t_1 return tmp
s_m = abs(s) x, c, s_m = sort([x, c, s_m]) function code(x, c, s_m) t_0 = Float64(Float64(c * s_m) * x) t_1 = Float64(Float64(-1.0 / c) / Float64(s_m * x)) tmp = 0.0 if (Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s_m ^ 2.0)) * x))) <= -4e-119) tmp = Float64(Float64(Float64(-2.0 * Float64(x * x)) - -1.0) / Float64(t_0 * t_0)); else tmp = Float64(t_1 * t_1); end return tmp end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp_2 = code(x, c, s_m)
t_0 = (c * s_m) * x;
t_1 = (-1.0 / c) / (s_m * x);
tmp = 0.0;
if ((cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s_m ^ 2.0)) * x))) <= -4e-119)
tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0);
else
tmp = t_1 * t_1;
end
tmp_2 = tmp;
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[(N[(-1.0 / c), $MachinePrecision] / N[(s$95$m * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s$95$m, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -4e-119], N[(N[(N[(-2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision] - -1.0), $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(t$95$1 * t$95$1), $MachinePrecision]]]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot s\_m\right) \cdot x\\
t_1 := \frac{\frac{-1}{c}}{s\_m \cdot x}\\
\mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s\_m}^{2}\right) \cdot x\right)} \leq -4 \cdot 10^{-119}:\\
\;\;\;\;\frac{-2 \cdot \left(x \cdot x\right) - -1}{t\_0 \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot t\_1\\
\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.00000000000000005e-119Initial program 76.4%
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.2
Applied rewrites99.2%
lift-pow.f64N/A
unpow2N/A
lower-*.f6499.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.2
Applied rewrites99.2%
Taylor expanded in x around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6452.5
Applied rewrites52.5%
if -4.00000000000000005e-119 < (/.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 61.5%
Taylor expanded in x around 0
associate-/r*N/A
metadata-evalN/A
unpow2N/A
times-fracN/A
pow-prod-downN/A
unpow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lower-*.f6459.2
Applied rewrites59.2%
lift-/.f64N/A
lift-*.f64N/A
lift-ratio-of-squares.f64N/A
sqr-neg-revN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
lower-/.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f6481.1
Applied rewrites81.1%
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
:precision binary64
(let* ((t_0 (* (* c s_m) x)))
(if (<=
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s_m 2.0)) x)))
-4e-119)
(/ (- (* -2.0 (* x x)) -1.0) (* t_0 t_0))
(/ (/ 1.0 t_0) t_0))))s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
double t_0 = (c * s_m) * x;
double tmp;
if ((cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s_m, 2.0)) * x))) <= -4e-119) {
tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0);
} else {
tmp = (1.0 / t_0) / t_0;
}
return tmp;
}
s_m = private
NOTE: x, c, 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, s_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s_m
real(8) :: t_0
real(8) :: tmp
t_0 = (c * s_m) * x
if ((cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s_m ** 2.0d0)) * x))) <= (-4d-119)) then
tmp = (((-2.0d0) * (x * x)) - (-1.0d0)) / (t_0 * t_0)
else
tmp = (1.0d0 / t_0) / t_0
end if
code = tmp
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
double t_0 = (c * s_m) * x;
double tmp;
if ((Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s_m, 2.0)) * x))) <= -4e-119) {
tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0);
} else {
tmp = (1.0 / t_0) / t_0;
}
return tmp;
}
s_m = math.fabs(s) [x, c, s_m] = sort([x, c, s_m]) def code(x, c, s_m): t_0 = (c * s_m) * x tmp = 0 if (math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s_m, 2.0)) * x))) <= -4e-119: tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0) else: tmp = (1.0 / t_0) / t_0 return tmp
s_m = abs(s) x, c, s_m = sort([x, c, s_m]) function code(x, c, s_m) t_0 = Float64(Float64(c * s_m) * x) tmp = 0.0 if (Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s_m ^ 2.0)) * x))) <= -4e-119) tmp = Float64(Float64(Float64(-2.0 * Float64(x * x)) - -1.0) / Float64(t_0 * t_0)); else tmp = Float64(Float64(1.0 / t_0) / t_0); end return tmp end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp_2 = code(x, c, s_m)
t_0 = (c * s_m) * x;
tmp = 0.0;
if ((cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s_m ^ 2.0)) * x))) <= -4e-119)
tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0);
else
tmp = (1.0 / t_0) / t_0;
end
tmp_2 = tmp;
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s$95$m, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -4e-119], N[(N[(N[(-2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision] - -1.0), $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot s\_m\right) \cdot x\\
\mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s\_m}^{2}\right) \cdot x\right)} \leq -4 \cdot 10^{-119}:\\
\;\;\;\;\frac{-2 \cdot \left(x \cdot x\right) - -1}{t\_0 \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{t\_0}}{t\_0}\\
\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.00000000000000005e-119Initial program 76.4%
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.2
Applied rewrites99.2%
lift-pow.f64N/A
unpow2N/A
lower-*.f6499.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.2
Applied rewrites99.2%
Taylor expanded in x around 0
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6452.5
Applied rewrites52.5%
if -4.00000000000000005e-119 < (/.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 61.5%
Taylor expanded in x around 0
associate-/r*N/A
metadata-evalN/A
unpow2N/A
times-fracN/A
pow-prod-downN/A
unpow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lower-*.f6459.2
Applied rewrites59.2%
lift-/.f64N/A
lift-*.f64N/A
lift-ratio-of-squares.f64N/A
frac-timesN/A
metadata-evalN/A
pow2N/A
pow2N/A
unpow-prod-downN/A
associate-/r*N/A
associate-*r*N/A
*-commutativeN/A
unpow-prod-downN/A
lift-*.f64N/A
unpow-prod-downN/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
unpow2N/A
associate-/r*N/A
Applied rewrites80.3%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (let* ((t_0 (* (* c s_m) x))) (/ (/ (cos (* -2.0 x)) t_0) t_0)))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
double t_0 = (c * s_m) * x;
return (cos((-2.0 * x)) / t_0) / t_0;
}
s_m = private
NOTE: x, c, 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, s_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s_m
real(8) :: t_0
t_0 = (c * s_m) * x
code = (cos(((-2.0d0) * x)) / t_0) / t_0
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
double t_0 = (c * s_m) * x;
return (Math.cos((-2.0 * x)) / t_0) / t_0;
}
s_m = math.fabs(s) [x, c, s_m] = sort([x, c, s_m]) def code(x, c, s_m): t_0 = (c * s_m) * x return (math.cos((-2.0 * x)) / t_0) / t_0
s_m = abs(s) x, c, s_m = sort([x, c, s_m]) function code(x, c, s_m) t_0 = Float64(Float64(c * s_m) * x) return Float64(Float64(cos(Float64(-2.0 * x)) / t_0) / t_0) end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp = code(x, c, s_m)
t_0 = (c * s_m) * x;
tmp = (cos((-2.0 * x)) / t_0) / t_0;
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, N[(N[(N[Cos[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot s\_m\right) \cdot x\\
\frac{\frac{\cos \left(-2 \cdot x\right)}{t\_0}}{t\_0}
\end{array}
\end{array}
Initial program 62.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
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%
lift-*.f64N/A
lift-cos.f64N/A
metadata-evalN/A
distribute-lft-neg-inN/A
cos-neg-revN/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
unpow-prod-downN/A
lift-*.f64N/A
unpow-prod-downN/A
*-commutativeN/A
associate-*r*N/A
lower-/.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
Applied rewrites97.4%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (let* ((t_0 (* (* c s_m) x))) (/ (cos (+ x x)) (* t_0 t_0))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
double t_0 = (c * s_m) * x;
return cos((x + x)) / (t_0 * t_0);
}
s_m = private
NOTE: x, c, 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, s_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s_m
real(8) :: t_0
t_0 = (c * s_m) * x
code = cos((x + x)) / (t_0 * t_0)
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
double t_0 = (c * s_m) * x;
return Math.cos((x + x)) / (t_0 * t_0);
}
s_m = math.fabs(s) [x, c, s_m] = sort([x, c, s_m]) def code(x, c, s_m): t_0 = (c * s_m) * x return math.cos((x + x)) / (t_0 * t_0)
s_m = abs(s) x, c, s_m = sort([x, c, s_m]) function code(x, c, s_m) t_0 = Float64(Float64(c * s_m) * x) return Float64(cos(Float64(x + x)) / Float64(t_0 * t_0)) end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp = code(x, c, s_m)
t_0 = (c * s_m) * x;
tmp = cos((x + x)) / (t_0 * t_0);
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot s\_m\right) \cdot x\\
\frac{\cos \left(x + x\right)}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Initial program 62.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
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%
lift-pow.f64N/A
unpow2N/A
lower-*.f6497.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6497.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6497.1
Applied rewrites97.1%
lift-*.f64N/A
count-2-revN/A
lower-+.f6497.1
Applied rewrites97.1%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (if (<= (pow s_m 2.0) 1e-122) (/ (ratio-of-squares (/ -1.0 c) s_m) (* x x)) (ratio-of-squares (/ 1.0 (* s_m x)) c)))
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
\mathbf{if}\;{s\_m}^{2} \leq 10^{-122}:\\
\;\;\;\;\frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), s\_m\right)}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s\_m \cdot x}\right), c\right)\\
\end{array}
\end{array}
if (pow.f64 s #s(literal 2 binary64)) < 1.00000000000000006e-122Initial program 62.9%
Taylor expanded in x around 0
associate-/r*N/A
metadata-evalN/A
unpow2N/A
times-fracN/A
pow-prod-downN/A
unpow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lower-*.f6442.2
Applied rewrites42.2%
lift-/.f64N/A
lift-*.f64N/A
lift-ratio-of-squares.f64N/A
frac-timesN/A
metadata-evalN/A
pow2N/A
pow2N/A
unpow-prod-downN/A
associate-/r*N/A
associate-/r*N/A
metadata-evalN/A
*-commutativeN/A
unpow-prod-downN/A
lift-*.f64N/A
unpow2N/A
times-fracN/A
pow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f6451.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6451.8
Applied rewrites51.8%
lift-ratio-of-squares.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
frac-timesN/A
metadata-evalN/A
pow2N/A
pow-prod-downN/A
pow2N/A
lower-/.f64N/A
Applied rewrites62.8%
if 1.00000000000000006e-122 < (pow.f64 s #s(literal 2 binary64)) Initial program 62.3%
Taylor expanded in x around 0
associate-/r*N/A
metadata-evalN/A
unpow2N/A
times-fracN/A
pow-prod-downN/A
unpow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lower-*.f6464.0
Applied rewrites64.0%
lift-/.f64N/A
lift-*.f64N/A
lift-ratio-of-squares.f64N/A
frac-timesN/A
metadata-evalN/A
pow2N/A
pow2N/A
unpow-prod-downN/A
associate-/r*N/A
*-commutativeN/A
associate-/r*N/A
metadata-evalN/A
unpow-prod-downN/A
pow2N/A
times-fracN/A
pow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lift-*.f6479.2
Applied rewrites79.2%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (if (<= (pow s_m 2.0) 2e-144) (ratio-of-squares (/ 1.0 c) (* s_m x)) (ratio-of-squares (/ 1.0 (* c s_m)) x)))
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
\mathbf{if}\;{s\_m}^{2} \leq 2 \cdot 10^{-144}:\\
\;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s\_m \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c \cdot s\_m}\right), x\right)\\
\end{array}
\end{array}
if (pow.f64 s #s(literal 2 binary64)) < 1.9999999999999999e-144Initial program 61.4%
Taylor expanded in x around 0
associate-/r*N/A
metadata-evalN/A
unpow2N/A
times-fracN/A
pow-prod-downN/A
unpow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lower-*.f6439.9
Applied rewrites39.9%
if 1.9999999999999999e-144 < (pow.f64 s #s(literal 2 binary64)) Initial program 63.3%
Taylor expanded in x around 0
associate-/r*N/A
metadata-evalN/A
unpow2N/A
times-fracN/A
pow-prod-downN/A
unpow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lower-*.f6464.9
Applied rewrites64.9%
lift-/.f64N/A
lift-*.f64N/A
lift-ratio-of-squares.f64N/A
frac-timesN/A
metadata-evalN/A
pow2N/A
pow2N/A
unpow-prod-downN/A
associate-/r*N/A
associate-/r*N/A
metadata-evalN/A
*-commutativeN/A
unpow-prod-downN/A
lift-*.f64N/A
unpow2N/A
times-fracN/A
pow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f6477.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6477.1
Applied rewrites77.1%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (let* ((t_0 (* (* c s_m) x))) (/ (/ 1.0 t_0) t_0)))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
double t_0 = (c * s_m) * x;
return (1.0 / t_0) / t_0;
}
s_m = private
NOTE: x, c, 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, s_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s_m
real(8) :: t_0
t_0 = (c * s_m) * x
code = (1.0d0 / t_0) / t_0
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
double t_0 = (c * s_m) * x;
return (1.0 / t_0) / t_0;
}
s_m = math.fabs(s) [x, c, s_m] = sort([x, c, s_m]) def code(x, c, s_m): t_0 = (c * s_m) * x return (1.0 / t_0) / t_0
s_m = abs(s) x, c, s_m = sort([x, c, s_m]) function code(x, c, s_m) t_0 = Float64(Float64(c * s_m) * x) return Float64(Float64(1.0 / t_0) / t_0) end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp = code(x, c, s_m)
t_0 = (c * s_m) * x;
tmp = (1.0 / t_0) / t_0;
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, N[(N[(1.0 / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot s\_m\right) \cdot x\\
\frac{\frac{1}{t\_0}}{t\_0}
\end{array}
\end{array}
Initial program 62.5%
Taylor expanded in x around 0
associate-/r*N/A
metadata-evalN/A
unpow2N/A
times-fracN/A
pow-prod-downN/A
unpow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lower-*.f6455.1
Applied rewrites55.1%
lift-/.f64N/A
lift-*.f64N/A
lift-ratio-of-squares.f64N/A
frac-timesN/A
metadata-evalN/A
pow2N/A
pow2N/A
unpow-prod-downN/A
associate-/r*N/A
associate-*r*N/A
*-commutativeN/A
unpow-prod-downN/A
lift-*.f64N/A
unpow-prod-downN/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
unpow2N/A
associate-/r*N/A
Applied rewrites74.7%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (if (<= s_m 1.65e+62) (/ (/ (ratio-of-squares (/ -1.0 c) x) s_m) s_m) (ratio-of-squares (/ 1.0 (* s_m x)) c)))
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
\mathbf{if}\;s\_m \leq 1.65 \cdot 10^{+62}:\\
\;\;\;\;\frac{\frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), x\right)}{s\_m}}{s\_m}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s\_m \cdot x}\right), c\right)\\
\end{array}
\end{array}
if s < 1.65e62Initial program 61.5%
Taylor expanded in x around 0
associate-/r*N/A
metadata-evalN/A
unpow2N/A
times-fracN/A
pow-prod-downN/A
unpow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lower-*.f6452.5
Applied rewrites52.5%
lift-/.f64N/A
lift-*.f64N/A
lift-ratio-of-squares.f64N/A
frac-timesN/A
metadata-evalN/A
pow2N/A
pow2N/A
unpow-prod-downN/A
associate-/r*N/A
associate-/r*N/A
metadata-evalN/A
*-commutativeN/A
unpow-prod-downN/A
lift-*.f64N/A
unpow2N/A
times-fracN/A
pow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f6463.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6463.1
Applied rewrites63.1%
lift-ratio-of-squares.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
frac-timesN/A
times-fracN/A
metadata-evalN/A
pow2N/A
lift-*.f64N/A
pow2N/A
associate-/r*N/A
*-commutativeN/A
associate-/r*N/A
Applied rewrites66.1%
if 1.65e62 < s Initial program 68.1%
Taylor expanded in x around 0
associate-/r*N/A
metadata-evalN/A
unpow2N/A
times-fracN/A
pow-prod-downN/A
unpow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lower-*.f6469.2
Applied rewrites69.2%
lift-/.f64N/A
lift-*.f64N/A
lift-ratio-of-squares.f64N/A
frac-timesN/A
metadata-evalN/A
pow2N/A
pow2N/A
unpow-prod-downN/A
associate-/r*N/A
*-commutativeN/A
associate-/r*N/A
metadata-evalN/A
unpow-prod-downN/A
pow2N/A
times-fracN/A
pow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lift-*.f6489.1
Applied rewrites89.1%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (let* ((t_0 (* (* c s_m) x))) (/ 1.0 (* t_0 t_0))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
double t_0 = (c * s_m) * x;
return 1.0 / (t_0 * t_0);
}
s_m = private
NOTE: x, c, 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, s_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s_m
real(8) :: t_0
t_0 = (c * s_m) * x
code = 1.0d0 / (t_0 * t_0)
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
double t_0 = (c * s_m) * x;
return 1.0 / (t_0 * t_0);
}
s_m = math.fabs(s) [x, c, s_m] = sort([x, c, s_m]) def code(x, c, s_m): t_0 = (c * s_m) * x return 1.0 / (t_0 * t_0)
s_m = abs(s) x, c, s_m = sort([x, c, s_m]) function code(x, c, s_m) t_0 = Float64(Float64(c * s_m) * x) return Float64(1.0 / Float64(t_0 * t_0)) end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp = code(x, c, s_m)
t_0 = (c * s_m) * x;
tmp = 1.0 / (t_0 * t_0);
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot s\_m\right) \cdot x\\
\frac{1}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Initial program 62.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
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%
lift-pow.f64N/A
unpow2N/A
lower-*.f6497.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6497.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6497.1
Applied rewrites97.1%
Taylor expanded in x around 0
Applied rewrites74.7%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (if (<= s_m 5e+21) (/ (ratio-of-squares (/ -1.0 c) x) (* s_m s_m)) (ratio-of-squares (/ 1.0 (* s_m x)) c)))
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
\mathbf{if}\;s\_m \leq 5 \cdot 10^{+21}:\\
\;\;\;\;\frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), x\right)}{s\_m \cdot s\_m}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s\_m \cdot x}\right), c\right)\\
\end{array}
\end{array}
if s < 5e21Initial program 60.9%
Taylor expanded in x around 0
associate-/r*N/A
metadata-evalN/A
unpow2N/A
times-fracN/A
pow-prod-downN/A
unpow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lower-*.f6451.6
Applied rewrites51.6%
lift-/.f64N/A
lift-*.f64N/A
lift-ratio-of-squares.f64N/A
frac-timesN/A
metadata-evalN/A
pow2N/A
pow2N/A
unpow-prod-downN/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
metadata-evalN/A
pow2N/A
frac-timesN/A
sqr-neg-revN/A
pow2N/A
lower-ratio-of-squares.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f64N/A
pow2N/A
lift-*.f6459.8
Applied rewrites59.8%
if 5e21 < s Initial program 70.1%
Taylor expanded in x around 0
associate-/r*N/A
metadata-evalN/A
unpow2N/A
times-fracN/A
pow-prod-downN/A
unpow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lower-*.f6471.3
Applied rewrites71.3%
lift-/.f64N/A
lift-*.f64N/A
lift-ratio-of-squares.f64N/A
frac-timesN/A
metadata-evalN/A
pow2N/A
pow2N/A
unpow-prod-downN/A
associate-/r*N/A
*-commutativeN/A
associate-/r*N/A
metadata-evalN/A
unpow-prod-downN/A
pow2N/A
times-fracN/A
pow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lift-*.f6488.5
Applied rewrites88.5%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (ratio-of-squares (/ 1.0 (* s_m x)) c))
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s\_m \cdot x}\right), c\right)
\end{array}
Initial program 62.5%
Taylor expanded in x around 0
associate-/r*N/A
metadata-evalN/A
unpow2N/A
times-fracN/A
pow-prod-downN/A
unpow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lower-*.f6455.1
Applied rewrites55.1%
lift-/.f64N/A
lift-*.f64N/A
lift-ratio-of-squares.f64N/A
frac-timesN/A
metadata-evalN/A
pow2N/A
pow2N/A
unpow-prod-downN/A
associate-/r*N/A
*-commutativeN/A
associate-/r*N/A
metadata-evalN/A
unpow-prod-downN/A
pow2N/A
times-fracN/A
pow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lift-*.f6463.2
Applied rewrites63.2%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (ratio-of-squares (/ 1.0 c) (* s_m x)))
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s\_m \cdot x\right)\right)
\end{array}
Initial program 62.5%
Taylor expanded in x around 0
associate-/r*N/A
metadata-evalN/A
unpow2N/A
times-fracN/A
pow-prod-downN/A
unpow2N/A
lower-ratio-of-squares.f64N/A
lower-/.f64N/A
lower-*.f6455.1
Applied rewrites55.1%
herbie shell --seed 2025058
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))