mixedcos

Percentage Accurate: 65.8% → 97.2%
Time: 6.4s
Alternatives: 9
Speedup: 2.4×

Specification

?
\[\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} \]
(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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 65.8% accurate, 1.0× speedup?

\[\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} \]
(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}

Alternative 1: 97.2% accurate, 2.4× speedup?

\[\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} \]
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}
Derivation
  1. Initial program 65.4%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
  4. Step-by-step derivation
    1. Applied rewrites73.1%

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
    2. Step-by-step derivation
      1. Applied rewrites89.0%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)\right) \cdot s} \]
      2. Step-by-step derivation
        1. Applied rewrites97.4%

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(s \cdot x\right) \cdot c\right) \cdot \color{blue}{\left(\left(s \cdot x\right) \cdot c\right)}} \]
        2. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \frac{\cos \color{blue}{\left(2 \cdot x\right)}}{\left(\left(s \cdot x\right) \cdot c\right) \cdot \left(\left(s \cdot x\right) \cdot c\right)} \]
          2. count-2-revN/A

            \[\leadsto \frac{\cos \color{blue}{\left(x + x\right)}}{\left(\left(s \cdot x\right) \cdot c\right) \cdot \left(\left(s \cdot x\right) \cdot c\right)} \]
          3. lower-+.f6497.4

            \[\leadsto \frac{\cos \color{blue}{\left(x + x\right)}}{\left(\left(s \cdot x\right) \cdot c\right) \cdot \left(\left(s \cdot x\right) \cdot c\right)} \]
        3. Applied rewrites97.4%

          \[\leadsto \frac{\cos \color{blue}{\left(x + x\right)}}{\left(\left(s \cdot x\right) \cdot c\right) \cdot \left(\left(s \cdot x\right) \cdot c\right)} \]
        4. Add Preprocessing

        Alternative 2: 81.7% accurate, 0.9× speedup?

        \[\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} \]
        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}
        
        Derivation
        1. Split input into 2 regimes
        2. 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-109

          1. Initial program 75.1%

            \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
          2. Add Preprocessing
          3. Taylor expanded in x around 0

            \[\leadsto \color{blue}{\frac{-2 \cdot \frac{{x}^{2}}{{c}^{2} \cdot {s}^{2}} + \frac{1}{{c}^{2} \cdot {s}^{2}}}{{x}^{2}}} \]
          4. Step-by-step derivation
            1. Applied rewrites57.4%

              \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
            2. Taylor expanded in x around inf

              \[\leadsto \frac{-2}{\color{blue}{{c}^{2} \cdot {s}^{2}}} \]
            3. Step-by-step derivation
              1. Applied rewrites57.7%

                \[\leadsto \frac{\frac{-2}{c}}{\color{blue}{\left(s \cdot s\right) \cdot c}} \]
              2. Step-by-step derivation
                1. Applied rewrites57.7%

                  \[\leadsto \frac{-2}{\left(\left(s \cdot s\right) \cdot c\right) \cdot \color{blue}{c}} \]
                2. Step-by-step derivation
                  1. Applied rewrites57.7%

                    \[\leadsto \frac{-2}{\left(s \cdot c\right) \cdot \left(s \cdot \color{blue}{c}\right)} \]

                  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)))

                  1. Initial program 64.3%

                    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
                  2. Add Preprocessing
                  3. Taylor expanded in x around 0

                    \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
                  4. Step-by-step derivation
                    1. Applied rewrites72.0%

                      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
                    2. Step-by-step derivation
                      1. Applied rewrites88.2%

                        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)\right) \cdot s} \]
                      2. Step-by-step derivation
                        1. Applied rewrites97.1%

                          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(s \cdot x\right) \cdot c\right) \cdot \color{blue}{\left(\left(s \cdot x\right) \cdot c\right)}} \]
                        2. Taylor expanded in x around 0

                          \[\leadsto \frac{\color{blue}{1}}{\left(\left(s \cdot x\right) \cdot c\right) \cdot \left(\left(s \cdot x\right) \cdot c\right)} \]
                        3. Step-by-step derivation
                          1. Applied rewrites83.5%

                            \[\leadsto \frac{\color{blue}{1}}{\left(\left(s \cdot x\right) \cdot c\right) \cdot \left(\left(s \cdot x\right) \cdot c\right)} \]
                        4. Recombined 2 regimes into one program.
                        5. Add Preprocessing

                        Alternative 3: 78.4% accurate, 0.9× speedup?

                        \[\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} \]
                        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}
                        
                        Derivation
                        1. Split input into 2 regimes
                        2. 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-109

                          1. Initial program 75.1%

                            \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
                          2. Add Preprocessing
                          3. Taylor expanded in x around 0

                            \[\leadsto \color{blue}{\frac{-2 \cdot \frac{{x}^{2}}{{c}^{2} \cdot {s}^{2}} + \frac{1}{{c}^{2} \cdot {s}^{2}}}{{x}^{2}}} \]
                          4. Step-by-step derivation
                            1. Applied rewrites57.4%

                              \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
                            2. Taylor expanded in x around inf

                              \[\leadsto \frac{-2}{\color{blue}{{c}^{2} \cdot {s}^{2}}} \]
                            3. Step-by-step derivation
                              1. Applied rewrites57.7%

                                \[\leadsto \frac{\frac{-2}{c}}{\color{blue}{\left(s \cdot s\right) \cdot c}} \]
                              2. Step-by-step derivation
                                1. Applied rewrites57.7%

                                  \[\leadsto \frac{-2}{\left(\left(s \cdot s\right) \cdot c\right) \cdot \color{blue}{c}} \]
                                2. Step-by-step derivation
                                  1. Applied rewrites57.7%

                                    \[\leadsto \frac{-2}{\left(s \cdot c\right) \cdot \left(s \cdot \color{blue}{c}\right)} \]

                                  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)))

                                  1. Initial program 64.3%

                                    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
                                  2. Add Preprocessing
                                  3. Taylor expanded in x around 0

                                    \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
                                  4. Step-by-step derivation
                                    1. Applied rewrites72.0%

                                      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
                                    2. Step-by-step derivation
                                      1. Applied rewrites88.2%

                                        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)\right) \cdot s} \]
                                      2. Taylor expanded in x around 0

                                        \[\leadsto \frac{\color{blue}{1}}{\left(c \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)\right) \cdot s} \]
                                      3. Step-by-step derivation
                                        1. Applied rewrites79.0%

                                          \[\leadsto \frac{\color{blue}{1}}{\left(c \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)\right) \cdot s} \]
                                      4. Recombined 2 regimes into one program.
                                      5. Add Preprocessing

                                      Alternative 4: 67.6% accurate, 0.9× speedup?

                                      \[\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} \]
                                      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}
                                      
                                      Derivation
                                      1. Split input into 2 regimes
                                      2. 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-109

                                        1. Initial program 75.1%

                                          \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
                                        2. Add Preprocessing
                                        3. Taylor expanded in x around 0

                                          \[\leadsto \color{blue}{\frac{-2 \cdot \frac{{x}^{2}}{{c}^{2} \cdot {s}^{2}} + \frac{1}{{c}^{2} \cdot {s}^{2}}}{{x}^{2}}} \]
                                        4. Step-by-step derivation
                                          1. Applied rewrites57.4%

                                            \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
                                          2. Taylor expanded in x around inf

                                            \[\leadsto \frac{-2}{\color{blue}{{c}^{2} \cdot {s}^{2}}} \]
                                          3. Step-by-step derivation
                                            1. Applied rewrites57.7%

                                              \[\leadsto \frac{\frac{-2}{c}}{\color{blue}{\left(s \cdot s\right) \cdot c}} \]
                                            2. Step-by-step derivation
                                              1. Applied rewrites57.7%

                                                \[\leadsto \frac{-2}{\left(\left(s \cdot s\right) \cdot c\right) \cdot \color{blue}{c}} \]
                                              2. Step-by-step derivation
                                                1. Applied rewrites57.7%

                                                  \[\leadsto \frac{-2}{\left(s \cdot c\right) \cdot \left(s \cdot \color{blue}{c}\right)} \]

                                                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)))

                                                1. Initial program 64.3%

                                                  \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
                                                2. Add Preprocessing
                                                3. Taylor expanded in x around 0

                                                  \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
                                                4. Step-by-step derivation
                                                  1. Applied rewrites72.0%

                                                    \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
                                                  2. Taylor expanded in x around 0

                                                    \[\leadsto \frac{\color{blue}{1}}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s} \]
                                                  3. Step-by-step derivation
                                                    1. Applied rewrites66.1%

                                                      \[\leadsto \frac{\color{blue}{1}}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s} \]
                                                  4. Recombined 2 regimes into one program.
                                                  5. Add Preprocessing

                                                  Alternative 5: 63.4% accurate, 0.9× speedup?

                                                  \[\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} \]
                                                  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}
                                                  
                                                  Derivation
                                                  1. Split input into 2 regimes
                                                  2. 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-109

                                                    1. Initial program 75.1%

                                                      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
                                                    2. Add Preprocessing
                                                    3. Taylor expanded in x around 0

                                                      \[\leadsto \color{blue}{\frac{-2 \cdot \frac{{x}^{2}}{{c}^{2} \cdot {s}^{2}} + \frac{1}{{c}^{2} \cdot {s}^{2}}}{{x}^{2}}} \]
                                                    4. Step-by-step derivation
                                                      1. Applied rewrites57.4%

                                                        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
                                                      2. Taylor expanded in x around inf

                                                        \[\leadsto \frac{-2}{\color{blue}{{c}^{2} \cdot {s}^{2}}} \]
                                                      3. Step-by-step derivation
                                                        1. Applied rewrites57.7%

                                                          \[\leadsto \frac{\frac{-2}{c}}{\color{blue}{\left(s \cdot s\right) \cdot c}} \]
                                                        2. Step-by-step derivation
                                                          1. Applied rewrites57.7%

                                                            \[\leadsto \frac{-2}{\left(\left(s \cdot s\right) \cdot c\right) \cdot \color{blue}{c}} \]
                                                          2. Step-by-step derivation
                                                            1. Applied rewrites57.7%

                                                              \[\leadsto \frac{-2}{\left(s \cdot c\right) \cdot \left(s \cdot \color{blue}{c}\right)} \]

                                                            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)))

                                                            1. Initial program 64.3%

                                                              \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
                                                            2. Add Preprocessing
                                                            3. Taylor expanded in x around 0

                                                              \[\leadsto \color{blue}{\frac{-2 \cdot \frac{{x}^{2}}{{c}^{2} \cdot {s}^{2}} + \frac{1}{{c}^{2} \cdot {s}^{2}}}{{x}^{2}}} \]
                                                            4. Step-by-step derivation
                                                              1. Applied rewrites47.9%

                                                                \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
                                                              2. Step-by-step derivation
                                                                1. Applied rewrites44.5%

                                                                  \[\leadsto \frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{\left(\left(\left(x \cdot x\right) \cdot \left(c \cdot c\right)\right) \cdot s\right) \cdot s} \]
                                                                2. Taylor expanded in x around 0

                                                                  \[\leadsto \frac{1}{\color{blue}{\left(\left(\left(x \cdot x\right) \cdot \left(c \cdot c\right)\right) \cdot s\right)} \cdot s} \]
                                                                3. Step-by-step derivation
                                                                  1. Applied rewrites61.0%

                                                                    \[\leadsto \frac{1}{\color{blue}{\left(\left(\left(x \cdot x\right) \cdot \left(c \cdot c\right)\right) \cdot s\right)} \cdot s} \]
                                                                4. Recombined 2 regimes into one program.
                                                                5. Add Preprocessing

                                                                Alternative 6: 74.2% accurate, 2.3× speedup?

                                                                \[\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} \]
                                                                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}
                                                                
                                                                Derivation
                                                                1. Split input into 2 regimes
                                                                2. if x < 1.10000000000000004e-4

                                                                  1. Initial program 64.9%

                                                                    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
                                                                  2. Add Preprocessing
                                                                  3. Taylor expanded in x around 0

                                                                    \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
                                                                  4. Step-by-step derivation
                                                                    1. Applied rewrites73.0%

                                                                      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
                                                                    2. Step-by-step derivation
                                                                      1. Applied rewrites89.5%

                                                                        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)\right) \cdot s} \]
                                                                      2. Step-by-step derivation
                                                                        1. Applied rewrites97.5%

                                                                          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(s \cdot x\right) \cdot c\right) \cdot \color{blue}{\left(\left(s \cdot x\right) \cdot c\right)}} \]
                                                                        2. Taylor expanded in x around 0

                                                                          \[\leadsto \frac{\color{blue}{1 + {x}^{2} \cdot \left(\frac{2}{3} \cdot {x}^{2} - 2\right)}}{\left(\left(s \cdot x\right) \cdot c\right) \cdot \left(\left(s \cdot x\right) \cdot c\right)} \]
                                                                        3. Step-by-step derivation
                                                                          1. Applied rewrites71.6%

                                                                            \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, -2\right), x \cdot x, 1\right)}}{\left(\left(s \cdot x\right) \cdot c\right) \cdot \left(\left(s \cdot x\right) \cdot c\right)} \]

                                                                          if 1.10000000000000004e-4 < x

                                                                          1. Initial program 66.9%

                                                                            \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
                                                                          2. Add Preprocessing
                                                                          3. Taylor expanded in x around 0

                                                                            \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
                                                                          4. Step-by-step derivation
                                                                            1. Applied rewrites73.3%

                                                                              \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
                                                                            2. Step-by-step derivation
                                                                              1. Applied rewrites87.6%

                                                                                \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)\right) \cdot s} \]
                                                                              2. Step-by-step derivation
                                                                                1. lift-*.f64N/A

                                                                                  \[\leadsto \frac{\cos \color{blue}{\left(2 \cdot x\right)}}{\left(c \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)\right) \cdot s} \]
                                                                                2. count-2-revN/A

                                                                                  \[\leadsto \frac{\cos \color{blue}{\left(x + x\right)}}{\left(c \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)\right) \cdot s} \]
                                                                                3. lower-+.f6487.6

                                                                                  \[\leadsto \frac{\cos \color{blue}{\left(x + x\right)}}{\left(c \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)\right) \cdot s} \]
                                                                              3. Applied rewrites87.6%

                                                                                \[\leadsto \frac{\cos \color{blue}{\left(x + x\right)}}{\left(c \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)\right) \cdot s} \]
                                                                            3. Recombined 2 regimes into one program.
                                                                            4. Add Preprocessing

                                                                            Alternative 7: 28.7% accurate, 12.4× speedup?

                                                                            \[\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} \]
                                                                            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}
                                                                            
                                                                            Derivation
                                                                            1. Initial program 65.4%

                                                                              \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
                                                                            2. Add Preprocessing
                                                                            3. Taylor expanded in x around 0

                                                                              \[\leadsto \color{blue}{\frac{-2 \cdot \frac{{x}^{2}}{{c}^{2} \cdot {s}^{2}} + \frac{1}{{c}^{2} \cdot {s}^{2}}}{{x}^{2}}} \]
                                                                            4. Step-by-step derivation
                                                                              1. Applied rewrites48.9%

                                                                                \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
                                                                              2. Taylor expanded in x around inf

                                                                                \[\leadsto \frac{-2}{\color{blue}{{c}^{2} \cdot {s}^{2}}} \]
                                                                              3. Step-by-step derivation
                                                                                1. Applied rewrites28.1%

                                                                                  \[\leadsto \frac{\frac{-2}{c}}{\color{blue}{\left(s \cdot s\right) \cdot c}} \]
                                                                                2. Step-by-step derivation
                                                                                  1. Applied rewrites28.3%

                                                                                    \[\leadsto \frac{-2}{\left(\left(s \cdot s\right) \cdot c\right) \cdot \color{blue}{c}} \]
                                                                                  2. Add Preprocessing

                                                                                  Alternative 8: 28.4% accurate, 12.4× speedup?

                                                                                  \[\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} \]
                                                                                  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}
                                                                                  
                                                                                  Derivation
                                                                                  1. Initial program 65.4%

                                                                                    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
                                                                                  2. Add Preprocessing
                                                                                  3. Taylor expanded in x around 0

                                                                                    \[\leadsto \color{blue}{\frac{-2 \cdot \frac{{x}^{2}}{{c}^{2} \cdot {s}^{2}} + \frac{1}{{c}^{2} \cdot {s}^{2}}}{{x}^{2}}} \]
                                                                                  4. Step-by-step derivation
                                                                                    1. Applied rewrites48.9%

                                                                                      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
                                                                                    2. Taylor expanded in x around inf

                                                                                      \[\leadsto \frac{-2}{\color{blue}{{c}^{2} \cdot {s}^{2}}} \]
                                                                                    3. Step-by-step derivation
                                                                                      1. Applied rewrites28.1%

                                                                                        \[\leadsto \frac{\frac{-2}{c}}{\color{blue}{\left(s \cdot s\right) \cdot c}} \]
                                                                                      2. Step-by-step derivation
                                                                                        1. Applied rewrites28.3%

                                                                                          \[\leadsto \frac{-2}{\left(\left(s \cdot s\right) \cdot c\right) \cdot \color{blue}{c}} \]
                                                                                        2. Step-by-step derivation
                                                                                          1. Applied rewrites29.0%

                                                                                            \[\leadsto \frac{-2}{\left(s \cdot s\right) \cdot \left(c \cdot \color{blue}{c}\right)} \]
                                                                                          2. Add Preprocessing

                                                                                          Alternative 9: 26.2% accurate, 12.4× speedup?

                                                                                          \[\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} \]
                                                                                          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}
                                                                                          
                                                                                          Derivation
                                                                                          1. Initial program 65.4%

                                                                                            \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
                                                                                          2. Add Preprocessing
                                                                                          3. Taylor expanded in x around 0

                                                                                            \[\leadsto \color{blue}{\frac{-2 \cdot \frac{{x}^{2}}{{c}^{2} \cdot {s}^{2}} + \frac{1}{{c}^{2} \cdot {s}^{2}}}{{x}^{2}}} \]
                                                                                          4. Step-by-step derivation
                                                                                            1. Applied rewrites48.9%

                                                                                              \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right) \cdot s}} \]
                                                                                            2. Taylor expanded in x around inf

                                                                                              \[\leadsto \frac{-2}{\color{blue}{{c}^{2} \cdot {s}^{2}}} \]
                                                                                            3. Step-by-step derivation
                                                                                              1. Applied rewrites28.1%

                                                                                                \[\leadsto \frac{\frac{-2}{c}}{\color{blue}{\left(s \cdot s\right) \cdot c}} \]
                                                                                              2. Step-by-step derivation
                                                                                                1. Applied rewrites28.3%

                                                                                                  \[\leadsto \frac{-2}{\left(\left(s \cdot s\right) \cdot c\right) \cdot \color{blue}{c}} \]
                                                                                                2. Step-by-step derivation
                                                                                                  1. Applied rewrites26.2%

                                                                                                    \[\leadsto \frac{-2}{\left(s \cdot c\right) \cdot \left(s \cdot \color{blue}{c}\right)} \]
                                                                                                  2. Add Preprocessing

                                                                                                  Reproduce

                                                                                                  ?
                                                                                                  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))))