
(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}
NOTE: x, c, and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (let* ((t_0 (* (* s x) c))) (/ (cos (+ x x)) (* t_0 t_0))))
assert(x < c && c < s);
double code(double x, double c, double s) {
double t_0 = (s * x) * c;
return cos((x + x)) / (t_0 * t_0);
}
NOTE: x, c, and s 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: t_0
t_0 = (s * x) * c
code = cos((x + x)) / (t_0 * t_0)
end function
assert x < c && c < s;
public static double code(double x, double c, double s) {
double t_0 = (s * x) * c;
return Math.cos((x + x)) / (t_0 * t_0);
}
[x, c, s] = sort([x, c, s]) def code(x, c, s): t_0 = (s * x) * c return math.cos((x + x)) / (t_0 * t_0)
x, c, s = sort([x, c, s]) function code(x, c, s) t_0 = Float64(Float64(s * x) * c) return Float64(cos(Float64(x + x)) / Float64(t_0 * t_0)) end
x, c, s = num2cell(sort([x, c, s])){:}
function tmp = code(x, c, s)
t_0 = (s * x) * c;
tmp = cos((x + x)) / (t_0 * t_0);
end
NOTE: x, c, and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(N[(s * x), $MachinePrecision] * c), $MachinePrecision]}, N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\begin{array}{l}
t_0 := \left(s \cdot x\right) \cdot c\\
\frac{\cos \left(x + x\right)}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Initial program 65.4%
Taylor expanded in x around 0
Applied rewrites73.1%
Applied rewrites89.0%
Applied rewrites97.4%
lift-*.f64N/A
count-2-revN/A
lower-+.f6497.4
Applied rewrites97.4%
NOTE: x, c, and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
:precision binary64
(let* ((t_0 (* (* s x) c)))
(if (<= (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))) -5e-109)
(/ -2.0 (* (* s c) (* s c)))
(/ 1.0 (* t_0 t_0)))))assert(x < c && c < s);
double code(double x, double c, double s) {
double t_0 = (s * x) * c;
double tmp;
if ((cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x))) <= -5e-109) {
tmp = -2.0 / ((s * c) * (s * c));
} else {
tmp = 1.0 / (t_0 * t_0);
}
return tmp;
}
NOTE: x, c, and s 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: t_0
real(8) :: tmp
t_0 = (s * x) * c
if ((cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))) <= (-5d-109)) then
tmp = (-2.0d0) / ((s * c) * (s * c))
else
tmp = 1.0d0 / (t_0 * t_0)
end if
code = tmp
end function
assert x < c && c < s;
public static double code(double x, double c, double s) {
double t_0 = (s * x) * c;
double tmp;
if ((Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x))) <= -5e-109) {
tmp = -2.0 / ((s * c) * (s * c));
} else {
tmp = 1.0 / (t_0 * t_0);
}
return tmp;
}
[x, c, s] = sort([x, c, s]) def code(x, c, s): t_0 = (s * x) * c tmp = 0 if (math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))) <= -5e-109: tmp = -2.0 / ((s * c) * (s * c)) else: tmp = 1.0 / (t_0 * t_0) return tmp
x, c, s = sort([x, c, s]) function code(x, c, s) t_0 = Float64(Float64(s * x) * c) tmp = 0.0 if (Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) <= -5e-109) tmp = Float64(-2.0 / Float64(Float64(s * c) * Float64(s * c))); else tmp = Float64(1.0 / Float64(t_0 * t_0)); end return tmp end
x, c, s = num2cell(sort([x, c, s])){:}
function tmp_2 = code(x, c, s)
t_0 = (s * x) * c;
tmp = 0.0;
if ((cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x))) <= -5e-109)
tmp = -2.0 / ((s * c) * (s * c));
else
tmp = 1.0 / (t_0 * t_0);
end
tmp_2 = tmp;
end
NOTE: x, c, and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(N[(s * x), $MachinePrecision] * c), $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, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -5e-109], N[(-2.0 / N[(N[(s * c), $MachinePrecision] * N[(s * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\begin{array}{l}
t_0 := \left(s \cdot x\right) \cdot c\\
\mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \leq -5 \cdot 10^{-109}:\\
\;\;\;\;\frac{-2}{\left(s \cdot c\right) \cdot \left(s \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t\_0 \cdot 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))) < -5.0000000000000002e-109Initial program 75.1%
Taylor expanded in x around 0
Applied rewrites57.4%
Taylor expanded in x around inf
Applied rewrites57.7%
Applied rewrites57.7%
Applied rewrites57.7%
if -5.0000000000000002e-109 < (/.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 64.3%
Taylor expanded in x around 0
Applied rewrites72.0%
Applied rewrites88.2%
Applied rewrites97.1%
Taylor expanded in x around 0
Applied rewrites83.5%
NOTE: x, c, and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (if (<= (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))) -5e-109) (/ -2.0 (* (* s c) (* s c))) (/ 1.0 (* (* c (* (* c x) (* s x))) s))))
assert(x < c && c < s);
double code(double x, double c, double s) {
double tmp;
if ((cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x))) <= -5e-109) {
tmp = -2.0 / ((s * c) * (s * c));
} else {
tmp = 1.0 / ((c * ((c * x) * (s * x))) * s);
}
return tmp;
}
NOTE: x, c, and s 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: tmp
if ((cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))) <= (-5d-109)) then
tmp = (-2.0d0) / ((s * c) * (s * c))
else
tmp = 1.0d0 / ((c * ((c * x) * (s * x))) * s)
end if
code = tmp
end function
assert x < c && c < s;
public static double code(double x, double c, double s) {
double tmp;
if ((Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x))) <= -5e-109) {
tmp = -2.0 / ((s * c) * (s * c));
} else {
tmp = 1.0 / ((c * ((c * x) * (s * x))) * s);
}
return tmp;
}
[x, c, s] = sort([x, c, s]) def code(x, c, s): tmp = 0 if (math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))) <= -5e-109: tmp = -2.0 / ((s * c) * (s * c)) else: tmp = 1.0 / ((c * ((c * x) * (s * x))) * s) return tmp
x, c, s = sort([x, c, s]) function code(x, c, s) tmp = 0.0 if (Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) <= -5e-109) tmp = Float64(-2.0 / Float64(Float64(s * c) * Float64(s * c))); else tmp = Float64(1.0 / Float64(Float64(c * Float64(Float64(c * x) * Float64(s * x))) * s)); end return tmp end
x, c, s = num2cell(sort([x, c, s])){:}
function tmp_2 = code(x, c, s)
tmp = 0.0;
if ((cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x))) <= -5e-109)
tmp = -2.0 / ((s * c) * (s * c));
else
tmp = 1.0 / ((c * ((c * x) * (s * x))) * s);
end
tmp_2 = tmp;
end
NOTE: x, c, and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := If[LessEqual[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], -5e-109], N[(-2.0 / N[(N[(s * c), $MachinePrecision] * N[(s * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(c * N[(N[(c * x), $MachinePrecision] * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * s), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \leq -5 \cdot 10^{-109}:\\
\;\;\;\;\frac{-2}{\left(s \cdot c\right) \cdot \left(s \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(c \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)\right) \cdot s}\\
\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))) < -5.0000000000000002e-109Initial program 75.1%
Taylor expanded in x around 0
Applied rewrites57.4%
Taylor expanded in x around inf
Applied rewrites57.7%
Applied rewrites57.7%
Applied rewrites57.7%
if -5.0000000000000002e-109 < (/.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 64.3%
Taylor expanded in x around 0
Applied rewrites72.0%
Applied rewrites88.2%
Taylor expanded in x around 0
Applied rewrites79.0%
NOTE: x, c, and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (if (<= (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))) -5e-109) (/ -2.0 (* (* s c) (* s c))) (/ 1.0 (* (* (* (* (* c c) x) x) s) s))))
assert(x < c && c < s);
double code(double x, double c, double s) {
double tmp;
if ((cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x))) <= -5e-109) {
tmp = -2.0 / ((s * c) * (s * c));
} else {
tmp = 1.0 / (((((c * c) * x) * x) * s) * s);
}
return tmp;
}
NOTE: x, c, and s 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: tmp
if ((cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))) <= (-5d-109)) then
tmp = (-2.0d0) / ((s * c) * (s * c))
else
tmp = 1.0d0 / (((((c * c) * x) * x) * s) * s)
end if
code = tmp
end function
assert x < c && c < s;
public static double code(double x, double c, double s) {
double tmp;
if ((Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x))) <= -5e-109) {
tmp = -2.0 / ((s * c) * (s * c));
} else {
tmp = 1.0 / (((((c * c) * x) * x) * s) * s);
}
return tmp;
}
[x, c, s] = sort([x, c, s]) def code(x, c, s): tmp = 0 if (math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))) <= -5e-109: tmp = -2.0 / ((s * c) * (s * c)) else: tmp = 1.0 / (((((c * c) * x) * x) * s) * s) return tmp
x, c, s = sort([x, c, s]) function code(x, c, s) tmp = 0.0 if (Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) <= -5e-109) tmp = Float64(-2.0 / Float64(Float64(s * c) * Float64(s * c))); else tmp = Float64(1.0 / Float64(Float64(Float64(Float64(Float64(c * c) * x) * x) * s) * s)); end return tmp end
x, c, s = num2cell(sort([x, c, s])){:}
function tmp_2 = code(x, c, s)
tmp = 0.0;
if ((cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x))) <= -5e-109)
tmp = -2.0 / ((s * c) * (s * c));
else
tmp = 1.0 / (((((c * c) * x) * x) * s) * s);
end
tmp_2 = tmp;
end
NOTE: x, c, and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := If[LessEqual[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], -5e-109], N[(-2.0 / N[(N[(s * c), $MachinePrecision] * N[(s * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(N[(N[(c * c), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * s), $MachinePrecision] * s), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \leq -5 \cdot 10^{-109}:\\
\;\;\;\;\frac{-2}{\left(s \cdot c\right) \cdot \left(s \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}\\
\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))) < -5.0000000000000002e-109Initial program 75.1%
Taylor expanded in x around 0
Applied rewrites57.4%
Taylor expanded in x around inf
Applied rewrites57.7%
Applied rewrites57.7%
Applied rewrites57.7%
if -5.0000000000000002e-109 < (/.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 64.3%
Taylor expanded in x around 0
Applied rewrites72.0%
Taylor expanded in x around 0
Applied rewrites66.1%
NOTE: x, c, and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (if (<= (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))) -5e-109) (/ -2.0 (* (* s c) (* s c))) (/ 1.0 (* (* (* (* x x) (* c c)) s) s))))
assert(x < c && c < s);
double code(double x, double c, double s) {
double tmp;
if ((cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x))) <= -5e-109) {
tmp = -2.0 / ((s * c) * (s * c));
} else {
tmp = 1.0 / ((((x * x) * (c * c)) * s) * s);
}
return tmp;
}
NOTE: x, c, and s 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: tmp
if ((cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))) <= (-5d-109)) then
tmp = (-2.0d0) / ((s * c) * (s * c))
else
tmp = 1.0d0 / ((((x * x) * (c * c)) * s) * s)
end if
code = tmp
end function
assert x < c && c < s;
public static double code(double x, double c, double s) {
double tmp;
if ((Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x))) <= -5e-109) {
tmp = -2.0 / ((s * c) * (s * c));
} else {
tmp = 1.0 / ((((x * x) * (c * c)) * s) * s);
}
return tmp;
}
[x, c, s] = sort([x, c, s]) def code(x, c, s): tmp = 0 if (math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))) <= -5e-109: tmp = -2.0 / ((s * c) * (s * c)) else: tmp = 1.0 / ((((x * x) * (c * c)) * s) * s) return tmp
x, c, s = sort([x, c, s]) function code(x, c, s) tmp = 0.0 if (Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) <= -5e-109) tmp = Float64(-2.0 / Float64(Float64(s * c) * Float64(s * c))); else tmp = Float64(1.0 / Float64(Float64(Float64(Float64(x * x) * Float64(c * c)) * s) * s)); end return tmp end
x, c, s = num2cell(sort([x, c, s])){:}
function tmp_2 = code(x, c, s)
tmp = 0.0;
if ((cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x))) <= -5e-109)
tmp = -2.0 / ((s * c) * (s * c));
else
tmp = 1.0 / ((((x * x) * (c * c)) * s) * s);
end
tmp_2 = tmp;
end
NOTE: x, c, and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := If[LessEqual[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], -5e-109], N[(-2.0 / N[(N[(s * c), $MachinePrecision] * N[(s * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(N[(x * x), $MachinePrecision] * N[(c * c), $MachinePrecision]), $MachinePrecision] * s), $MachinePrecision] * s), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \leq -5 \cdot 10^{-109}:\\
\;\;\;\;\frac{-2}{\left(s \cdot c\right) \cdot \left(s \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(\left(x \cdot x\right) \cdot \left(c \cdot c\right)\right) \cdot s\right) \cdot s}\\
\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))) < -5.0000000000000002e-109Initial program 75.1%
Taylor expanded in x around 0
Applied rewrites57.4%
Taylor expanded in x around inf
Applied rewrites57.7%
Applied rewrites57.7%
Applied rewrites57.7%
if -5.0000000000000002e-109 < (/.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 64.3%
Taylor expanded in x around 0
Applied rewrites47.9%
Applied rewrites44.5%
Taylor expanded in x around 0
Applied rewrites61.0%
NOTE: x, c, and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
:precision binary64
(let* ((t_0 (* (* s x) c)))
(if (<= x 0.00011)
(/ (fma (fma 0.6666666666666666 (* x x) -2.0) (* x x) 1.0) (* t_0 t_0))
(/ (cos (+ x x)) (* (* c (* (* c x) (* s x))) s)))))assert(x < c && c < s);
double code(double x, double c, double s) {
double t_0 = (s * x) * c;
double tmp;
if (x <= 0.00011) {
tmp = fma(fma(0.6666666666666666, (x * x), -2.0), (x * x), 1.0) / (t_0 * t_0);
} else {
tmp = cos((x + x)) / ((c * ((c * x) * (s * x))) * s);
}
return tmp;
}
x, c, s = sort([x, c, s]) function code(x, c, s) t_0 = Float64(Float64(s * x) * c) tmp = 0.0 if (x <= 0.00011) tmp = Float64(fma(fma(0.6666666666666666, Float64(x * x), -2.0), Float64(x * x), 1.0) / Float64(t_0 * t_0)); else tmp = Float64(cos(Float64(x + x)) / Float64(Float64(c * Float64(Float64(c * x) * Float64(s * x))) * s)); end return tmp end
NOTE: x, c, and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(N[(s * x), $MachinePrecision] * c), $MachinePrecision]}, If[LessEqual[x, 0.00011], N[(N[(N[(0.6666666666666666 * N[(x * x), $MachinePrecision] + -2.0), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / N[(N[(c * N[(N[(c * x), $MachinePrecision] * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * s), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\begin{array}{l}
t_0 := \left(s \cdot x\right) \cdot c\\
\mathbf{if}\;x \leq 0.00011:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, -2\right), x \cdot x, 1\right)}{t\_0 \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(x + x\right)}{\left(c \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)\right) \cdot s}\\
\end{array}
\end{array}
if x < 1.10000000000000004e-4Initial program 64.9%
Taylor expanded in x around 0
Applied rewrites73.0%
Applied rewrites89.5%
Applied rewrites97.5%
Taylor expanded in x around 0
Applied rewrites71.6%
if 1.10000000000000004e-4 < x Initial program 66.9%
Taylor expanded in x around 0
Applied rewrites73.3%
Applied rewrites87.6%
lift-*.f64N/A
count-2-revN/A
lower-+.f6487.6
Applied rewrites87.6%
NOTE: x, c, and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (/ -2.0 (* (* (* s s) c) c)))
assert(x < c && c < s);
double code(double x, double c, double s) {
return -2.0 / (((s * s) * c) * c);
}
NOTE: x, c, and s 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = (-2.0d0) / (((s * s) * c) * c)
end function
assert x < c && c < s;
public static double code(double x, double c, double s) {
return -2.0 / (((s * s) * c) * c);
}
[x, c, s] = sort([x, c, s]) def code(x, c, s): return -2.0 / (((s * s) * c) * c)
x, c, s = sort([x, c, s]) function code(x, c, s) return Float64(-2.0 / Float64(Float64(Float64(s * s) * c) * c)) end
x, c, s = num2cell(sort([x, c, s])){:}
function tmp = code(x, c, s)
tmp = -2.0 / (((s * s) * c) * c);
end
NOTE: x, c, and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(-2.0 / N[(N[(N[(s * s), $MachinePrecision] * c), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\frac{-2}{\left(\left(s \cdot s\right) \cdot c\right) \cdot c}
\end{array}
Initial program 65.4%
Taylor expanded in x around 0
Applied rewrites48.9%
Taylor expanded in x around inf
Applied rewrites28.1%
Applied rewrites28.3%
NOTE: x, c, and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (/ -2.0 (* (* s s) (* c c))))
assert(x < c && c < s);
double code(double x, double c, double s) {
return -2.0 / ((s * s) * (c * c));
}
NOTE: x, c, and s 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = (-2.0d0) / ((s * s) * (c * c))
end function
assert x < c && c < s;
public static double code(double x, double c, double s) {
return -2.0 / ((s * s) * (c * c));
}
[x, c, s] = sort([x, c, s]) def code(x, c, s): return -2.0 / ((s * s) * (c * c))
x, c, s = sort([x, c, s]) function code(x, c, s) return Float64(-2.0 / Float64(Float64(s * s) * Float64(c * c))) end
x, c, s = num2cell(sort([x, c, s])){:}
function tmp = code(x, c, s)
tmp = -2.0 / ((s * s) * (c * c));
end
NOTE: x, c, and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(-2.0 / N[(N[(s * s), $MachinePrecision] * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\frac{-2}{\left(s \cdot s\right) \cdot \left(c \cdot c\right)}
\end{array}
Initial program 65.4%
Taylor expanded in x around 0
Applied rewrites48.9%
Taylor expanded in x around inf
Applied rewrites28.1%
Applied rewrites28.3%
Applied rewrites29.0%
NOTE: x, c, and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (/ -2.0 (* (* s c) (* s c))))
assert(x < c && c < s);
double code(double x, double c, double s) {
return -2.0 / ((s * c) * (s * c));
}
NOTE: x, c, and s 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = (-2.0d0) / ((s * c) * (s * c))
end function
assert x < c && c < s;
public static double code(double x, double c, double s) {
return -2.0 / ((s * c) * (s * c));
}
[x, c, s] = sort([x, c, s]) def code(x, c, s): return -2.0 / ((s * c) * (s * c))
x, c, s = sort([x, c, s]) function code(x, c, s) return Float64(-2.0 / Float64(Float64(s * c) * Float64(s * c))) end
x, c, s = num2cell(sort([x, c, s])){:}
function tmp = code(x, c, s)
tmp = -2.0 / ((s * c) * (s * c));
end
NOTE: x, c, and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(-2.0 / N[(N[(s * c), $MachinePrecision] * N[(s * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\frac{-2}{\left(s \cdot c\right) \cdot \left(s \cdot c\right)}
\end{array}
Initial program 65.4%
Taylor expanded in x around 0
Applied rewrites48.9%
Taylor expanded in x around inf
Applied rewrites28.1%
Applied rewrites28.3%
Applied rewrites26.2%
herbie shell --seed 2025026
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))