mixedcos

Percentage Accurate: 66.9% → 98.9%
Time: 19.2s
Alternatives: 13
Speedup: 17.1×

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 13 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: 66.9% 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: 98.9% accurate, 0.7× speedup?

\[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \begin{array}{l} t_0 := \left(s\_m \cdot x\right) \cdot c\\ t_1 := \cos \left(2 \cdot x\right)\\ t_2 := \left(c \cdot s\_m\right) \cdot x\\ \mathbf{if}\;\frac{t\_1}{{c}^{2} \cdot \left(\left(x \cdot {s\_m}^{2}\right) \cdot x\right)} \leq \infty:\\ \;\;\;\;\frac{t\_1}{t\_0 \cdot t\_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x + x\right)}{t\_2 \cdot t\_2}\\ \end{array} \end{array} \]
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
 :precision binary64
 (let* ((t_0 (* (* s_m x) c)) (t_1 (cos (* 2.0 x))) (t_2 (* (* c s_m) x)))
   (if (<= (/ t_1 (* (pow c 2.0) (* (* x (pow s_m 2.0)) x))) INFINITY)
     (/ t_1 (* t_0 t_0))
     (/ (cos (+ x x)) (* t_2 t_2)))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
	double t_0 = (s_m * x) * c;
	double t_1 = cos((2.0 * x));
	double t_2 = (c * s_m) * x;
	double tmp;
	if ((t_1 / (pow(c, 2.0) * ((x * pow(s_m, 2.0)) * x))) <= ((double) INFINITY)) {
		tmp = t_1 / (t_0 * t_0);
	} else {
		tmp = cos((x + x)) / (t_2 * t_2);
	}
	return tmp;
}
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
	double t_0 = (s_m * x) * c;
	double t_1 = Math.cos((2.0 * x));
	double t_2 = (c * s_m) * x;
	double tmp;
	if ((t_1 / (Math.pow(c, 2.0) * ((x * Math.pow(s_m, 2.0)) * x))) <= Double.POSITIVE_INFINITY) {
		tmp = t_1 / (t_0 * t_0);
	} else {
		tmp = Math.cos((x + x)) / (t_2 * t_2);
	}
	return tmp;
}
s_m = math.fabs(s)
[x, c, s_m] = sort([x, c, s_m])
def code(x, c, s_m):
	t_0 = (s_m * x) * c
	t_1 = math.cos((2.0 * x))
	t_2 = (c * s_m) * x
	tmp = 0
	if (t_1 / (math.pow(c, 2.0) * ((x * math.pow(s_m, 2.0)) * x))) <= math.inf:
		tmp = t_1 / (t_0 * t_0)
	else:
		tmp = math.cos((x + x)) / (t_2 * t_2)
	return tmp
s_m = abs(s)
x, c, s_m = sort([x, c, s_m])
function code(x, c, s_m)
	t_0 = Float64(Float64(s_m * x) * c)
	t_1 = cos(Float64(2.0 * x))
	t_2 = Float64(Float64(c * s_m) * x)
	tmp = 0.0
	if (Float64(t_1 / Float64((c ^ 2.0) * Float64(Float64(x * (s_m ^ 2.0)) * x))) <= Inf)
		tmp = Float64(t_1 / Float64(t_0 * t_0));
	else
		tmp = Float64(cos(Float64(x + x)) / Float64(t_2 * t_2));
	end
	return tmp
end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp_2 = code(x, c, s_m)
	t_0 = (s_m * x) * c;
	t_1 = cos((2.0 * x));
	t_2 = (c * s_m) * x;
	tmp = 0.0;
	if ((t_1 / ((c ^ 2.0) * ((x * (s_m ^ 2.0)) * x))) <= Inf)
		tmp = t_1 / (t_0 * t_0);
	else
		tmp = cos((x + x)) / (t_2 * t_2);
	end
	tmp_2 = tmp;
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(s$95$m * x), $MachinePrecision] * c), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[N[(t$95$1 / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s$95$m, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(t$95$1 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(s\_m \cdot x\right) \cdot c\\
t_1 := \cos \left(2 \cdot x\right)\\
t_2 := \left(c \cdot s\_m\right) \cdot x\\
\mathbf{if}\;\frac{t\_1}{{c}^{2} \cdot \left(\left(x \cdot {s\_m}^{2}\right) \cdot x\right)} \leq \infty:\\
\;\;\;\;\frac{t\_1}{t\_0 \cdot t\_0}\\

\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(x + x\right)}{t\_2 \cdot t\_2}\\


\end{array}
\end{array}
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))) < +inf.0

    1. Initial program 84.7%

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
      2. lift-pow.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2}} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)} \]
      5. lift-pow.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot \color{blue}{{s}^{2}}\right) \cdot x\right)} \]
      6. *-commutativeN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)} \]
      7. associate-*r*N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}} \]
      8. unpow2N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left({s}^{2} \cdot \color{blue}{{x}^{2}}\right)} \]
      9. associate-*r*N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}} \]
      10. pow-prod-downN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(c \cdot s\right)}^{2}} \cdot {x}^{2}} \]
      11. pow-prod-downN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
      12. lower-pow.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
      13. lower-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}}^{2}} \]
      14. *-commutativeN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
      15. lower-*.f6497.3

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\color{blue}{\left(\left(s \cdot c\right) \cdot x\right)}}^{2}} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
      5. unpow-prod-downN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(s \cdot c\right)}^{2} \cdot {x}^{2}}} \]
      6. lift-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\color{blue}{\left(s \cdot c\right)}}^{2} \cdot {x}^{2}} \]
      7. unpow-prod-downN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({s}^{2} \cdot {c}^{2}\right)} \cdot {x}^{2}} \]
      8. *-commutativeN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right)} \cdot {x}^{2}} \]
      9. associate-*r*N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
      10. *-commutativeN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({s}^{2} \cdot {x}^{2}\right) \cdot {c}^{2}}} \]
      11. unpow-prod-downN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(s \cdot x\right)}^{2}} \cdot {c}^{2}} \]
      12. pow2N/A

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(\mathsf{neg}\left(s \cdot x\right)\right) \cdot \left(\mathsf{neg}\left(s \cdot x\right)\right)\right)} \cdot {c}^{2}} \]
      14. pow2N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(\mathsf{neg}\left(s \cdot x\right)\right) \cdot \left(\mathsf{neg}\left(s \cdot x\right)\right)\right) \cdot \color{blue}{\left(c \cdot c\right)}} \]
      15. unswap-sqrN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(\mathsf{neg}\left(s \cdot x\right)\right) \cdot c\right) \cdot \left(\left(\mathsf{neg}\left(s \cdot x\right)\right) \cdot c\right)}} \]
      16. lower-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(\mathsf{neg}\left(s \cdot x\right)\right) \cdot c\right) \cdot \left(\left(\mathsf{neg}\left(s \cdot x\right)\right) \cdot c\right)}} \]
      17. lower-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(\mathsf{neg}\left(s \cdot x\right)\right) \cdot c\right)} \cdot \left(\left(\mathsf{neg}\left(s \cdot x\right)\right) \cdot c\right)} \]
      18. distribute-lft-neg-inN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(\left(\mathsf{neg}\left(s\right)\right) \cdot x\right)} \cdot c\right) \cdot \left(\left(\mathsf{neg}\left(s \cdot x\right)\right) \cdot c\right)} \]
      19. lower-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(\left(\mathsf{neg}\left(s\right)\right) \cdot x\right)} \cdot c\right) \cdot \left(\left(\mathsf{neg}\left(s \cdot x\right)\right) \cdot c\right)} \]
      20. lower-neg.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(\color{blue}{\left(-s\right)} \cdot x\right) \cdot c\right) \cdot \left(\left(\mathsf{neg}\left(s \cdot x\right)\right) \cdot c\right)} \]
      21. lower-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(\left(-s\right) \cdot x\right) \cdot c\right) \cdot \color{blue}{\left(\left(\mathsf{neg}\left(s \cdot x\right)\right) \cdot c\right)}} \]
      22. distribute-lft-neg-inN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(\left(-s\right) \cdot x\right) \cdot c\right) \cdot \left(\color{blue}{\left(\left(\mathsf{neg}\left(s\right)\right) \cdot x\right)} \cdot c\right)} \]
      23. lower-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(\left(-s\right) \cdot x\right) \cdot c\right) \cdot \left(\color{blue}{\left(\left(\mathsf{neg}\left(s\right)\right) \cdot x\right)} \cdot c\right)} \]
      24. lower-neg.f6499.3

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

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

    if +inf.0 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x)))

    1. Initial program 0.0%

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
      2. lift-pow.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2}} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)} \]
      5. lift-pow.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot \color{blue}{{s}^{2}}\right) \cdot x\right)} \]
      6. *-commutativeN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)} \]
      7. associate-*r*N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}} \]
      8. unpow2N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left({s}^{2} \cdot \color{blue}{{x}^{2}}\right)} \]
      9. associate-*r*N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}} \]
      10. pow-prod-downN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(c \cdot s\right)}^{2}} \cdot {x}^{2}} \]
      11. pow-prod-downN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
      12. lower-pow.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
      13. lower-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}}^{2}} \]
      14. *-commutativeN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
      15. lower-*.f6496.5

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
    4. Applied rewrites96.5%

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot s\right)} \cdot x\right) \cdot \left(\left(s \cdot c\right) \cdot x\right)} \]
      6. lower-*.f6496.4

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\color{blue}{\left(c \cdot s\right)} \cdot x\right)} \]
      9. lower-*.f6496.4

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\color{blue}{\left(c \cdot s\right)} \cdot x\right)} \]
    6. Applied rewrites96.4%

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

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

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

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

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

    \[\leadsto \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 \infty:\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{\left(\left(s \cdot x\right) \cdot c\right) \cdot \left(\left(s \cdot x\right) \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x + x\right)}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 82.6% accurate, 0.8× speedup?

\[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \begin{array}{l} t_0 := \left(c \cdot s\_m\right) \cdot x\\ t_1 := \frac{\frac{-1}{c}}{s\_m \cdot x}\\ \mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s\_m}^{2}\right) \cdot x\right)} \leq -4 \cdot 10^{-119}:\\ \;\;\;\;\frac{-2 \cdot \left(x \cdot x\right) - -1}{t\_0 \cdot t\_0}\\ \mathbf{else}:\\ \;\;\;\;t\_1 \cdot t\_1\\ \end{array} \end{array} \]
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
 :precision binary64
 (let* ((t_0 (* (* c s_m) x)) (t_1 (/ (/ -1.0 c) (* s_m x))))
   (if (<=
        (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s_m 2.0)) x)))
        -4e-119)
     (/ (- (* -2.0 (* x x)) -1.0) (* t_0 t_0))
     (* t_1 t_1))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
	double t_0 = (c * s_m) * x;
	double t_1 = (-1.0 / c) / (s_m * x);
	double tmp;
	if ((cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s_m, 2.0)) * x))) <= -4e-119) {
		tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0);
	} else {
		tmp = t_1 * t_1;
	}
	return tmp;
}
s_m =     private
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, c, s_m)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s_m
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (c * s_m) * x
    t_1 = ((-1.0d0) / c) / (s_m * x)
    if ((cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s_m ** 2.0d0)) * x))) <= (-4d-119)) then
        tmp = (((-2.0d0) * (x * x)) - (-1.0d0)) / (t_0 * t_0)
    else
        tmp = t_1 * t_1
    end if
    code = tmp
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
	double t_0 = (c * s_m) * x;
	double t_1 = (-1.0 / c) / (s_m * x);
	double tmp;
	if ((Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s_m, 2.0)) * x))) <= -4e-119) {
		tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0);
	} else {
		tmp = t_1 * t_1;
	}
	return tmp;
}
s_m = math.fabs(s)
[x, c, s_m] = sort([x, c, s_m])
def code(x, c, s_m):
	t_0 = (c * s_m) * x
	t_1 = (-1.0 / c) / (s_m * x)
	tmp = 0
	if (math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s_m, 2.0)) * x))) <= -4e-119:
		tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0)
	else:
		tmp = t_1 * t_1
	return tmp
s_m = abs(s)
x, c, s_m = sort([x, c, s_m])
function code(x, c, s_m)
	t_0 = Float64(Float64(c * s_m) * x)
	t_1 = Float64(Float64(-1.0 / c) / Float64(s_m * x))
	tmp = 0.0
	if (Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s_m ^ 2.0)) * x))) <= -4e-119)
		tmp = Float64(Float64(Float64(-2.0 * Float64(x * x)) - -1.0) / Float64(t_0 * t_0));
	else
		tmp = Float64(t_1 * t_1);
	end
	return tmp
end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp_2 = code(x, c, s_m)
	t_0 = (c * s_m) * x;
	t_1 = (-1.0 / c) / (s_m * x);
	tmp = 0.0;
	if ((cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s_m ^ 2.0)) * x))) <= -4e-119)
		tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0);
	else
		tmp = t_1 * t_1;
	end
	tmp_2 = tmp;
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[(N[(-1.0 / c), $MachinePrecision] / N[(s$95$m * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s$95$m, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -4e-119], N[(N[(N[(-2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision] - -1.0), $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(t$95$1 * t$95$1), $MachinePrecision]]]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot s\_m\right) \cdot x\\
t_1 := \frac{\frac{-1}{c}}{s\_m \cdot x}\\
\mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s\_m}^{2}\right) \cdot x\right)} \leq -4 \cdot 10^{-119}:\\
\;\;\;\;\frac{-2 \cdot \left(x \cdot x\right) - -1}{t\_0 \cdot t\_0}\\

\mathbf{else}:\\
\;\;\;\;t\_1 \cdot t\_1\\


\end{array}
\end{array}
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))) < -4.00000000000000005e-119

    1. Initial program 76.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. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
      2. lift-pow.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2}} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)} \]
      5. lift-pow.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot \color{blue}{{s}^{2}}\right) \cdot x\right)} \]
      6. *-commutativeN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)} \]
      7. associate-*r*N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}} \]
      8. unpow2N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left({s}^{2} \cdot \color{blue}{{x}^{2}}\right)} \]
      9. associate-*r*N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}} \]
      10. pow-prod-downN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(c \cdot s\right)}^{2}} \cdot {x}^{2}} \]
      11. pow-prod-downN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
      12. lower-pow.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
      13. lower-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}}^{2}} \]
      14. *-commutativeN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
      15. lower-*.f6499.2

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
    4. Applied rewrites99.2%

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(s \cdot c\right) \cdot x\right) \cdot \left(\left(s \cdot c\right) \cdot x\right)}} \]
      3. lower-*.f6499.2

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot s\right)} \cdot x\right) \cdot \left(\left(s \cdot c\right) \cdot x\right)} \]
      6. lower-*.f6499.2

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\color{blue}{\left(c \cdot s\right)} \cdot x\right)} \]
      9. lower-*.f6499.2

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

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

      \[\leadsto \frac{\color{blue}{1 + -2 \cdot {x}^{2}}}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
    8. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{-2 \cdot {x}^{2} + \color{blue}{1}}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      2. metadata-evalN/A

        \[\leadsto \frac{-2 \cdot {x}^{2} + 1 \cdot \color{blue}{1}}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      3. fp-cancel-sign-sub-invN/A

        \[\leadsto \frac{-2 \cdot {x}^{2} - \color{blue}{\left(\mathsf{neg}\left(1\right)\right) \cdot 1}}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      4. metadata-evalN/A

        \[\leadsto \frac{-2 \cdot {x}^{2} - -1 \cdot 1}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      5. metadata-evalN/A

        \[\leadsto \frac{-2 \cdot {x}^{2} - -1}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      6. lower--.f64N/A

        \[\leadsto \frac{-2 \cdot {x}^{2} - \color{blue}{-1}}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      7. lower-*.f64N/A

        \[\leadsto \frac{-2 \cdot {x}^{2} - -1}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      8. pow2N/A

        \[\leadsto \frac{-2 \cdot \left(x \cdot x\right) - -1}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      9. lift-*.f6452.5

        \[\leadsto \frac{-2 \cdot \left(x \cdot x\right) - -1}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
    9. Applied rewrites52.5%

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

    if -4.00000000000000005e-119 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x)))

    1. Initial program 61.5%

      \[\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{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot {x}^{2}}} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2}}}{{\color{blue}{s}}^{2} \cdot {x}^{2}} \]
      3. unpow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{{s}^{\color{blue}{2}} \cdot {x}^{2}} \]
      4. times-fracN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{{s}^{2}} \cdot {x}^{2}} \]
      5. pow-prod-downN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      6. unpow2N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\left(s \cdot x\right) \cdot \color{blue}{\left(s \cdot x\right)}} \]
      7. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \color{blue}{\left(s \cdot x\right)}\right) \]
      8. lower-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      9. lower-*.f6459.2

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
    5. Applied rewrites59.2%

      \[\leadsto \color{blue}{\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot x\right)\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
      3. lift-ratio-of-squares.f64N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}} \]
      4. sqr-neg-revN/A

        \[\leadsto \frac{\left(\mathsf{neg}\left(\frac{1}{c}\right)\right) \cdot \left(\mathsf{neg}\left(\frac{1}{c}\right)\right)}{\color{blue}{\left(s \cdot x\right)} \cdot \left(s \cdot x\right)} \]
      5. times-fracN/A

        \[\leadsto \frac{\mathsf{neg}\left(\frac{1}{c}\right)}{s \cdot x} \cdot \color{blue}{\frac{\mathsf{neg}\left(\frac{1}{c}\right)}{s \cdot x}} \]
      6. lower-*.f64N/A

        \[\leadsto \frac{\mathsf{neg}\left(\frac{1}{c}\right)}{s \cdot x} \cdot \color{blue}{\frac{\mathsf{neg}\left(\frac{1}{c}\right)}{s \cdot x}} \]
      7. lower-/.f64N/A

        \[\leadsto \frac{\mathsf{neg}\left(\frac{1}{c}\right)}{s \cdot x} \cdot \frac{\color{blue}{\mathsf{neg}\left(\frac{1}{c}\right)}}{s \cdot x} \]
      8. distribute-neg-fracN/A

        \[\leadsto \frac{\frac{\mathsf{neg}\left(1\right)}{c}}{s \cdot x} \cdot \frac{\mathsf{neg}\left(\color{blue}{\frac{1}{c}}\right)}{s \cdot x} \]
      9. metadata-evalN/A

        \[\leadsto \frac{\frac{-1}{c}}{s \cdot x} \cdot \frac{\mathsf{neg}\left(\frac{\color{blue}{1}}{c}\right)}{s \cdot x} \]
      10. lower-/.f64N/A

        \[\leadsto \frac{\frac{-1}{c}}{s \cdot x} \cdot \frac{\mathsf{neg}\left(\color{blue}{\frac{1}{c}}\right)}{s \cdot x} \]
      11. lift-*.f64N/A

        \[\leadsto \frac{\frac{-1}{c}}{s \cdot x} \cdot \frac{\mathsf{neg}\left(\frac{1}{c}\right)}{s \cdot x} \]
      12. lower-/.f64N/A

        \[\leadsto \frac{\frac{-1}{c}}{s \cdot x} \cdot \frac{\mathsf{neg}\left(\frac{1}{c}\right)}{\color{blue}{s \cdot x}} \]
      13. distribute-neg-fracN/A

        \[\leadsto \frac{\frac{-1}{c}}{s \cdot x} \cdot \frac{\frac{\mathsf{neg}\left(1\right)}{c}}{\color{blue}{s} \cdot x} \]
      14. metadata-evalN/A

        \[\leadsto \frac{\frac{-1}{c}}{s \cdot x} \cdot \frac{\frac{-1}{c}}{s \cdot x} \]
      15. lower-/.f64N/A

        \[\leadsto \frac{\frac{-1}{c}}{s \cdot x} \cdot \frac{\frac{-1}{c}}{\color{blue}{s} \cdot x} \]
      16. lift-*.f6481.1

        \[\leadsto \frac{\frac{-1}{c}}{s \cdot x} \cdot \frac{\frac{-1}{c}}{s \cdot \color{blue}{x}} \]
    7. Applied rewrites81.1%

      \[\leadsto \frac{\frac{-1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\frac{-1}{c}}{s \cdot x}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 81.9% accurate, 0.9× speedup?

\[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \begin{array}{l} t_0 := \left(c \cdot s\_m\right) \cdot x\\ \mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s\_m}^{2}\right) \cdot x\right)} \leq -4 \cdot 10^{-119}:\\ \;\;\;\;\frac{-2 \cdot \left(x \cdot x\right) - -1}{t\_0 \cdot t\_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{t\_0}}{t\_0}\\ \end{array} \end{array} \]
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
 :precision binary64
 (let* ((t_0 (* (* c s_m) x)))
   (if (<=
        (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s_m 2.0)) x)))
        -4e-119)
     (/ (- (* -2.0 (* x x)) -1.0) (* t_0 t_0))
     (/ (/ 1.0 t_0) t_0))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
	double t_0 = (c * s_m) * x;
	double tmp;
	if ((cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s_m, 2.0)) * x))) <= -4e-119) {
		tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0);
	} else {
		tmp = (1.0 / t_0) / t_0;
	}
	return tmp;
}
s_m =     private
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, c, s_m)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (c * s_m) * x
    if ((cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s_m ** 2.0d0)) * x))) <= (-4d-119)) then
        tmp = (((-2.0d0) * (x * x)) - (-1.0d0)) / (t_0 * t_0)
    else
        tmp = (1.0d0 / t_0) / t_0
    end if
    code = tmp
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
	double t_0 = (c * s_m) * x;
	double tmp;
	if ((Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s_m, 2.0)) * x))) <= -4e-119) {
		tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0);
	} else {
		tmp = (1.0 / t_0) / t_0;
	}
	return tmp;
}
s_m = math.fabs(s)
[x, c, s_m] = sort([x, c, s_m])
def code(x, c, s_m):
	t_0 = (c * s_m) * x
	tmp = 0
	if (math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s_m, 2.0)) * x))) <= -4e-119:
		tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0)
	else:
		tmp = (1.0 / t_0) / t_0
	return tmp
s_m = abs(s)
x, c, s_m = sort([x, c, s_m])
function code(x, c, s_m)
	t_0 = Float64(Float64(c * s_m) * x)
	tmp = 0.0
	if (Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s_m ^ 2.0)) * x))) <= -4e-119)
		tmp = Float64(Float64(Float64(-2.0 * Float64(x * x)) - -1.0) / Float64(t_0 * t_0));
	else
		tmp = Float64(Float64(1.0 / t_0) / t_0);
	end
	return tmp
end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp_2 = code(x, c, s_m)
	t_0 = (c * s_m) * x;
	tmp = 0.0;
	if ((cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s_m ^ 2.0)) * x))) <= -4e-119)
		tmp = ((-2.0 * (x * x)) - -1.0) / (t_0 * t_0);
	else
		tmp = (1.0 / t_0) / t_0;
	end
	tmp_2 = tmp;
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s$95$m, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -4e-119], N[(N[(N[(-2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision] - -1.0), $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot s\_m\right) \cdot x\\
\mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s\_m}^{2}\right) \cdot x\right)} \leq -4 \cdot 10^{-119}:\\
\;\;\;\;\frac{-2 \cdot \left(x \cdot x\right) - -1}{t\_0 \cdot t\_0}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{t\_0}}{t\_0}\\


\end{array}
\end{array}
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))) < -4.00000000000000005e-119

    1. Initial program 76.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. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
      2. lift-pow.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2}} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)} \]
      5. lift-pow.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot \color{blue}{{s}^{2}}\right) \cdot x\right)} \]
      6. *-commutativeN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)} \]
      7. associate-*r*N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}} \]
      8. unpow2N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left({s}^{2} \cdot \color{blue}{{x}^{2}}\right)} \]
      9. associate-*r*N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}} \]
      10. pow-prod-downN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(c \cdot s\right)}^{2}} \cdot {x}^{2}} \]
      11. pow-prod-downN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
      12. lower-pow.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
      13. lower-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}}^{2}} \]
      14. *-commutativeN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
      15. lower-*.f6499.2

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
    4. Applied rewrites99.2%

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(s \cdot c\right) \cdot x\right) \cdot \left(\left(s \cdot c\right) \cdot x\right)}} \]
      3. lower-*.f6499.2

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot s\right)} \cdot x\right) \cdot \left(\left(s \cdot c\right) \cdot x\right)} \]
      6. lower-*.f6499.2

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\color{blue}{\left(c \cdot s\right)} \cdot x\right)} \]
      9. lower-*.f6499.2

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

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

      \[\leadsto \frac{\color{blue}{1 + -2 \cdot {x}^{2}}}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
    8. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{-2 \cdot {x}^{2} + \color{blue}{1}}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      2. metadata-evalN/A

        \[\leadsto \frac{-2 \cdot {x}^{2} + 1 \cdot \color{blue}{1}}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      3. fp-cancel-sign-sub-invN/A

        \[\leadsto \frac{-2 \cdot {x}^{2} - \color{blue}{\left(\mathsf{neg}\left(1\right)\right) \cdot 1}}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      4. metadata-evalN/A

        \[\leadsto \frac{-2 \cdot {x}^{2} - -1 \cdot 1}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      5. metadata-evalN/A

        \[\leadsto \frac{-2 \cdot {x}^{2} - -1}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      6. lower--.f64N/A

        \[\leadsto \frac{-2 \cdot {x}^{2} - \color{blue}{-1}}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      7. lower-*.f64N/A

        \[\leadsto \frac{-2 \cdot {x}^{2} - -1}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      8. pow2N/A

        \[\leadsto \frac{-2 \cdot \left(x \cdot x\right) - -1}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
      9. lift-*.f6452.5

        \[\leadsto \frac{-2 \cdot \left(x \cdot x\right) - -1}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)} \]
    9. Applied rewrites52.5%

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

    if -4.00000000000000005e-119 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x)))

    1. Initial program 61.5%

      \[\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{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot {x}^{2}}} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2}}}{{\color{blue}{s}}^{2} \cdot {x}^{2}} \]
      3. unpow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{{s}^{\color{blue}{2}} \cdot {x}^{2}} \]
      4. times-fracN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{{s}^{2}} \cdot {x}^{2}} \]
      5. pow-prod-downN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      6. unpow2N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\left(s \cdot x\right) \cdot \color{blue}{\left(s \cdot x\right)}} \]
      7. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \color{blue}{\left(s \cdot x\right)}\right) \]
      8. lower-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      9. lower-*.f6459.2

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
    5. Applied rewrites59.2%

      \[\leadsto \color{blue}{\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot x\right)\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
      3. lift-ratio-of-squares.f64N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}} \]
      4. frac-timesN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{\color{blue}{\left(s \cdot x\right)} \cdot \left(s \cdot x\right)} \]
      5. metadata-evalN/A

        \[\leadsto \frac{\frac{1}{c \cdot c}}{\left(\color{blue}{s} \cdot x\right) \cdot \left(s \cdot x\right)} \]
      6. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(s \cdot \color{blue}{x}\right) \cdot \left(s \cdot x\right)} \]
      7. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      8. unpow-prod-downN/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
      9. associate-/r*N/A

        \[\leadsto \frac{1}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
      10. associate-*r*N/A

        \[\leadsto \frac{1}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \color{blue}{{x}^{2}}} \]
      11. *-commutativeN/A

        \[\leadsto \frac{1}{\left({s}^{2} \cdot {c}^{2}\right) \cdot {\color{blue}{x}}^{2}} \]
      12. unpow-prod-downN/A

        \[\leadsto \frac{1}{{\left(s \cdot c\right)}^{2} \cdot {\color{blue}{x}}^{2}} \]
      13. lift-*.f64N/A

        \[\leadsto \frac{1}{{\left(s \cdot c\right)}^{2} \cdot {x}^{2}} \]
      14. unpow-prod-downN/A

        \[\leadsto \frac{1}{{\left(\left(s \cdot c\right) \cdot x\right)}^{\color{blue}{2}}} \]
      15. lift-*.f64N/A

        \[\leadsto \frac{1}{{\left(\left(s \cdot c\right) \cdot x\right)}^{2}} \]
      16. lift-*.f64N/A

        \[\leadsto \frac{1}{{\left(\left(s \cdot c\right) \cdot x\right)}^{2}} \]
      17. lift-*.f64N/A

        \[\leadsto \frac{1}{{\left(\left(s \cdot c\right) \cdot x\right)}^{2}} \]
      18. unpow2N/A

        \[\leadsto \frac{1}{\left(\left(s \cdot c\right) \cdot x\right) \cdot \color{blue}{\left(\left(s \cdot c\right) \cdot x\right)}} \]
      19. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{\left(s \cdot c\right) \cdot x}}{\color{blue}{\left(s \cdot c\right) \cdot x}} \]
    7. Applied rewrites80.3%

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

Alternative 4: 97.3% accurate, 2.3× speedup?

\[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \begin{array}{l} t_0 := \left(c \cdot s\_m\right) \cdot x\\ \frac{\frac{\cos \left(-2 \cdot x\right)}{t\_0}}{t\_0} \end{array} \end{array} \]
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
 :precision binary64
 (let* ((t_0 (* (* c s_m) x))) (/ (/ (cos (* -2.0 x)) t_0) t_0)))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
	double t_0 = (c * s_m) * x;
	return (cos((-2.0 * x)) / t_0) / t_0;
}
s_m =     private
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, c, s_m)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s_m
    real(8) :: t_0
    t_0 = (c * s_m) * x
    code = (cos(((-2.0d0) * x)) / t_0) / t_0
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
	double t_0 = (c * s_m) * x;
	return (Math.cos((-2.0 * x)) / t_0) / t_0;
}
s_m = math.fabs(s)
[x, c, s_m] = sort([x, c, s_m])
def code(x, c, s_m):
	t_0 = (c * s_m) * x
	return (math.cos((-2.0 * x)) / t_0) / t_0
s_m = abs(s)
x, c, s_m = sort([x, c, s_m])
function code(x, c, s_m)
	t_0 = Float64(Float64(c * s_m) * x)
	return Float64(Float64(cos(Float64(-2.0 * x)) / t_0) / t_0)
end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp = code(x, c, s_m)
	t_0 = (c * s_m) * x;
	tmp = (cos((-2.0 * x)) / t_0) / t_0;
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, N[(N[(N[Cos[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot s\_m\right) \cdot x\\
\frac{\frac{\cos \left(-2 \cdot x\right)}{t\_0}}{t\_0}
\end{array}
\end{array}
Derivation
  1. Initial program 62.5%

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    2. lift-pow.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2}} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    4. lift-*.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)} \]
    5. lift-pow.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot \color{blue}{{s}^{2}}\right) \cdot x\right)} \]
    6. *-commutativeN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)} \]
    7. associate-*r*N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}} \]
    8. unpow2N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left({s}^{2} \cdot \color{blue}{{x}^{2}}\right)} \]
    9. associate-*r*N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}} \]
    10. pow-prod-downN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(c \cdot s\right)}^{2}} \cdot {x}^{2}} \]
    11. pow-prod-downN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
    12. lower-pow.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
    13. lower-*.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}}^{2}} \]
    14. *-commutativeN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
    15. lower-*.f6497.1

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

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

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

      \[\leadsto \frac{\color{blue}{\cos \left(2 \cdot x\right)}}{{\left(\left(s \cdot c\right) \cdot x\right)}^{2}} \]
    3. metadata-evalN/A

      \[\leadsto \frac{\cos \left(\color{blue}{\left(\mathsf{neg}\left(-2\right)\right)} \cdot x\right)}{{\left(\left(s \cdot c\right) \cdot x\right)}^{2}} \]
    4. distribute-lft-neg-inN/A

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

      \[\leadsto \frac{\color{blue}{\cos \left(-2 \cdot x\right)}}{{\left(\left(s \cdot c\right) \cdot x\right)}^{2}} \]
    6. lift-pow.f64N/A

      \[\leadsto \frac{\cos \left(-2 \cdot x\right)}{\color{blue}{{\left(\left(s \cdot c\right) \cdot x\right)}^{2}}} \]
    7. lift-*.f64N/A

      \[\leadsto \frac{\cos \left(-2 \cdot x\right)}{{\color{blue}{\left(\left(s \cdot c\right) \cdot x\right)}}^{2}} \]
    8. lift-*.f64N/A

      \[\leadsto \frac{\cos \left(-2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
    9. lift-*.f64N/A

      \[\leadsto \frac{\cos \left(-2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
    10. unpow-prod-downN/A

      \[\leadsto \frac{\cos \left(-2 \cdot x\right)}{\color{blue}{{\left(s \cdot c\right)}^{2} \cdot {x}^{2}}} \]
    11. lift-*.f64N/A

      \[\leadsto \frac{\cos \left(-2 \cdot x\right)}{{\color{blue}{\left(s \cdot c\right)}}^{2} \cdot {x}^{2}} \]
    12. unpow-prod-downN/A

      \[\leadsto \frac{\cos \left(-2 \cdot x\right)}{\color{blue}{\left({s}^{2} \cdot {c}^{2}\right)} \cdot {x}^{2}} \]
    13. *-commutativeN/A

      \[\leadsto \frac{\cos \left(-2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right)} \cdot {x}^{2}} \]
    14. associate-*r*N/A

      \[\leadsto \frac{\cos \left(-2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    15. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{\cos \left(-2 \cdot x\right)}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    16. *-commutativeN/A

      \[\leadsto \frac{\cos \left(-2 \cdot x\right)}{\color{blue}{\left({s}^{2} \cdot {x}^{2}\right) \cdot {c}^{2}}} \]
    17. *-commutativeN/A

      \[\leadsto \frac{\cos \left(-2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    18. associate-*r*N/A

      \[\leadsto \frac{\cos \left(-2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}} \]
  6. Applied rewrites97.4%

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

Alternative 5: 97.0% accurate, 2.4× speedup?

\[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \begin{array}{l} t_0 := \left(c \cdot s\_m\right) \cdot x\\ \frac{\cos \left(x + x\right)}{t\_0 \cdot t\_0} \end{array} \end{array} \]
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
 :precision binary64
 (let* ((t_0 (* (* c s_m) x))) (/ (cos (+ x x)) (* t_0 t_0))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
	double t_0 = (c * s_m) * x;
	return cos((x + x)) / (t_0 * t_0);
}
s_m =     private
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, c, s_m)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s_m
    real(8) :: t_0
    t_0 = (c * s_m) * x
    code = cos((x + x)) / (t_0 * t_0)
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
	double t_0 = (c * s_m) * x;
	return Math.cos((x + x)) / (t_0 * t_0);
}
s_m = math.fabs(s)
[x, c, s_m] = sort([x, c, s_m])
def code(x, c, s_m):
	t_0 = (c * s_m) * x
	return math.cos((x + x)) / (t_0 * t_0)
s_m = abs(s)
x, c, s_m = sort([x, c, s_m])
function code(x, c, s_m)
	t_0 = Float64(Float64(c * s_m) * x)
	return Float64(cos(Float64(x + x)) / Float64(t_0 * t_0))
end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp = code(x, c, s_m)
	t_0 = (c * s_m) * x;
	tmp = cos((x + x)) / (t_0 * t_0);
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot s\_m\right) \cdot x\\
\frac{\cos \left(x + x\right)}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Derivation
  1. Initial program 62.5%

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    2. lift-pow.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2}} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    4. lift-*.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)} \]
    5. lift-pow.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot \color{blue}{{s}^{2}}\right) \cdot x\right)} \]
    6. *-commutativeN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)} \]
    7. associate-*r*N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}} \]
    8. unpow2N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left({s}^{2} \cdot \color{blue}{{x}^{2}}\right)} \]
    9. associate-*r*N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}} \]
    10. pow-prod-downN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(c \cdot s\right)}^{2}} \cdot {x}^{2}} \]
    11. pow-prod-downN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
    12. lower-pow.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
    13. lower-*.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}}^{2}} \]
    14. *-commutativeN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
    15. lower-*.f6497.1

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

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

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

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

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot s\right)} \cdot x\right) \cdot \left(\left(s \cdot c\right) \cdot x\right)} \]
    6. lower-*.f6497.1

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\color{blue}{\left(c \cdot s\right)} \cdot x\right)} \]
    9. lower-*.f6497.1

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\color{blue}{\left(c \cdot s\right)} \cdot x\right)} \]
  6. Applied rewrites97.1%

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

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

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

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

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

Alternative 6: 77.2% accurate, 2.4× speedup?

\[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \begin{array}{l} \mathbf{if}\;{s\_m}^{2} \leq 10^{-122}:\\ \;\;\;\;\frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), s\_m\right)}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s\_m \cdot x}\right), c\right)\\ \end{array} \end{array} \]
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
 :precision binary64
 (if (<= (pow s_m 2.0) 1e-122)
   (/ (ratio-of-squares (/ -1.0 c) s_m) (* x x))
   (ratio-of-squares (/ 1.0 (* s_m x)) c)))
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
\mathbf{if}\;{s\_m}^{2} \leq 10^{-122}:\\
\;\;\;\;\frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), s\_m\right)}{x \cdot x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s\_m \cdot x}\right), c\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (pow.f64 s #s(literal 2 binary64)) < 1.00000000000000006e-122

    1. Initial program 62.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 \color{blue}{\frac{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot {x}^{2}}} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2}}}{{\color{blue}{s}}^{2} \cdot {x}^{2}} \]
      3. unpow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{{s}^{\color{blue}{2}} \cdot {x}^{2}} \]
      4. times-fracN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{{s}^{2}} \cdot {x}^{2}} \]
      5. pow-prod-downN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      6. unpow2N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\left(s \cdot x\right) \cdot \color{blue}{\left(s \cdot x\right)}} \]
      7. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \color{blue}{\left(s \cdot x\right)}\right) \]
      8. lower-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      9. lower-*.f6442.2

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
    5. Applied rewrites42.2%

      \[\leadsto \color{blue}{\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot x\right)\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
      3. lift-ratio-of-squares.f64N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}} \]
      4. frac-timesN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{\color{blue}{\left(s \cdot x\right)} \cdot \left(s \cdot x\right)} \]
      5. metadata-evalN/A

        \[\leadsto \frac{\frac{1}{c \cdot c}}{\left(\color{blue}{s} \cdot x\right) \cdot \left(s \cdot x\right)} \]
      6. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(s \cdot \color{blue}{x}\right) \cdot \left(s \cdot x\right)} \]
      7. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      8. unpow-prod-downN/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
      9. associate-/r*N/A

        \[\leadsto \frac{\frac{\frac{1}{{c}^{2}}}{{s}^{2}}}{\color{blue}{{x}^{2}}} \]
      10. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2} \cdot {s}^{2}}}{{\color{blue}{x}}^{2}} \]
      11. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2} \cdot {s}^{2}}}{{x}^{2}} \]
      12. *-commutativeN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{s}^{2} \cdot {c}^{2}}}{{x}^{2}} \]
      13. unpow-prod-downN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{\left(s \cdot c\right)}^{2}}}{{x}^{2}} \]
      14. lift-*.f64N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{\left(s \cdot c\right)}^{2}}}{{x}^{2}} \]
      15. unpow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{\left(s \cdot c\right) \cdot \left(s \cdot c\right)}}{{x}^{2}} \]
      16. times-fracN/A

        \[\leadsto \frac{\frac{1}{s \cdot c} \cdot \frac{1}{s \cdot c}}{{\color{blue}{x}}^{2}} \]
      17. pow2N/A

        \[\leadsto \frac{\frac{1}{s \cdot c} \cdot \frac{1}{s \cdot c}}{x \cdot \color{blue}{x}} \]
      18. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot c}\right), \color{blue}{x}\right) \]
      19. lower-/.f6451.8

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot c}\right), x\right) \]
      20. lift-*.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot c}\right), x\right) \]
      21. *-commutativeN/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c \cdot s}\right), x\right) \]
      22. lower-*.f6451.8

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c \cdot s}\right), x\right) \]
    7. Applied rewrites51.8%

      \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c \cdot s}\right), \color{blue}{x}\right) \]
    8. Step-by-step derivation
      1. lift-ratio-of-squares.f64N/A

        \[\leadsto \frac{\frac{1}{c \cdot s} \cdot \frac{1}{c \cdot s}}{\color{blue}{x \cdot x}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\frac{1}{c \cdot s} \cdot \frac{1}{c \cdot s}}{x \cdot x} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{\frac{1}{c \cdot s} \cdot \frac{1}{c \cdot s}}{x \cdot x} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{\frac{1}{c \cdot s} \cdot \frac{1}{c \cdot s}}{x \cdot x} \]
      5. lift-/.f64N/A

        \[\leadsto \frac{\frac{1}{c \cdot s} \cdot \frac{1}{c \cdot s}}{x \cdot x} \]
      6. frac-timesN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{\left(c \cdot s\right) \cdot \left(c \cdot s\right)}}{\color{blue}{x} \cdot x} \]
      7. metadata-evalN/A

        \[\leadsto \frac{\frac{1}{\left(c \cdot s\right) \cdot \left(c \cdot s\right)}}{x \cdot x} \]
      8. pow2N/A

        \[\leadsto \frac{\frac{1}{{\left(c \cdot s\right)}^{2}}}{x \cdot x} \]
      9. pow-prod-downN/A

        \[\leadsto \frac{\frac{1}{{c}^{2} \cdot {s}^{2}}}{x \cdot x} \]
      10. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2} \cdot {s}^{2}}}{{x}^{\color{blue}{2}}} \]
      11. lower-/.f64N/A

        \[\leadsto \frac{\frac{1}{{c}^{2} \cdot {s}^{2}}}{\color{blue}{{x}^{2}}} \]
    9. Applied rewrites62.8%

      \[\leadsto \frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), s\right)}{\color{blue}{x \cdot x}} \]

    if 1.00000000000000006e-122 < (pow.f64 s #s(literal 2 binary64))

    1. Initial program 62.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{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot {x}^{2}}} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2}}}{{\color{blue}{s}}^{2} \cdot {x}^{2}} \]
      3. unpow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{{s}^{\color{blue}{2}} \cdot {x}^{2}} \]
      4. times-fracN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{{s}^{2}} \cdot {x}^{2}} \]
      5. pow-prod-downN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      6. unpow2N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\left(s \cdot x\right) \cdot \color{blue}{\left(s \cdot x\right)}} \]
      7. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \color{blue}{\left(s \cdot x\right)}\right) \]
      8. lower-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      9. lower-*.f6464.0

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
    5. Applied rewrites64.0%

      \[\leadsto \color{blue}{\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot x\right)\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
      3. lift-ratio-of-squares.f64N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}} \]
      4. frac-timesN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{\color{blue}{\left(s \cdot x\right)} \cdot \left(s \cdot x\right)} \]
      5. metadata-evalN/A

        \[\leadsto \frac{\frac{1}{c \cdot c}}{\left(\color{blue}{s} \cdot x\right) \cdot \left(s \cdot x\right)} \]
      6. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(s \cdot \color{blue}{x}\right) \cdot \left(s \cdot x\right)} \]
      7. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      8. unpow-prod-downN/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
      9. associate-/r*N/A

        \[\leadsto \frac{1}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
      10. *-commutativeN/A

        \[\leadsto \frac{1}{\left({s}^{2} \cdot {x}^{2}\right) \cdot \color{blue}{{c}^{2}}} \]
      11. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{s}^{2} \cdot {x}^{2}}}{\color{blue}{{c}^{2}}} \]
      12. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{s}^{2} \cdot {x}^{2}}}{{c}^{2}} \]
      13. unpow-prod-downN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{\left(s \cdot x\right)}^{2}}}{{c}^{2}} \]
      14. pow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}}{{c}^{2}} \]
      15. times-fracN/A

        \[\leadsto \frac{\frac{1}{s \cdot x} \cdot \frac{1}{s \cdot x}}{{\color{blue}{c}}^{2}} \]
      16. pow2N/A

        \[\leadsto \frac{\frac{1}{s \cdot x} \cdot \frac{1}{s \cdot x}}{c \cdot \color{blue}{c}} \]
      17. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot x}\right), \color{blue}{c}\right) \]
      18. lower-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot x}\right), c\right) \]
      19. lift-*.f6479.2

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot x}\right), c\right) \]
    7. Applied rewrites79.2%

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

Alternative 7: 71.0% accurate, 2.6× speedup?

\[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \begin{array}{l} \mathbf{if}\;{s\_m}^{2} \leq 2 \cdot 10^{-144}:\\ \;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s\_m \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c \cdot s\_m}\right), x\right)\\ \end{array} \end{array} \]
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
 :precision binary64
 (if (<= (pow s_m 2.0) 2e-144)
   (ratio-of-squares (/ 1.0 c) (* s_m x))
   (ratio-of-squares (/ 1.0 (* c s_m)) x)))
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
\mathbf{if}\;{s\_m}^{2} \leq 2 \cdot 10^{-144}:\\
\;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s\_m \cdot x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c \cdot s\_m}\right), x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (pow.f64 s #s(literal 2 binary64)) < 1.9999999999999999e-144

    1. Initial program 61.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{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot {x}^{2}}} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2}}}{{\color{blue}{s}}^{2} \cdot {x}^{2}} \]
      3. unpow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{{s}^{\color{blue}{2}} \cdot {x}^{2}} \]
      4. times-fracN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{{s}^{2}} \cdot {x}^{2}} \]
      5. pow-prod-downN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      6. unpow2N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\left(s \cdot x\right) \cdot \color{blue}{\left(s \cdot x\right)}} \]
      7. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \color{blue}{\left(s \cdot x\right)}\right) \]
      8. lower-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      9. lower-*.f6439.9

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
    5. Applied rewrites39.9%

      \[\leadsto \color{blue}{\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot x\right)\right)} \]

    if 1.9999999999999999e-144 < (pow.f64 s #s(literal 2 binary64))

    1. Initial program 63.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{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot {x}^{2}}} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2}}}{{\color{blue}{s}}^{2} \cdot {x}^{2}} \]
      3. unpow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{{s}^{\color{blue}{2}} \cdot {x}^{2}} \]
      4. times-fracN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{{s}^{2}} \cdot {x}^{2}} \]
      5. pow-prod-downN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      6. unpow2N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\left(s \cdot x\right) \cdot \color{blue}{\left(s \cdot x\right)}} \]
      7. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \color{blue}{\left(s \cdot x\right)}\right) \]
      8. lower-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      9. lower-*.f6464.9

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
    5. Applied rewrites64.9%

      \[\leadsto \color{blue}{\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot x\right)\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
      3. lift-ratio-of-squares.f64N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}} \]
      4. frac-timesN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{\color{blue}{\left(s \cdot x\right)} \cdot \left(s \cdot x\right)} \]
      5. metadata-evalN/A

        \[\leadsto \frac{\frac{1}{c \cdot c}}{\left(\color{blue}{s} \cdot x\right) \cdot \left(s \cdot x\right)} \]
      6. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(s \cdot \color{blue}{x}\right) \cdot \left(s \cdot x\right)} \]
      7. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      8. unpow-prod-downN/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
      9. associate-/r*N/A

        \[\leadsto \frac{\frac{\frac{1}{{c}^{2}}}{{s}^{2}}}{\color{blue}{{x}^{2}}} \]
      10. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2} \cdot {s}^{2}}}{{\color{blue}{x}}^{2}} \]
      11. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2} \cdot {s}^{2}}}{{x}^{2}} \]
      12. *-commutativeN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{s}^{2} \cdot {c}^{2}}}{{x}^{2}} \]
      13. unpow-prod-downN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{\left(s \cdot c\right)}^{2}}}{{x}^{2}} \]
      14. lift-*.f64N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{\left(s \cdot c\right)}^{2}}}{{x}^{2}} \]
      15. unpow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{\left(s \cdot c\right) \cdot \left(s \cdot c\right)}}{{x}^{2}} \]
      16. times-fracN/A

        \[\leadsto \frac{\frac{1}{s \cdot c} \cdot \frac{1}{s \cdot c}}{{\color{blue}{x}}^{2}} \]
      17. pow2N/A

        \[\leadsto \frac{\frac{1}{s \cdot c} \cdot \frac{1}{s \cdot c}}{x \cdot \color{blue}{x}} \]
      18. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot c}\right), \color{blue}{x}\right) \]
      19. lower-/.f6477.1

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot c}\right), x\right) \]
      20. lift-*.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot c}\right), x\right) \]
      21. *-commutativeN/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c \cdot s}\right), x\right) \]
      22. lower-*.f6477.1

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c \cdot s}\right), x\right) \]
    7. Applied rewrites77.1%

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

Alternative 8: 78.4% accurate, 7.8× speedup?

\[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \begin{array}{l} t_0 := \left(c \cdot s\_m\right) \cdot x\\ \frac{\frac{1}{t\_0}}{t\_0} \end{array} \end{array} \]
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
 :precision binary64
 (let* ((t_0 (* (* c s_m) x))) (/ (/ 1.0 t_0) t_0)))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
	double t_0 = (c * s_m) * x;
	return (1.0 / t_0) / t_0;
}
s_m =     private
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, c, s_m)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s_m
    real(8) :: t_0
    t_0 = (c * s_m) * x
    code = (1.0d0 / t_0) / t_0
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
	double t_0 = (c * s_m) * x;
	return (1.0 / t_0) / t_0;
}
s_m = math.fabs(s)
[x, c, s_m] = sort([x, c, s_m])
def code(x, c, s_m):
	t_0 = (c * s_m) * x
	return (1.0 / t_0) / t_0
s_m = abs(s)
x, c, s_m = sort([x, c, s_m])
function code(x, c, s_m)
	t_0 = Float64(Float64(c * s_m) * x)
	return Float64(Float64(1.0 / t_0) / t_0)
end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp = code(x, c, s_m)
	t_0 = (c * s_m) * x;
	tmp = (1.0 / t_0) / t_0;
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, N[(N[(1.0 / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot s\_m\right) \cdot x\\
\frac{\frac{1}{t\_0}}{t\_0}
\end{array}
\end{array}
Derivation
  1. Initial program 62.5%

    \[\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{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
  4. Step-by-step derivation
    1. associate-/r*N/A

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot {x}^{2}}} \]
    2. metadata-evalN/A

      \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2}}}{{\color{blue}{s}}^{2} \cdot {x}^{2}} \]
    3. unpow2N/A

      \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{{s}^{\color{blue}{2}} \cdot {x}^{2}} \]
    4. times-fracN/A

      \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{{s}^{2}} \cdot {x}^{2}} \]
    5. pow-prod-downN/A

      \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
    6. unpow2N/A

      \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\left(s \cdot x\right) \cdot \color{blue}{\left(s \cdot x\right)}} \]
    7. lower-ratio-of-squares.f64N/A

      \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \color{blue}{\left(s \cdot x\right)}\right) \]
    8. lower-/.f64N/A

      \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
    9. lower-*.f6455.1

      \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
  5. Applied rewrites55.1%

    \[\leadsto \color{blue}{\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot x\right)\right)} \]
  6. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
    2. lift-*.f64N/A

      \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
    3. lift-ratio-of-squares.f64N/A

      \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}} \]
    4. frac-timesN/A

      \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{\color{blue}{\left(s \cdot x\right)} \cdot \left(s \cdot x\right)} \]
    5. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{c \cdot c}}{\left(\color{blue}{s} \cdot x\right) \cdot \left(s \cdot x\right)} \]
    6. pow2N/A

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(s \cdot \color{blue}{x}\right) \cdot \left(s \cdot x\right)} \]
    7. pow2N/A

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
    8. unpow-prod-downN/A

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
    9. associate-/r*N/A

      \[\leadsto \frac{1}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    10. associate-*r*N/A

      \[\leadsto \frac{1}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \color{blue}{{x}^{2}}} \]
    11. *-commutativeN/A

      \[\leadsto \frac{1}{\left({s}^{2} \cdot {c}^{2}\right) \cdot {\color{blue}{x}}^{2}} \]
    12. unpow-prod-downN/A

      \[\leadsto \frac{1}{{\left(s \cdot c\right)}^{2} \cdot {\color{blue}{x}}^{2}} \]
    13. lift-*.f64N/A

      \[\leadsto \frac{1}{{\left(s \cdot c\right)}^{2} \cdot {x}^{2}} \]
    14. unpow-prod-downN/A

      \[\leadsto \frac{1}{{\left(\left(s \cdot c\right) \cdot x\right)}^{\color{blue}{2}}} \]
    15. lift-*.f64N/A

      \[\leadsto \frac{1}{{\left(\left(s \cdot c\right) \cdot x\right)}^{2}} \]
    16. lift-*.f64N/A

      \[\leadsto \frac{1}{{\left(\left(s \cdot c\right) \cdot x\right)}^{2}} \]
    17. lift-*.f64N/A

      \[\leadsto \frac{1}{{\left(\left(s \cdot c\right) \cdot x\right)}^{2}} \]
    18. unpow2N/A

      \[\leadsto \frac{1}{\left(\left(s \cdot c\right) \cdot x\right) \cdot \color{blue}{\left(\left(s \cdot c\right) \cdot x\right)}} \]
    19. associate-/r*N/A

      \[\leadsto \frac{\frac{1}{\left(s \cdot c\right) \cdot x}}{\color{blue}{\left(s \cdot c\right) \cdot x}} \]
  7. Applied rewrites74.7%

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

Alternative 9: 78.5% accurate, 7.8× speedup?

\[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \begin{array}{l} \mathbf{if}\;s\_m \leq 1.65 \cdot 10^{+62}:\\ \;\;\;\;\frac{\frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), x\right)}{s\_m}}{s\_m}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s\_m \cdot x}\right), c\right)\\ \end{array} \end{array} \]
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
 :precision binary64
 (if (<= s_m 1.65e+62)
   (/ (/ (ratio-of-squares (/ -1.0 c) x) s_m) s_m)
   (ratio-of-squares (/ 1.0 (* s_m x)) c)))
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
\mathbf{if}\;s\_m \leq 1.65 \cdot 10^{+62}:\\
\;\;\;\;\frac{\frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), x\right)}{s\_m}}{s\_m}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s\_m \cdot x}\right), c\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 1.65e62

    1. Initial program 61.5%

      \[\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{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot {x}^{2}}} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2}}}{{\color{blue}{s}}^{2} \cdot {x}^{2}} \]
      3. unpow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{{s}^{\color{blue}{2}} \cdot {x}^{2}} \]
      4. times-fracN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{{s}^{2}} \cdot {x}^{2}} \]
      5. pow-prod-downN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      6. unpow2N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\left(s \cdot x\right) \cdot \color{blue}{\left(s \cdot x\right)}} \]
      7. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \color{blue}{\left(s \cdot x\right)}\right) \]
      8. lower-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      9. lower-*.f6452.5

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
    5. Applied rewrites52.5%

      \[\leadsto \color{blue}{\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot x\right)\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
      3. lift-ratio-of-squares.f64N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}} \]
      4. frac-timesN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{\color{blue}{\left(s \cdot x\right)} \cdot \left(s \cdot x\right)} \]
      5. metadata-evalN/A

        \[\leadsto \frac{\frac{1}{c \cdot c}}{\left(\color{blue}{s} \cdot x\right) \cdot \left(s \cdot x\right)} \]
      6. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(s \cdot \color{blue}{x}\right) \cdot \left(s \cdot x\right)} \]
      7. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      8. unpow-prod-downN/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
      9. associate-/r*N/A

        \[\leadsto \frac{\frac{\frac{1}{{c}^{2}}}{{s}^{2}}}{\color{blue}{{x}^{2}}} \]
      10. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2} \cdot {s}^{2}}}{{\color{blue}{x}}^{2}} \]
      11. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2} \cdot {s}^{2}}}{{x}^{2}} \]
      12. *-commutativeN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{s}^{2} \cdot {c}^{2}}}{{x}^{2}} \]
      13. unpow-prod-downN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{\left(s \cdot c\right)}^{2}}}{{x}^{2}} \]
      14. lift-*.f64N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{\left(s \cdot c\right)}^{2}}}{{x}^{2}} \]
      15. unpow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{\left(s \cdot c\right) \cdot \left(s \cdot c\right)}}{{x}^{2}} \]
      16. times-fracN/A

        \[\leadsto \frac{\frac{1}{s \cdot c} \cdot \frac{1}{s \cdot c}}{{\color{blue}{x}}^{2}} \]
      17. pow2N/A

        \[\leadsto \frac{\frac{1}{s \cdot c} \cdot \frac{1}{s \cdot c}}{x \cdot \color{blue}{x}} \]
      18. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot c}\right), \color{blue}{x}\right) \]
      19. lower-/.f6463.1

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot c}\right), x\right) \]
      20. lift-*.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot c}\right), x\right) \]
      21. *-commutativeN/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c \cdot s}\right), x\right) \]
      22. lower-*.f6463.1

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c \cdot s}\right), x\right) \]
    7. Applied rewrites63.1%

      \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c \cdot s}\right), \color{blue}{x}\right) \]
    8. Step-by-step derivation
      1. lift-ratio-of-squares.f64N/A

        \[\leadsto \frac{\frac{1}{c \cdot s} \cdot \frac{1}{c \cdot s}}{\color{blue}{x \cdot x}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\frac{1}{c \cdot s} \cdot \frac{1}{c \cdot s}}{x \cdot x} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{\frac{1}{c \cdot s} \cdot \frac{1}{c \cdot s}}{x \cdot x} \]
      4. associate-/r*N/A

        \[\leadsto \frac{\frac{\frac{1}{c}}{s} \cdot \frac{1}{c \cdot s}}{x \cdot x} \]
      5. lift-*.f64N/A

        \[\leadsto \frac{\frac{\frac{1}{c}}{s} \cdot \frac{1}{c \cdot s}}{x \cdot x} \]
      6. lift-/.f64N/A

        \[\leadsto \frac{\frac{\frac{1}{c}}{s} \cdot \frac{1}{c \cdot s}}{x \cdot x} \]
      7. associate-/r*N/A

        \[\leadsto \frac{\frac{\frac{1}{c}}{s} \cdot \frac{\frac{1}{c}}{s}}{x \cdot x} \]
      8. frac-timesN/A

        \[\leadsto \frac{\frac{\frac{1}{c} \cdot \frac{1}{c}}{s \cdot s}}{\color{blue}{x} \cdot x} \]
      9. times-fracN/A

        \[\leadsto \frac{\frac{\frac{1 \cdot 1}{c \cdot c}}{s \cdot s}}{x \cdot x} \]
      10. metadata-evalN/A

        \[\leadsto \frac{\frac{\frac{1}{c \cdot c}}{s \cdot s}}{x \cdot x} \]
      11. pow2N/A

        \[\leadsto \frac{\frac{\frac{1}{{c}^{2}}}{s \cdot s}}{x \cdot x} \]
      12. lift-*.f64N/A

        \[\leadsto \frac{\frac{\frac{1}{{c}^{2}}}{s \cdot s}}{x \cdot x} \]
      13. pow2N/A

        \[\leadsto \frac{\frac{\frac{1}{{c}^{2}}}{s \cdot s}}{{x}^{\color{blue}{2}}} \]
      14. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{\left(s \cdot s\right) \cdot {x}^{2}}} \]
      15. *-commutativeN/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{x}^{2} \cdot \color{blue}{\left(s \cdot s\right)}} \]
      16. associate-/r*N/A

        \[\leadsto \frac{\frac{\frac{1}{{c}^{2}}}{{x}^{2}}}{\color{blue}{s \cdot s}} \]
    9. Applied rewrites66.1%

      \[\leadsto \frac{\frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), x\right)}{s}}{\color{blue}{s}} \]

    if 1.65e62 < s

    1. Initial program 68.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{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot {x}^{2}}} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2}}}{{\color{blue}{s}}^{2} \cdot {x}^{2}} \]
      3. unpow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{{s}^{\color{blue}{2}} \cdot {x}^{2}} \]
      4. times-fracN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{{s}^{2}} \cdot {x}^{2}} \]
      5. pow-prod-downN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      6. unpow2N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\left(s \cdot x\right) \cdot \color{blue}{\left(s \cdot x\right)}} \]
      7. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \color{blue}{\left(s \cdot x\right)}\right) \]
      8. lower-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      9. lower-*.f6469.2

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
    5. Applied rewrites69.2%

      \[\leadsto \color{blue}{\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot x\right)\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
      3. lift-ratio-of-squares.f64N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}} \]
      4. frac-timesN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{\color{blue}{\left(s \cdot x\right)} \cdot \left(s \cdot x\right)} \]
      5. metadata-evalN/A

        \[\leadsto \frac{\frac{1}{c \cdot c}}{\left(\color{blue}{s} \cdot x\right) \cdot \left(s \cdot x\right)} \]
      6. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(s \cdot \color{blue}{x}\right) \cdot \left(s \cdot x\right)} \]
      7. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      8. unpow-prod-downN/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
      9. associate-/r*N/A

        \[\leadsto \frac{1}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
      10. *-commutativeN/A

        \[\leadsto \frac{1}{\left({s}^{2} \cdot {x}^{2}\right) \cdot \color{blue}{{c}^{2}}} \]
      11. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{s}^{2} \cdot {x}^{2}}}{\color{blue}{{c}^{2}}} \]
      12. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{s}^{2} \cdot {x}^{2}}}{{c}^{2}} \]
      13. unpow-prod-downN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{\left(s \cdot x\right)}^{2}}}{{c}^{2}} \]
      14. pow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}}{{c}^{2}} \]
      15. times-fracN/A

        \[\leadsto \frac{\frac{1}{s \cdot x} \cdot \frac{1}{s \cdot x}}{{\color{blue}{c}}^{2}} \]
      16. pow2N/A

        \[\leadsto \frac{\frac{1}{s \cdot x} \cdot \frac{1}{s \cdot x}}{c \cdot \color{blue}{c}} \]
      17. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot x}\right), \color{blue}{c}\right) \]
      18. lower-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot x}\right), c\right) \]
      19. lift-*.f6489.1

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot x}\right), c\right) \]
    7. Applied rewrites89.1%

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

Alternative 10: 78.3% accurate, 9.0× speedup?

\[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \begin{array}{l} t_0 := \left(c \cdot s\_m\right) \cdot x\\ \frac{1}{t\_0 \cdot t\_0} \end{array} \end{array} \]
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
 :precision binary64
 (let* ((t_0 (* (* c s_m) x))) (/ 1.0 (* t_0 t_0))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
	double t_0 = (c * s_m) * x;
	return 1.0 / (t_0 * t_0);
}
s_m =     private
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, c, s_m)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s_m
    real(8) :: t_0
    t_0 = (c * s_m) * x
    code = 1.0d0 / (t_0 * t_0)
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
	double t_0 = (c * s_m) * x;
	return 1.0 / (t_0 * t_0);
}
s_m = math.fabs(s)
[x, c, s_m] = sort([x, c, s_m])
def code(x, c, s_m):
	t_0 = (c * s_m) * x
	return 1.0 / (t_0 * t_0)
s_m = abs(s)
x, c, s_m = sort([x, c, s_m])
function code(x, c, s_m)
	t_0 = Float64(Float64(c * s_m) * x)
	return Float64(1.0 / Float64(t_0 * t_0))
end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp = code(x, c, s_m)
	t_0 = (c * s_m) * x;
	tmp = 1.0 / (t_0 * t_0);
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(N[(c * s$95$m), $MachinePrecision] * x), $MachinePrecision]}, N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot s\_m\right) \cdot x\\
\frac{1}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Derivation
  1. Initial program 62.5%

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    2. lift-pow.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2}} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    4. lift-*.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)} \]
    5. lift-pow.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot \color{blue}{{s}^{2}}\right) \cdot x\right)} \]
    6. *-commutativeN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)} \]
    7. associate-*r*N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}} \]
    8. unpow2N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left({s}^{2} \cdot \color{blue}{{x}^{2}}\right)} \]
    9. associate-*r*N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}} \]
    10. pow-prod-downN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(c \cdot s\right)}^{2}} \cdot {x}^{2}} \]
    11. pow-prod-downN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
    12. lower-pow.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}} \]
    13. lower-*.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}}^{2}} \]
    14. *-commutativeN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{\left(\color{blue}{\left(s \cdot c\right)} \cdot x\right)}^{2}} \]
    15. lower-*.f6497.1

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

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

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

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

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot s\right)} \cdot x\right) \cdot \left(\left(s \cdot c\right) \cdot x\right)} \]
    6. lower-*.f6497.1

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\color{blue}{\left(c \cdot s\right)} \cdot x\right)} \]
    9. lower-*.f6497.1

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\color{blue}{\left(c \cdot s\right)} \cdot x\right)} \]
  6. Applied rewrites97.1%

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

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

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

    Alternative 11: 77.5% accurate, 9.1× speedup?

    \[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \begin{array}{l} \mathbf{if}\;s\_m \leq 5 \cdot 10^{+21}:\\ \;\;\;\;\frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), x\right)}{s\_m \cdot s\_m}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s\_m \cdot x}\right), c\right)\\ \end{array} \end{array} \]
    s_m = (fabs.f64 s)
    NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
    (FPCore (x c s_m)
     :precision binary64
     (if (<= s_m 5e+21)
       (/ (ratio-of-squares (/ -1.0 c) x) (* s_m s_m))
       (ratio-of-squares (/ 1.0 (* s_m x)) c)))
    \begin{array}{l}
    s_m = \left|s\right|
    \\
    [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;s\_m \leq 5 \cdot 10^{+21}:\\
    \;\;\;\;\frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), x\right)}{s\_m \cdot s\_m}\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s\_m \cdot x}\right), c\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if s < 5e21

      1. Initial program 60.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 \color{blue}{\frac{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
      4. Step-by-step derivation
        1. associate-/r*N/A

          \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot {x}^{2}}} \]
        2. metadata-evalN/A

          \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2}}}{{\color{blue}{s}}^{2} \cdot {x}^{2}} \]
        3. unpow2N/A

          \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{{s}^{\color{blue}{2}} \cdot {x}^{2}} \]
        4. times-fracN/A

          \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{{s}^{2}} \cdot {x}^{2}} \]
        5. pow-prod-downN/A

          \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
        6. unpow2N/A

          \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\left(s \cdot x\right) \cdot \color{blue}{\left(s \cdot x\right)}} \]
        7. lower-ratio-of-squares.f64N/A

          \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \color{blue}{\left(s \cdot x\right)}\right) \]
        8. lower-/.f64N/A

          \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
        9. lower-*.f6451.6

          \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
      5. Applied rewrites51.6%

        \[\leadsto \color{blue}{\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot x\right)\right)} \]
      6. Step-by-step derivation
        1. lift-/.f64N/A

          \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
        2. lift-*.f64N/A

          \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
        3. lift-ratio-of-squares.f64N/A

          \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}} \]
        4. frac-timesN/A

          \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{\color{blue}{\left(s \cdot x\right)} \cdot \left(s \cdot x\right)} \]
        5. metadata-evalN/A

          \[\leadsto \frac{\frac{1}{c \cdot c}}{\left(\color{blue}{s} \cdot x\right) \cdot \left(s \cdot x\right)} \]
        6. pow2N/A

          \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(s \cdot \color{blue}{x}\right) \cdot \left(s \cdot x\right)} \]
        7. pow2N/A

          \[\leadsto \frac{\frac{1}{{c}^{2}}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
        8. unpow-prod-downN/A

          \[\leadsto \frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
        9. *-commutativeN/A

          \[\leadsto \frac{\frac{1}{{c}^{2}}}{{x}^{2} \cdot \color{blue}{{s}^{2}}} \]
        10. associate-/r*N/A

          \[\leadsto \frac{\frac{\frac{1}{{c}^{2}}}{{x}^{2}}}{\color{blue}{{s}^{2}}} \]
        11. lower-/.f64N/A

          \[\leadsto \frac{\frac{\frac{1}{{c}^{2}}}{{x}^{2}}}{\color{blue}{{s}^{2}}} \]
        12. metadata-evalN/A

          \[\leadsto \frac{\frac{\frac{1 \cdot 1}{{c}^{2}}}{{x}^{2}}}{{s}^{2}} \]
        13. pow2N/A

          \[\leadsto \frac{\frac{\frac{1 \cdot 1}{c \cdot c}}{{x}^{2}}}{{s}^{2}} \]
        14. frac-timesN/A

          \[\leadsto \frac{\frac{\frac{1}{c} \cdot \frac{1}{c}}{{x}^{2}}}{{s}^{2}} \]
        15. sqr-neg-revN/A

          \[\leadsto \frac{\frac{\left(\mathsf{neg}\left(\frac{1}{c}\right)\right) \cdot \left(\mathsf{neg}\left(\frac{1}{c}\right)\right)}{{x}^{2}}}{{s}^{2}} \]
        16. pow2N/A

          \[\leadsto \frac{\frac{\left(\mathsf{neg}\left(\frac{1}{c}\right)\right) \cdot \left(\mathsf{neg}\left(\frac{1}{c}\right)\right)}{x \cdot x}}{{s}^{2}} \]
        17. lower-ratio-of-squares.f64N/A

          \[\leadsto \frac{\mathsf{ratio\_of\_squares}\left(\left(\mathsf{neg}\left(\frac{1}{c}\right)\right), x\right)}{{\color{blue}{s}}^{2}} \]
        18. distribute-neg-fracN/A

          \[\leadsto \frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{\mathsf{neg}\left(1\right)}{c}\right), x\right)}{{s}^{2}} \]
        19. metadata-evalN/A

          \[\leadsto \frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), x\right)}{{s}^{2}} \]
        20. lower-/.f64N/A

          \[\leadsto \frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), x\right)}{{s}^{2}} \]
        21. pow2N/A

          \[\leadsto \frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), x\right)}{s \cdot \color{blue}{s}} \]
        22. lift-*.f6459.8

          \[\leadsto \frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), x\right)}{s \cdot \color{blue}{s}} \]
      7. Applied rewrites59.8%

        \[\leadsto \frac{\mathsf{ratio\_of\_squares}\left(\left(\frac{-1}{c}\right), x\right)}{\color{blue}{s \cdot s}} \]

      if 5e21 < s

      1. Initial program 70.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{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
      4. Step-by-step derivation
        1. associate-/r*N/A

          \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot {x}^{2}}} \]
        2. metadata-evalN/A

          \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2}}}{{\color{blue}{s}}^{2} \cdot {x}^{2}} \]
        3. unpow2N/A

          \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{{s}^{\color{blue}{2}} \cdot {x}^{2}} \]
        4. times-fracN/A

          \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{{s}^{2}} \cdot {x}^{2}} \]
        5. pow-prod-downN/A

          \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
        6. unpow2N/A

          \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\left(s \cdot x\right) \cdot \color{blue}{\left(s \cdot x\right)}} \]
        7. lower-ratio-of-squares.f64N/A

          \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \color{blue}{\left(s \cdot x\right)}\right) \]
        8. lower-/.f64N/A

          \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
        9. lower-*.f6471.3

          \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
      5. Applied rewrites71.3%

        \[\leadsto \color{blue}{\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot x\right)\right)} \]
      6. Step-by-step derivation
        1. lift-/.f64N/A

          \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
        2. lift-*.f64N/A

          \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
        3. lift-ratio-of-squares.f64N/A

          \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}} \]
        4. frac-timesN/A

          \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{\color{blue}{\left(s \cdot x\right)} \cdot \left(s \cdot x\right)} \]
        5. metadata-evalN/A

          \[\leadsto \frac{\frac{1}{c \cdot c}}{\left(\color{blue}{s} \cdot x\right) \cdot \left(s \cdot x\right)} \]
        6. pow2N/A

          \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(s \cdot \color{blue}{x}\right) \cdot \left(s \cdot x\right)} \]
        7. pow2N/A

          \[\leadsto \frac{\frac{1}{{c}^{2}}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
        8. unpow-prod-downN/A

          \[\leadsto \frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
        9. associate-/r*N/A

          \[\leadsto \frac{1}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
        10. *-commutativeN/A

          \[\leadsto \frac{1}{\left({s}^{2} \cdot {x}^{2}\right) \cdot \color{blue}{{c}^{2}}} \]
        11. associate-/r*N/A

          \[\leadsto \frac{\frac{1}{{s}^{2} \cdot {x}^{2}}}{\color{blue}{{c}^{2}}} \]
        12. metadata-evalN/A

          \[\leadsto \frac{\frac{1 \cdot 1}{{s}^{2} \cdot {x}^{2}}}{{c}^{2}} \]
        13. unpow-prod-downN/A

          \[\leadsto \frac{\frac{1 \cdot 1}{{\left(s \cdot x\right)}^{2}}}{{c}^{2}} \]
        14. pow2N/A

          \[\leadsto \frac{\frac{1 \cdot 1}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}}{{c}^{2}} \]
        15. times-fracN/A

          \[\leadsto \frac{\frac{1}{s \cdot x} \cdot \frac{1}{s \cdot x}}{{\color{blue}{c}}^{2}} \]
        16. pow2N/A

          \[\leadsto \frac{\frac{1}{s \cdot x} \cdot \frac{1}{s \cdot x}}{c \cdot \color{blue}{c}} \]
        17. lower-ratio-of-squares.f64N/A

          \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot x}\right), \color{blue}{c}\right) \]
        18. lower-/.f64N/A

          \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot x}\right), c\right) \]
        19. lift-*.f6488.5

          \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot x}\right), c\right) \]
      7. Applied rewrites88.5%

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

    Alternative 12: 71.6% accurate, 17.1× speedup?

    \[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s\_m \cdot x}\right), c\right) \end{array} \]
    s_m = (fabs.f64 s)
    NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
    (FPCore (x c s_m) :precision binary64 (ratio-of-squares (/ 1.0 (* s_m x)) c))
    \begin{array}{l}
    s_m = \left|s\right|
    \\
    [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
    \\
    \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s\_m \cdot x}\right), c\right)
    \end{array}
    
    Derivation
    1. Initial program 62.5%

      \[\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{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot {x}^{2}}} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2}}}{{\color{blue}{s}}^{2} \cdot {x}^{2}} \]
      3. unpow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{{s}^{\color{blue}{2}} \cdot {x}^{2}} \]
      4. times-fracN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{{s}^{2}} \cdot {x}^{2}} \]
      5. pow-prod-downN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      6. unpow2N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\left(s \cdot x\right) \cdot \color{blue}{\left(s \cdot x\right)}} \]
      7. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \color{blue}{\left(s \cdot x\right)}\right) \]
      8. lower-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      9. lower-*.f6455.1

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
    5. Applied rewrites55.1%

      \[\leadsto \color{blue}{\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot x\right)\right)} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
      3. lift-ratio-of-squares.f64N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}} \]
      4. frac-timesN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{\color{blue}{\left(s \cdot x\right)} \cdot \left(s \cdot x\right)} \]
      5. metadata-evalN/A

        \[\leadsto \frac{\frac{1}{c \cdot c}}{\left(\color{blue}{s} \cdot x\right) \cdot \left(s \cdot x\right)} \]
      6. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(s \cdot \color{blue}{x}\right) \cdot \left(s \cdot x\right)} \]
      7. pow2N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      8. unpow-prod-downN/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
      9. associate-/r*N/A

        \[\leadsto \frac{1}{\color{blue}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
      10. *-commutativeN/A

        \[\leadsto \frac{1}{\left({s}^{2} \cdot {x}^{2}\right) \cdot \color{blue}{{c}^{2}}} \]
      11. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{s}^{2} \cdot {x}^{2}}}{\color{blue}{{c}^{2}}} \]
      12. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{s}^{2} \cdot {x}^{2}}}{{c}^{2}} \]
      13. unpow-prod-downN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{\left(s \cdot x\right)}^{2}}}{{c}^{2}} \]
      14. pow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}}{{c}^{2}} \]
      15. times-fracN/A

        \[\leadsto \frac{\frac{1}{s \cdot x} \cdot \frac{1}{s \cdot x}}{{\color{blue}{c}}^{2}} \]
      16. pow2N/A

        \[\leadsto \frac{\frac{1}{s \cdot x} \cdot \frac{1}{s \cdot x}}{c \cdot \color{blue}{c}} \]
      17. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot x}\right), \color{blue}{c}\right) \]
      18. lower-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot x}\right), c\right) \]
      19. lift-*.f6463.2

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot x}\right), c\right) \]
    7. Applied rewrites63.2%

      \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{s \cdot x}\right), \color{blue}{c}\right) \]
    8. Add Preprocessing

    Alternative 13: 57.4% accurate, 17.1× speedup?

    \[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s\_m \cdot x\right)\right) \end{array} \]
    s_m = (fabs.f64 s)
    NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
    (FPCore (x c s_m) :precision binary64 (ratio-of-squares (/ 1.0 c) (* s_m x)))
    \begin{array}{l}
    s_m = \left|s\right|
    \\
    [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
    \\
    \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s\_m \cdot x\right)\right)
    \end{array}
    
    Derivation
    1. Initial program 62.5%

      \[\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{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot {x}^{2}}} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\frac{1 \cdot 1}{{c}^{2}}}{{\color{blue}{s}}^{2} \cdot {x}^{2}} \]
      3. unpow2N/A

        \[\leadsto \frac{\frac{1 \cdot 1}{c \cdot c}}{{s}^{\color{blue}{2}} \cdot {x}^{2}} \]
      4. times-fracN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\color{blue}{{s}^{2}} \cdot {x}^{2}} \]
      5. pow-prod-downN/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{{\left(s \cdot x\right)}^{\color{blue}{2}}} \]
      6. unpow2N/A

        \[\leadsto \frac{\frac{1}{c} \cdot \frac{1}{c}}{\left(s \cdot x\right) \cdot \color{blue}{\left(s \cdot x\right)}} \]
      7. lower-ratio-of-squares.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \color{blue}{\left(s \cdot x\right)}\right) \]
      8. lower-/.f64N/A

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(\color{blue}{s} \cdot x\right)\right) \]
      9. lower-*.f6455.1

        \[\leadsto \mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot \color{blue}{x}\right)\right) \]
    5. Applied rewrites55.1%

      \[\leadsto \color{blue}{\mathsf{ratio\_of\_squares}\left(\left(\frac{1}{c}\right), \left(s \cdot x\right)\right)} \]
    6. Add Preprocessing

    Reproduce

    ?
    herbie shell --seed 2025058 
    (FPCore (x c s)
      :name "mixedcos"
      :precision binary64
      (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))