cos2 (problem 3.4.1)

Percentage Accurate: 50.4% → 99.5%
Time: 3.2s
Alternatives: 8
Speedup: 41.8×

Specification

?
\[\begin{array}{l} \\ \frac{1 - \cos x}{x \cdot x} \end{array} \]
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
double code(double x) {
	return (1.0 - cos(x)) / (x * 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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = (1.0d0 - cos(x)) / (x * x)
end function
public static double code(double x) {
	return (1.0 - Math.cos(x)) / (x * x);
}
def code(x):
	return (1.0 - math.cos(x)) / (x * x)
function code(x)
	return Float64(Float64(1.0 - cos(x)) / Float64(x * x))
end
function tmp = code(x)
	tmp = (1.0 - cos(x)) / (x * x);
end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1 - \cos x}{x \cdot x}
\end{array}

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 8 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: 50.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1 - \cos x}{x \cdot x} \end{array} \]
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
double code(double x) {
	return (1.0 - cos(x)) / (x * 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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = (1.0d0 - cos(x)) / (x * x)
end function
public static double code(double x) {
	return (1.0 - Math.cos(x)) / (x * x);
}
def code(x):
	return (1.0 - math.cos(x)) / (x * x)
function code(x)
	return Float64(Float64(1.0 - cos(x)) / Float64(x * x))
end
function tmp = code(x)
	tmp = (1.0 - cos(x)) / (x * x);
end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1 - \cos x}{x \cdot x}
\end{array}

Alternative 1: 99.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \frac{\sin x}{x} \end{array} \]
(FPCore (x)
 :precision binary64
 (* (/ (sin x) (fma (cos x) x x)) (/ (sin x) x)))
double code(double x) {
	return (sin(x) / fma(cos(x), x, x)) * (sin(x) / x);
}
function code(x)
	return Float64(Float64(sin(x) / fma(cos(x), x, x)) * Float64(sin(x) / x))
end
code[x_] := N[(N[(N[Sin[x], $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision] * N[(N[Sin[x], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \frac{\sin x}{x}
\end{array}
Derivation
  1. Initial program 50.4%

    \[\frac{1 - \cos x}{x \cdot x} \]
  2. Step-by-step derivation
    1. lift-/.f64N/A

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

      \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
    3. flip--N/A

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
    4. associate-/l/N/A

      \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
    5. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
    6. metadata-evalN/A

      \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
    7. lower--.f64N/A

      \[\leadsto \frac{\color{blue}{1 - \cos x \cdot \cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
    8. lift-cos.f64N/A

      \[\leadsto \frac{1 - \color{blue}{\cos x} \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
    9. lift-cos.f64N/A

      \[\leadsto \frac{1 - \cos x \cdot \color{blue}{\cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
    10. sqr-cos-aN/A

      \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
    11. lower-+.f64N/A

      \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
    12. lower-*.f64N/A

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

      \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \color{blue}{\cos \left(2 \cdot x\right)}\right)}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
    14. lower-*.f64N/A

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

      \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
    16. +-commutativeN/A

      \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
    17. lower-+.f6450.1

      \[\leadsto \frac{1 - \left(0.5 + 0.5 \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
  3. Applied rewrites50.1%

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

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

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

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

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

      \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \color{blue}{\left(2 \cdot x\right)}\right)}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
    6. sqr-cos-a-revN/A

      \[\leadsto \frac{1 - \color{blue}{\cos x \cdot \cos x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
    7. 1-sub-cosN/A

      \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
    8. pow2N/A

      \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
    9. lower-pow.f64N/A

      \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
    10. lower-sin.f6475.3

      \[\leadsto \frac{{\color{blue}{\sin x}}^{2}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
  5. Applied rewrites75.3%

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

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

      \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
    3. unpow2N/A

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

      \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)}} \]
    5. lift-*.f64N/A

      \[\leadsto \frac{\sin x \cdot \sin x}{\left(\cos x + 1\right) \cdot \color{blue}{\left(x \cdot x\right)}} \]
    6. associate-*r*N/A

      \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\left(\cos x + 1\right) \cdot x\right) \cdot x}} \]
    7. times-fracN/A

      \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
    8. lower-*.f64N/A

      \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
    9. lift-+.f64N/A

      \[\leadsto \frac{\sin x}{\color{blue}{\left(\cos x + 1\right)} \cdot x} \cdot \frac{\sin x}{x} \]
    10. distribute-rgt1-inN/A

      \[\leadsto \frac{\sin x}{\color{blue}{x + \cos x \cdot x}} \cdot \frac{\sin x}{x} \]
    11. *-lft-identityN/A

      \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
    12. lift-*.f64N/A

      \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
    13. *-commutativeN/A

      \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
    14. lift-*.f64N/A

      \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
    15. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{\sin x}{1 \cdot x + x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
    16. lift-*.f64N/A

      \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
    17. *-lft-identityN/A

      \[\leadsto \frac{\sin x}{\color{blue}{x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
    18. +-commutativeN/A

      \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x + x}} \cdot \frac{\sin x}{x} \]
    19. lift-*.f64N/A

      \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x} + x} \cdot \frac{\sin x}{x} \]
    20. *-commutativeN/A

      \[\leadsto \frac{\sin x}{\color{blue}{\cos x \cdot x} + x} \cdot \frac{\sin x}{x} \]
    21. lower-fma.f64N/A

      \[\leadsto \frac{\sin x}{\color{blue}{\mathsf{fma}\left(\cos x, x, x\right)}} \cdot \frac{\sin x}{x} \]
    22. lower-/.f6499.5

      \[\leadsto \frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \color{blue}{\frac{\sin x}{x}} \]
  7. Applied rewrites99.5%

    \[\leadsto \color{blue}{\frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \frac{\sin x}{x}} \]
  8. Add Preprocessing

Alternative 2: 75.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.034:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.034)
   (fma (fma 0.001388888888888889 (* x x) -0.041666666666666664) (* x x) 0.5)
   (/ (/ (- 1.0 (cos x)) x) x)))
double code(double x) {
	double tmp;
	if (x <= 0.034) {
		tmp = fma(fma(0.001388888888888889, (x * x), -0.041666666666666664), (x * x), 0.5);
	} else {
		tmp = ((1.0 - cos(x)) / x) / x;
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= 0.034)
		tmp = fma(fma(0.001388888888888889, Float64(x * x), -0.041666666666666664), Float64(x * x), 0.5);
	else
		tmp = Float64(Float64(Float64(1.0 - cos(x)) / x) / x);
	end
	return tmp
end
code[x_] := If[LessEqual[x, 0.034], N[(N[(0.001388888888888889 * N[(x * x), $MachinePrecision] + -0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.034:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 0.034000000000000002

    1. Initial program 50.4%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Step-by-step derivation
      1. lift-/.f64N/A

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

        \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
      3. flip--N/A

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
      4. associate-/l/N/A

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
      5. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
      6. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      7. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{1 - \cos x \cdot \cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      8. lift-cos.f64N/A

        \[\leadsto \frac{1 - \color{blue}{\cos x} \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      9. lift-cos.f64N/A

        \[\leadsto \frac{1 - \cos x \cdot \color{blue}{\cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      10. sqr-cos-aN/A

        \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      11. lower-+.f64N/A

        \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      12. lower-*.f64N/A

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

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \color{blue}{\cos \left(2 \cdot x\right)}\right)}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      14. lower-*.f64N/A

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

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
      16. +-commutativeN/A

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
      17. lower-+.f6450.1

        \[\leadsto \frac{1 - \left(0.5 + 0.5 \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
    3. Applied rewrites50.1%

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

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

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

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

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

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \color{blue}{\left(2 \cdot x\right)}\right)}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      6. sqr-cos-a-revN/A

        \[\leadsto \frac{1 - \color{blue}{\cos x \cdot \cos x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      7. 1-sub-cosN/A

        \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      8. pow2N/A

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      9. lower-pow.f64N/A

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      10. lower-sin.f6475.3

        \[\leadsto \frac{{\color{blue}{\sin x}}^{2}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
    5. Applied rewrites75.3%

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

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

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      3. unpow2N/A

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

        \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)}} \]
      5. lift-*.f64N/A

        \[\leadsto \frac{\sin x \cdot \sin x}{\left(\cos x + 1\right) \cdot \color{blue}{\left(x \cdot x\right)}} \]
      6. associate-*r*N/A

        \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\left(\cos x + 1\right) \cdot x\right) \cdot x}} \]
      7. times-fracN/A

        \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
      8. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
      9. lift-+.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{\left(\cos x + 1\right)} \cdot x} \cdot \frac{\sin x}{x} \]
      10. distribute-rgt1-inN/A

        \[\leadsto \frac{\sin x}{\color{blue}{x + \cos x \cdot x}} \cdot \frac{\sin x}{x} \]
      11. *-lft-identityN/A

        \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
      12. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
      13. *-commutativeN/A

        \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
      14. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
      15. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{1 \cdot x + x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
      16. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
      17. *-lft-identityN/A

        \[\leadsto \frac{\sin x}{\color{blue}{x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
      18. +-commutativeN/A

        \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x + x}} \cdot \frac{\sin x}{x} \]
      19. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x} + x} \cdot \frac{\sin x}{x} \]
      20. *-commutativeN/A

        \[\leadsto \frac{\sin x}{\color{blue}{\cos x \cdot x} + x} \cdot \frac{\sin x}{x} \]
      21. lower-fma.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{\mathsf{fma}\left(\cos x, x, x\right)}} \cdot \frac{\sin x}{x} \]
      22. lower-/.f6499.5

        \[\leadsto \frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \color{blue}{\frac{\sin x}{x}} \]
    7. Applied rewrites99.5%

      \[\leadsto \color{blue}{\frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \frac{\sin x}{x}} \]
    8. Taylor expanded in x around 0

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

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

        \[\leadsto \left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right) \cdot {x}^{2} + \frac{1}{2} \]
      3. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}, \color{blue}{{x}^{2}}, \frac{1}{2}\right) \]
      4. sub-flipN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{720} \cdot {x}^{2} + \left(\mathsf{neg}\left(\frac{1}{24}\right)\right), {\color{blue}{x}}^{2}, \frac{1}{2}\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{720} \cdot {x}^{2} + \frac{-1}{24}, {x}^{2}, \frac{1}{2}\right) \]
      6. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, {x}^{2}, \frac{-1}{24}\right), {\color{blue}{x}}^{2}, \frac{1}{2}\right) \]
      7. pow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{-1}{24}\right), {x}^{2}, \frac{1}{2}\right) \]
      8. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{-1}{24}\right), {x}^{2}, \frac{1}{2}\right) \]
      9. pow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{-1}{24}\right), x \cdot \color{blue}{x}, \frac{1}{2}\right) \]
      10. lift-*.f6451.4

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot \color{blue}{x}, 0.5\right) \]
    10. Applied rewrites51.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)} \]

    if 0.034000000000000002 < x

    1. Initial program 50.4%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Step-by-step derivation
      1. lift-/.f64N/A

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

        \[\leadsto \frac{1 - \cos x}{\color{blue}{x \cdot x}} \]
      3. associate-/r*N/A

        \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
      4. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
      5. lower-/.f6451.5

        \[\leadsto \frac{\color{blue}{\frac{1 - \cos x}{x}}}{x} \]
    3. Applied rewrites51.5%

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

Alternative 3: 75.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.034:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \cos x}{x \cdot x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.034)
   (fma (fma 0.001388888888888889 (* x x) -0.041666666666666664) (* x x) 0.5)
   (/ (- 1.0 (cos x)) (* x x))))
double code(double x) {
	double tmp;
	if (x <= 0.034) {
		tmp = fma(fma(0.001388888888888889, (x * x), -0.041666666666666664), (x * x), 0.5);
	} else {
		tmp = (1.0 - cos(x)) / (x * x);
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= 0.034)
		tmp = fma(fma(0.001388888888888889, Float64(x * x), -0.041666666666666664), Float64(x * x), 0.5);
	else
		tmp = Float64(Float64(1.0 - cos(x)) / Float64(x * x));
	end
	return tmp
end
code[x_] := If[LessEqual[x, 0.034], N[(N[(0.001388888888888889 * N[(x * x), $MachinePrecision] + -0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.034:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1 - \cos x}{x \cdot x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 0.034000000000000002

    1. Initial program 50.4%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Step-by-step derivation
      1. lift-/.f64N/A

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

        \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
      3. flip--N/A

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
      4. associate-/l/N/A

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
      5. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
      6. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      7. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{1 - \cos x \cdot \cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      8. lift-cos.f64N/A

        \[\leadsto \frac{1 - \color{blue}{\cos x} \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      9. lift-cos.f64N/A

        \[\leadsto \frac{1 - \cos x \cdot \color{blue}{\cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      10. sqr-cos-aN/A

        \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      11. lower-+.f64N/A

        \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      12. lower-*.f64N/A

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

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \color{blue}{\cos \left(2 \cdot x\right)}\right)}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      14. lower-*.f64N/A

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

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
      16. +-commutativeN/A

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
      17. lower-+.f6450.1

        \[\leadsto \frac{1 - \left(0.5 + 0.5 \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
    3. Applied rewrites50.1%

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

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

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

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

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

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \color{blue}{\left(2 \cdot x\right)}\right)}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      6. sqr-cos-a-revN/A

        \[\leadsto \frac{1 - \color{blue}{\cos x \cdot \cos x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      7. 1-sub-cosN/A

        \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      8. pow2N/A

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      9. lower-pow.f64N/A

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      10. lower-sin.f6475.3

        \[\leadsto \frac{{\color{blue}{\sin x}}^{2}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
    5. Applied rewrites75.3%

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

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

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      3. unpow2N/A

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

        \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)}} \]
      5. lift-*.f64N/A

        \[\leadsto \frac{\sin x \cdot \sin x}{\left(\cos x + 1\right) \cdot \color{blue}{\left(x \cdot x\right)}} \]
      6. associate-*r*N/A

        \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\left(\cos x + 1\right) \cdot x\right) \cdot x}} \]
      7. times-fracN/A

        \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
      8. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
      9. lift-+.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{\left(\cos x + 1\right)} \cdot x} \cdot \frac{\sin x}{x} \]
      10. distribute-rgt1-inN/A

        \[\leadsto \frac{\sin x}{\color{blue}{x + \cos x \cdot x}} \cdot \frac{\sin x}{x} \]
      11. *-lft-identityN/A

        \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
      12. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
      13. *-commutativeN/A

        \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
      14. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
      15. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{1 \cdot x + x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
      16. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
      17. *-lft-identityN/A

        \[\leadsto \frac{\sin x}{\color{blue}{x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
      18. +-commutativeN/A

        \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x + x}} \cdot \frac{\sin x}{x} \]
      19. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x} + x} \cdot \frac{\sin x}{x} \]
      20. *-commutativeN/A

        \[\leadsto \frac{\sin x}{\color{blue}{\cos x \cdot x} + x} \cdot \frac{\sin x}{x} \]
      21. lower-fma.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{\mathsf{fma}\left(\cos x, x, x\right)}} \cdot \frac{\sin x}{x} \]
      22. lower-/.f6499.5

        \[\leadsto \frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \color{blue}{\frac{\sin x}{x}} \]
    7. Applied rewrites99.5%

      \[\leadsto \color{blue}{\frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \frac{\sin x}{x}} \]
    8. Taylor expanded in x around 0

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

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

        \[\leadsto \left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right) \cdot {x}^{2} + \frac{1}{2} \]
      3. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}, \color{blue}{{x}^{2}}, \frac{1}{2}\right) \]
      4. sub-flipN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{720} \cdot {x}^{2} + \left(\mathsf{neg}\left(\frac{1}{24}\right)\right), {\color{blue}{x}}^{2}, \frac{1}{2}\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{720} \cdot {x}^{2} + \frac{-1}{24}, {x}^{2}, \frac{1}{2}\right) \]
      6. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, {x}^{2}, \frac{-1}{24}\right), {\color{blue}{x}}^{2}, \frac{1}{2}\right) \]
      7. pow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{-1}{24}\right), {x}^{2}, \frac{1}{2}\right) \]
      8. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{-1}{24}\right), {x}^{2}, \frac{1}{2}\right) \]
      9. pow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{-1}{24}\right), x \cdot \color{blue}{x}, \frac{1}{2}\right) \]
      10. lift-*.f6451.4

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot \color{blue}{x}, 0.5\right) \]
    10. Applied rewrites51.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)} \]

    if 0.034000000000000002 < x

    1. Initial program 50.4%

      \[\frac{1 - \cos x}{x \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 65.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\frac{1}{x}}\\ \mathbf{if}\;x \leq 3.9:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_0 \cdot t\_0}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (/ 1.0 x))))
   (if (<= x 3.9)
     (fma (fma 0.001388888888888889 (* x x) -0.041666666666666664) (* x x) 0.5)
     (/ (* t_0 t_0) x))))
double code(double x) {
	double t_0 = sqrt((1.0 / x));
	double tmp;
	if (x <= 3.9) {
		tmp = fma(fma(0.001388888888888889, (x * x), -0.041666666666666664), (x * x), 0.5);
	} else {
		tmp = (t_0 * t_0) / x;
	}
	return tmp;
}
function code(x)
	t_0 = sqrt(Float64(1.0 / x))
	tmp = 0.0
	if (x <= 3.9)
		tmp = fma(fma(0.001388888888888889, Float64(x * x), -0.041666666666666664), Float64(x * x), 0.5);
	else
		tmp = Float64(Float64(t_0 * t_0) / x);
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 3.9], N[(N[(0.001388888888888889 * N[(x * x), $MachinePrecision] + -0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(t$95$0 * t$95$0), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{\frac{1}{x}}\\
\mathbf{if}\;x \leq 3.9:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{t\_0 \cdot t\_0}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3.89999999999999991

    1. Initial program 50.4%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Step-by-step derivation
      1. lift-/.f64N/A

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

        \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
      3. flip--N/A

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
      4. associate-/l/N/A

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
      5. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
      6. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      7. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{1 - \cos x \cdot \cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      8. lift-cos.f64N/A

        \[\leadsto \frac{1 - \color{blue}{\cos x} \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      9. lift-cos.f64N/A

        \[\leadsto \frac{1 - \cos x \cdot \color{blue}{\cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      10. sqr-cos-aN/A

        \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      11. lower-+.f64N/A

        \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      12. lower-*.f64N/A

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

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \color{blue}{\cos \left(2 \cdot x\right)}\right)}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      14. lower-*.f64N/A

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

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
      16. +-commutativeN/A

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
      17. lower-+.f6450.1

        \[\leadsto \frac{1 - \left(0.5 + 0.5 \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
    3. Applied rewrites50.1%

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

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

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

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

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

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \color{blue}{\left(2 \cdot x\right)}\right)}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      6. sqr-cos-a-revN/A

        \[\leadsto \frac{1 - \color{blue}{\cos x \cdot \cos x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      7. 1-sub-cosN/A

        \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      8. pow2N/A

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      9. lower-pow.f64N/A

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      10. lower-sin.f6475.3

        \[\leadsto \frac{{\color{blue}{\sin x}}^{2}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
    5. Applied rewrites75.3%

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

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

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      3. unpow2N/A

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

        \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)}} \]
      5. lift-*.f64N/A

        \[\leadsto \frac{\sin x \cdot \sin x}{\left(\cos x + 1\right) \cdot \color{blue}{\left(x \cdot x\right)}} \]
      6. associate-*r*N/A

        \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\left(\cos x + 1\right) \cdot x\right) \cdot x}} \]
      7. times-fracN/A

        \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
      8. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
      9. lift-+.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{\left(\cos x + 1\right)} \cdot x} \cdot \frac{\sin x}{x} \]
      10. distribute-rgt1-inN/A

        \[\leadsto \frac{\sin x}{\color{blue}{x + \cos x \cdot x}} \cdot \frac{\sin x}{x} \]
      11. *-lft-identityN/A

        \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
      12. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
      13. *-commutativeN/A

        \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
      14. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
      15. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{1 \cdot x + x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
      16. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
      17. *-lft-identityN/A

        \[\leadsto \frac{\sin x}{\color{blue}{x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
      18. +-commutativeN/A

        \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x + x}} \cdot \frac{\sin x}{x} \]
      19. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x} + x} \cdot \frac{\sin x}{x} \]
      20. *-commutativeN/A

        \[\leadsto \frac{\sin x}{\color{blue}{\cos x \cdot x} + x} \cdot \frac{\sin x}{x} \]
      21. lower-fma.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{\mathsf{fma}\left(\cos x, x, x\right)}} \cdot \frac{\sin x}{x} \]
      22. lower-/.f6499.5

        \[\leadsto \frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \color{blue}{\frac{\sin x}{x}} \]
    7. Applied rewrites99.5%

      \[\leadsto \color{blue}{\frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \frac{\sin x}{x}} \]
    8. Taylor expanded in x around 0

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

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

        \[\leadsto \left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right) \cdot {x}^{2} + \frac{1}{2} \]
      3. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}, \color{blue}{{x}^{2}}, \frac{1}{2}\right) \]
      4. sub-flipN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{720} \cdot {x}^{2} + \left(\mathsf{neg}\left(\frac{1}{24}\right)\right), {\color{blue}{x}}^{2}, \frac{1}{2}\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{720} \cdot {x}^{2} + \frac{-1}{24}, {x}^{2}, \frac{1}{2}\right) \]
      6. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, {x}^{2}, \frac{-1}{24}\right), {\color{blue}{x}}^{2}, \frac{1}{2}\right) \]
      7. pow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{-1}{24}\right), {x}^{2}, \frac{1}{2}\right) \]
      8. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{-1}{24}\right), {x}^{2}, \frac{1}{2}\right) \]
      9. pow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{-1}{24}\right), x \cdot \color{blue}{x}, \frac{1}{2}\right) \]
      10. lift-*.f6451.4

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot \color{blue}{x}, 0.5\right) \]
    10. Applied rewrites51.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)} \]

    if 3.89999999999999991 < x

    1. Initial program 50.4%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Step-by-step derivation
      1. lift-/.f64N/A

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

        \[\leadsto \frac{1 - \cos x}{\color{blue}{x \cdot x}} \]
      3. associate-/r*N/A

        \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
      4. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
      5. lower-/.f6451.5

        \[\leadsto \frac{\color{blue}{\frac{1 - \cos x}{x}}}{x} \]
    3. Applied rewrites51.5%

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
    4. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{1 - \cos x}{x}}}{x} \]
      2. lift--.f64N/A

        \[\leadsto \frac{\frac{\color{blue}{1 - \cos x}}{x}}{x} \]
      3. sub-flipN/A

        \[\leadsto \frac{\frac{\color{blue}{1 + \left(\mathsf{neg}\left(\cos x\right)\right)}}{x}}{x} \]
      4. lift-neg.f64N/A

        \[\leadsto \frac{\frac{1 + \color{blue}{\left(-\cos x\right)}}{x}}{x} \]
      5. div-addN/A

        \[\leadsto \frac{\color{blue}{\frac{1}{x} + \frac{-\cos x}{x}}}{x} \]
      6. inv-powN/A

        \[\leadsto \frac{\color{blue}{{x}^{-1}} + \frac{-\cos x}{x}}{x} \]
      7. sqr-powN/A

        \[\leadsto \frac{\color{blue}{{x}^{\left(\frac{-1}{2}\right)} \cdot {x}^{\left(\frac{-1}{2}\right)}} + \frac{-\cos x}{x}}{x} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({x}^{\left(\frac{-1}{2}\right)}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}}{x} \]
      9. metadata-evalN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\color{blue}{\frac{-1}{2}}}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}{x} \]
      10. metadata-evalN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}{x} \]
      11. lower-pow.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{{x}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}{x} \]
      12. metadata-evalN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\color{blue}{\frac{-1}{2}}}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}{x} \]
      13. metadata-evalN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\color{blue}{\frac{-1}{2}}}, \frac{-\cos x}{x}\right)}{x} \]
      14. metadata-evalN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}, \frac{-\cos x}{x}\right)}{x} \]
      15. lower-pow.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, \color{blue}{{x}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}, \frac{-\cos x}{x}\right)}{x} \]
      16. metadata-evalN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\color{blue}{\frac{-1}{2}}}, \frac{-\cos x}{x}\right)}{x} \]
      17. frac-2negN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \color{blue}{\frac{\mathsf{neg}\left(\left(-\cos x\right)\right)}{\mathsf{neg}\left(x\right)}}\right)}{x} \]
      18. lift-neg.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \frac{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\cos x\right)\right)}\right)}{\mathsf{neg}\left(x\right)}\right)}{x} \]
      19. remove-double-negN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \frac{\color{blue}{\cos x}}{\mathsf{neg}\left(x\right)}\right)}{x} \]
      20. lower-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \color{blue}{\frac{\cos x}{\mathsf{neg}\left(x\right)}}\right)}{x} \]
      21. lower-neg.f6425.4

        \[\leadsto \frac{\mathsf{fma}\left({x}^{-0.5}, {x}^{-0.5}, \frac{\cos x}{\color{blue}{-x}}\right)}{x} \]
    5. Applied rewrites25.4%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({x}^{-0.5}, {x}^{-0.5}, \frac{\cos x}{-x}\right)}}{x} \]
    6. Taylor expanded in x around inf

      \[\leadsto \frac{\color{blue}{{\left({\left(\frac{1}{x}\right)}^{\frac{1}{2}}\right)}^{2}}}{x} \]
    7. Step-by-step derivation
      1. unpow2N/A

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

        \[\leadsto \frac{{\left(\frac{1}{x}\right)}^{\frac{1}{2}} \cdot \color{blue}{{\left(\frac{1}{x}\right)}^{\frac{1}{2}}}}{x} \]
      3. inv-powN/A

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

        \[\leadsto \frac{{\left({x}^{\left(\frac{-1}{2} + \frac{-1}{2}\right)}\right)}^{\frac{1}{2}} \cdot {\left(\frac{1}{x}\right)}^{\frac{1}{2}}}{x} \]
      5. pow-prod-upN/A

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

        \[\leadsto \frac{{\left({\left({x}^{\frac{-1}{2}}\right)}^{2}\right)}^{\frac{1}{2}} \cdot {\left(\frac{\color{blue}{1}}{x}\right)}^{\frac{1}{2}}}{x} \]
      7. unpow1/2N/A

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

        \[\leadsto \frac{\sqrt{{\left({x}^{\frac{-1}{2}}\right)}^{2}} \cdot {\color{blue}{\left(\frac{1}{x}\right)}}^{\frac{1}{2}}}{x} \]
      9. pow2N/A

        \[\leadsto \frac{\sqrt{{x}^{\frac{-1}{2}} \cdot {x}^{\frac{-1}{2}}} \cdot {\left(\frac{\color{blue}{1}}{x}\right)}^{\frac{1}{2}}}{x} \]
      10. pow-prod-upN/A

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

        \[\leadsto \frac{\sqrt{{x}^{-1}} \cdot {\left(\frac{1}{x}\right)}^{\frac{1}{2}}}{x} \]
      12. inv-powN/A

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

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot {\left(\frac{\color{blue}{1}}{x}\right)}^{\frac{1}{2}}}{x} \]
      14. inv-powN/A

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

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot {\left({x}^{\left(\frac{-1}{2} + \frac{-1}{2}\right)}\right)}^{\frac{1}{2}}}{x} \]
      16. pow-prod-upN/A

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

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot {\left({\left({x}^{\frac{-1}{2}}\right)}^{2}\right)}^{\frac{1}{2}}}{x} \]
      18. unpow1/2N/A

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

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

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot \sqrt{{x}^{\frac{-1}{2}} \cdot {x}^{\frac{-1}{2}}}}{x} \]
      21. pow-prod-upN/A

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot \sqrt{{x}^{\left(\frac{-1}{2} + \frac{-1}{2}\right)}}}{x} \]
      22. metadata-evalN/A

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot \sqrt{{x}^{-1}}}{x} \]
      23. inv-powN/A

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot \sqrt{\frac{1}{x}}}{x} \]
      24. lower-/.f6415.6

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot \sqrt{\frac{1}{x}}}{x} \]
    8. Applied rewrites15.6%

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

Alternative 5: 64.2% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 72000000:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{1}{x}, x, -1\right)}{x \cdot x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 72000000.0)
   (fma (fma 0.001388888888888889 (* x x) -0.041666666666666664) (* x x) 0.5)
   (/ (fma (/ 1.0 x) x -1.0) (* x x))))
double code(double x) {
	double tmp;
	if (x <= 72000000.0) {
		tmp = fma(fma(0.001388888888888889, (x * x), -0.041666666666666664), (x * x), 0.5);
	} else {
		tmp = fma((1.0 / x), x, -1.0) / (x * x);
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= 72000000.0)
		tmp = fma(fma(0.001388888888888889, Float64(x * x), -0.041666666666666664), Float64(x * x), 0.5);
	else
		tmp = Float64(fma(Float64(1.0 / x), x, -1.0) / Float64(x * x));
	end
	return tmp
end
code[x_] := If[LessEqual[x, 72000000.0], N[(N[(0.001388888888888889 * N[(x * x), $MachinePrecision] + -0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision], N[(N[(N[(1.0 / x), $MachinePrecision] * x + -1.0), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 72000000:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{1}{x}, x, -1\right)}{x \cdot x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 7.2e7

    1. Initial program 50.4%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Step-by-step derivation
      1. lift-/.f64N/A

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

        \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
      3. flip--N/A

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
      4. associate-/l/N/A

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
      5. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
      6. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      7. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{1 - \cos x \cdot \cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      8. lift-cos.f64N/A

        \[\leadsto \frac{1 - \color{blue}{\cos x} \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      9. lift-cos.f64N/A

        \[\leadsto \frac{1 - \cos x \cdot \color{blue}{\cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      10. sqr-cos-aN/A

        \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      11. lower-+.f64N/A

        \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      12. lower-*.f64N/A

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

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \color{blue}{\cos \left(2 \cdot x\right)}\right)}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
      14. lower-*.f64N/A

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

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
      16. +-commutativeN/A

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
      17. lower-+.f6450.1

        \[\leadsto \frac{1 - \left(0.5 + 0.5 \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
    3. Applied rewrites50.1%

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

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

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

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

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

        \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \color{blue}{\left(2 \cdot x\right)}\right)}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      6. sqr-cos-a-revN/A

        \[\leadsto \frac{1 - \color{blue}{\cos x \cdot \cos x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      7. 1-sub-cosN/A

        \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      8. pow2N/A

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      9. lower-pow.f64N/A

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      10. lower-sin.f6475.3

        \[\leadsto \frac{{\color{blue}{\sin x}}^{2}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
    5. Applied rewrites75.3%

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

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

        \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      3. unpow2N/A

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

        \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)}} \]
      5. lift-*.f64N/A

        \[\leadsto \frac{\sin x \cdot \sin x}{\left(\cos x + 1\right) \cdot \color{blue}{\left(x \cdot x\right)}} \]
      6. associate-*r*N/A

        \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\left(\cos x + 1\right) \cdot x\right) \cdot x}} \]
      7. times-fracN/A

        \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
      8. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
      9. lift-+.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{\left(\cos x + 1\right)} \cdot x} \cdot \frac{\sin x}{x} \]
      10. distribute-rgt1-inN/A

        \[\leadsto \frac{\sin x}{\color{blue}{x + \cos x \cdot x}} \cdot \frac{\sin x}{x} \]
      11. *-lft-identityN/A

        \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
      12. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
      13. *-commutativeN/A

        \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
      14. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
      15. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin x}{1 \cdot x + x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
      16. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
      17. *-lft-identityN/A

        \[\leadsto \frac{\sin x}{\color{blue}{x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
      18. +-commutativeN/A

        \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x + x}} \cdot \frac{\sin x}{x} \]
      19. lift-*.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x} + x} \cdot \frac{\sin x}{x} \]
      20. *-commutativeN/A

        \[\leadsto \frac{\sin x}{\color{blue}{\cos x \cdot x} + x} \cdot \frac{\sin x}{x} \]
      21. lower-fma.f64N/A

        \[\leadsto \frac{\sin x}{\color{blue}{\mathsf{fma}\left(\cos x, x, x\right)}} \cdot \frac{\sin x}{x} \]
      22. lower-/.f6499.5

        \[\leadsto \frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \color{blue}{\frac{\sin x}{x}} \]
    7. Applied rewrites99.5%

      \[\leadsto \color{blue}{\frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \frac{\sin x}{x}} \]
    8. Taylor expanded in x around 0

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

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

        \[\leadsto \left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right) \cdot {x}^{2} + \frac{1}{2} \]
      3. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}, \color{blue}{{x}^{2}}, \frac{1}{2}\right) \]
      4. sub-flipN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{720} \cdot {x}^{2} + \left(\mathsf{neg}\left(\frac{1}{24}\right)\right), {\color{blue}{x}}^{2}, \frac{1}{2}\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{720} \cdot {x}^{2} + \frac{-1}{24}, {x}^{2}, \frac{1}{2}\right) \]
      6. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, {x}^{2}, \frac{-1}{24}\right), {\color{blue}{x}}^{2}, \frac{1}{2}\right) \]
      7. pow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{-1}{24}\right), {x}^{2}, \frac{1}{2}\right) \]
      8. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{-1}{24}\right), {x}^{2}, \frac{1}{2}\right) \]
      9. pow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{-1}{24}\right), x \cdot \color{blue}{x}, \frac{1}{2}\right) \]
      10. lift-*.f6451.4

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot \color{blue}{x}, 0.5\right) \]
    10. Applied rewrites51.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, -0.041666666666666664\right), x \cdot x, 0.5\right)} \]

    if 7.2e7 < x

    1. Initial program 50.4%

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Step-by-step derivation
      1. lift-/.f64N/A

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

        \[\leadsto \frac{1 - \cos x}{\color{blue}{x \cdot x}} \]
      3. associate-/r*N/A

        \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
      4. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
      5. lower-/.f6451.5

        \[\leadsto \frac{\color{blue}{\frac{1 - \cos x}{x}}}{x} \]
    3. Applied rewrites51.5%

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
    4. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{1 - \cos x}{x}}}{x} \]
      2. lift--.f64N/A

        \[\leadsto \frac{\frac{\color{blue}{1 - \cos x}}{x}}{x} \]
      3. sub-flipN/A

        \[\leadsto \frac{\frac{\color{blue}{1 + \left(\mathsf{neg}\left(\cos x\right)\right)}}{x}}{x} \]
      4. lift-neg.f64N/A

        \[\leadsto \frac{\frac{1 + \color{blue}{\left(-\cos x\right)}}{x}}{x} \]
      5. div-addN/A

        \[\leadsto \frac{\color{blue}{\frac{1}{x} + \frac{-\cos x}{x}}}{x} \]
      6. inv-powN/A

        \[\leadsto \frac{\color{blue}{{x}^{-1}} + \frac{-\cos x}{x}}{x} \]
      7. sqr-powN/A

        \[\leadsto \frac{\color{blue}{{x}^{\left(\frac{-1}{2}\right)} \cdot {x}^{\left(\frac{-1}{2}\right)}} + \frac{-\cos x}{x}}{x} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({x}^{\left(\frac{-1}{2}\right)}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}}{x} \]
      9. metadata-evalN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\color{blue}{\frac{-1}{2}}}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}{x} \]
      10. metadata-evalN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}{x} \]
      11. lower-pow.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{{x}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}{x} \]
      12. metadata-evalN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\color{blue}{\frac{-1}{2}}}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}{x} \]
      13. metadata-evalN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\color{blue}{\frac{-1}{2}}}, \frac{-\cos x}{x}\right)}{x} \]
      14. metadata-evalN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}, \frac{-\cos x}{x}\right)}{x} \]
      15. lower-pow.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, \color{blue}{{x}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}, \frac{-\cos x}{x}\right)}{x} \]
      16. metadata-evalN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\color{blue}{\frac{-1}{2}}}, \frac{-\cos x}{x}\right)}{x} \]
      17. frac-2negN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \color{blue}{\frac{\mathsf{neg}\left(\left(-\cos x\right)\right)}{\mathsf{neg}\left(x\right)}}\right)}{x} \]
      18. lift-neg.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \frac{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\cos x\right)\right)}\right)}{\mathsf{neg}\left(x\right)}\right)}{x} \]
      19. remove-double-negN/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \frac{\color{blue}{\cos x}}{\mathsf{neg}\left(x\right)}\right)}{x} \]
      20. lower-/.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \color{blue}{\frac{\cos x}{\mathsf{neg}\left(x\right)}}\right)}{x} \]
      21. lower-neg.f6425.4

        \[\leadsto \frac{\mathsf{fma}\left({x}^{-0.5}, {x}^{-0.5}, \frac{\cos x}{\color{blue}{-x}}\right)}{x} \]
    5. Applied rewrites25.4%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({x}^{-0.5}, {x}^{-0.5}, \frac{\cos x}{-x}\right)}}{x} \]
    6. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{x \cdot {\left({x}^{\frac{-1}{2}}\right)}^{2} - 1}{{x}^{2}}} \]
    7. Step-by-step derivation
      1. Applied rewrites27.6%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{1}{x}, x, -1\right)}{x \cdot x}} \]
    8. Recombined 2 regimes into one program.
    9. Add Preprocessing

    Alternative 6: 64.1% accurate, 2.2× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1.65 \cdot 10^{+35}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{1}{x}, x, -1\right)}{x \cdot x}\\ \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (if (<= x 1.65e+35) 0.5 (/ (fma (/ 1.0 x) x -1.0) (* x x))))
    double code(double x) {
    	double tmp;
    	if (x <= 1.65e+35) {
    		tmp = 0.5;
    	} else {
    		tmp = fma((1.0 / x), x, -1.0) / (x * x);
    	}
    	return tmp;
    }
    
    function code(x)
    	tmp = 0.0
    	if (x <= 1.65e+35)
    		tmp = 0.5;
    	else
    		tmp = Float64(fma(Float64(1.0 / x), x, -1.0) / Float64(x * x));
    	end
    	return tmp
    end
    
    code[x_] := If[LessEqual[x, 1.65e+35], 0.5, N[(N[(N[(1.0 / x), $MachinePrecision] * x + -1.0), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq 1.65 \cdot 10^{+35}:\\
    \;\;\;\;0.5\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{\mathsf{fma}\left(\frac{1}{x}, x, -1\right)}{x \cdot x}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 1.6500000000000001e35

      1. Initial program 50.4%

        \[\frac{1 - \cos x}{x \cdot x} \]
      2. Step-by-step derivation
        1. lift-/.f64N/A

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

          \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
        3. flip--N/A

          \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
        4. associate-/l/N/A

          \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
        5. lower-/.f64N/A

          \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
        6. metadata-evalN/A

          \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
        7. lower--.f64N/A

          \[\leadsto \frac{\color{blue}{1 - \cos x \cdot \cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
        8. lift-cos.f64N/A

          \[\leadsto \frac{1 - \color{blue}{\cos x} \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
        9. lift-cos.f64N/A

          \[\leadsto \frac{1 - \cos x \cdot \color{blue}{\cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
        10. sqr-cos-aN/A

          \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
        11. lower-+.f64N/A

          \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
        12. lower-*.f64N/A

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

          \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \color{blue}{\cos \left(2 \cdot x\right)}\right)}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
        14. lower-*.f64N/A

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

          \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
        16. +-commutativeN/A

          \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
        17. lower-+.f6450.1

          \[\leadsto \frac{1 - \left(0.5 + 0.5 \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
      3. Applied rewrites50.1%

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

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

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

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

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

          \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \color{blue}{\left(2 \cdot x\right)}\right)}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
        6. sqr-cos-a-revN/A

          \[\leadsto \frac{1 - \color{blue}{\cos x \cdot \cos x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
        7. 1-sub-cosN/A

          \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
        8. pow2N/A

          \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
        9. lower-pow.f64N/A

          \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
        10. lower-sin.f6475.3

          \[\leadsto \frac{{\color{blue}{\sin x}}^{2}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
      5. Applied rewrites75.3%

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

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

          \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
        3. unpow2N/A

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

          \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)}} \]
        5. lift-*.f64N/A

          \[\leadsto \frac{\sin x \cdot \sin x}{\left(\cos x + 1\right) \cdot \color{blue}{\left(x \cdot x\right)}} \]
        6. associate-*r*N/A

          \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\left(\cos x + 1\right) \cdot x\right) \cdot x}} \]
        7. times-fracN/A

          \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
        8. lower-*.f64N/A

          \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
        9. lift-+.f64N/A

          \[\leadsto \frac{\sin x}{\color{blue}{\left(\cos x + 1\right)} \cdot x} \cdot \frac{\sin x}{x} \]
        10. distribute-rgt1-inN/A

          \[\leadsto \frac{\sin x}{\color{blue}{x + \cos x \cdot x}} \cdot \frac{\sin x}{x} \]
        11. *-lft-identityN/A

          \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
        12. lift-*.f64N/A

          \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
        13. *-commutativeN/A

          \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
        14. lift-*.f64N/A

          \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
        15. lower-/.f64N/A

          \[\leadsto \color{blue}{\frac{\sin x}{1 \cdot x + x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
        16. lift-*.f64N/A

          \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
        17. *-lft-identityN/A

          \[\leadsto \frac{\sin x}{\color{blue}{x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
        18. +-commutativeN/A

          \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x + x}} \cdot \frac{\sin x}{x} \]
        19. lift-*.f64N/A

          \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x} + x} \cdot \frac{\sin x}{x} \]
        20. *-commutativeN/A

          \[\leadsto \frac{\sin x}{\color{blue}{\cos x \cdot x} + x} \cdot \frac{\sin x}{x} \]
        21. lower-fma.f64N/A

          \[\leadsto \frac{\sin x}{\color{blue}{\mathsf{fma}\left(\cos x, x, x\right)}} \cdot \frac{\sin x}{x} \]
        22. lower-/.f6499.5

          \[\leadsto \frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \color{blue}{\frac{\sin x}{x}} \]
      7. Applied rewrites99.5%

        \[\leadsto \color{blue}{\frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \frac{\sin x}{x}} \]
      8. Taylor expanded in x around 0

        \[\leadsto \color{blue}{\frac{1}{2}} \]
      9. Step-by-step derivation
        1. Applied rewrites52.0%

          \[\leadsto \color{blue}{0.5} \]

        if 1.6500000000000001e35 < x

        1. Initial program 50.4%

          \[\frac{1 - \cos x}{x \cdot x} \]
        2. Step-by-step derivation
          1. lift-/.f64N/A

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

            \[\leadsto \frac{1 - \cos x}{\color{blue}{x \cdot x}} \]
          3. associate-/r*N/A

            \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
          4. lower-/.f64N/A

            \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
          5. lower-/.f6451.5

            \[\leadsto \frac{\color{blue}{\frac{1 - \cos x}{x}}}{x} \]
        3. Applied rewrites51.5%

          \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}} \]
        4. Step-by-step derivation
          1. lift-/.f64N/A

            \[\leadsto \frac{\color{blue}{\frac{1 - \cos x}{x}}}{x} \]
          2. lift--.f64N/A

            \[\leadsto \frac{\frac{\color{blue}{1 - \cos x}}{x}}{x} \]
          3. sub-flipN/A

            \[\leadsto \frac{\frac{\color{blue}{1 + \left(\mathsf{neg}\left(\cos x\right)\right)}}{x}}{x} \]
          4. lift-neg.f64N/A

            \[\leadsto \frac{\frac{1 + \color{blue}{\left(-\cos x\right)}}{x}}{x} \]
          5. div-addN/A

            \[\leadsto \frac{\color{blue}{\frac{1}{x} + \frac{-\cos x}{x}}}{x} \]
          6. inv-powN/A

            \[\leadsto \frac{\color{blue}{{x}^{-1}} + \frac{-\cos x}{x}}{x} \]
          7. sqr-powN/A

            \[\leadsto \frac{\color{blue}{{x}^{\left(\frac{-1}{2}\right)} \cdot {x}^{\left(\frac{-1}{2}\right)}} + \frac{-\cos x}{x}}{x} \]
          8. lower-fma.f64N/A

            \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({x}^{\left(\frac{-1}{2}\right)}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}}{x} \]
          9. metadata-evalN/A

            \[\leadsto \frac{\mathsf{fma}\left({x}^{\color{blue}{\frac{-1}{2}}}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}{x} \]
          10. metadata-evalN/A

            \[\leadsto \frac{\mathsf{fma}\left({x}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}{x} \]
          11. lower-pow.f64N/A

            \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{{x}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}{x} \]
          12. metadata-evalN/A

            \[\leadsto \frac{\mathsf{fma}\left({x}^{\color{blue}{\frac{-1}{2}}}, {x}^{\left(\frac{-1}{2}\right)}, \frac{-\cos x}{x}\right)}{x} \]
          13. metadata-evalN/A

            \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\color{blue}{\frac{-1}{2}}}, \frac{-\cos x}{x}\right)}{x} \]
          14. metadata-evalN/A

            \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}, \frac{-\cos x}{x}\right)}{x} \]
          15. lower-pow.f64N/A

            \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, \color{blue}{{x}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}, \frac{-\cos x}{x}\right)}{x} \]
          16. metadata-evalN/A

            \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\color{blue}{\frac{-1}{2}}}, \frac{-\cos x}{x}\right)}{x} \]
          17. frac-2negN/A

            \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \color{blue}{\frac{\mathsf{neg}\left(\left(-\cos x\right)\right)}{\mathsf{neg}\left(x\right)}}\right)}{x} \]
          18. lift-neg.f64N/A

            \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \frac{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\cos x\right)\right)}\right)}{\mathsf{neg}\left(x\right)}\right)}{x} \]
          19. remove-double-negN/A

            \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \frac{\color{blue}{\cos x}}{\mathsf{neg}\left(x\right)}\right)}{x} \]
          20. lower-/.f64N/A

            \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, {x}^{\frac{-1}{2}}, \color{blue}{\frac{\cos x}{\mathsf{neg}\left(x\right)}}\right)}{x} \]
          21. lower-neg.f6425.4

            \[\leadsto \frac{\mathsf{fma}\left({x}^{-0.5}, {x}^{-0.5}, \frac{\cos x}{\color{blue}{-x}}\right)}{x} \]
        5. Applied rewrites25.4%

          \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({x}^{-0.5}, {x}^{-0.5}, \frac{\cos x}{-x}\right)}}{x} \]
        6. Taylor expanded in x around 0

          \[\leadsto \color{blue}{\frac{x \cdot {\left({x}^{\frac{-1}{2}}\right)}^{2} - 1}{{x}^{2}}} \]
        7. Step-by-step derivation
          1. Applied rewrites27.6%

            \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{1}{x}, x, -1\right)}{x \cdot x}} \]
        8. Recombined 2 regimes into one program.
        9. Add Preprocessing

        Alternative 7: 64.0% accurate, 2.4× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 9.5 \cdot 10^{+76}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\left(1 - 1\right) \cdot \frac{\frac{-1}{x}}{x}\\ \end{array} \end{array} \]
        (FPCore (x)
         :precision binary64
         (if (<= x 9.5e+76) 0.5 (* (- 1.0 1.0) (/ (/ -1.0 x) x))))
        double code(double x) {
        	double tmp;
        	if (x <= 9.5e+76) {
        		tmp = 0.5;
        	} else {
        		tmp = (1.0 - 1.0) * ((-1.0 / x) / x);
        	}
        	return tmp;
        }
        
        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)
        use fmin_fmax_functions
            real(8), intent (in) :: x
            real(8) :: tmp
            if (x <= 9.5d+76) then
                tmp = 0.5d0
            else
                tmp = (1.0d0 - 1.0d0) * (((-1.0d0) / x) / x)
            end if
            code = tmp
        end function
        
        public static double code(double x) {
        	double tmp;
        	if (x <= 9.5e+76) {
        		tmp = 0.5;
        	} else {
        		tmp = (1.0 - 1.0) * ((-1.0 / x) / x);
        	}
        	return tmp;
        }
        
        def code(x):
        	tmp = 0
        	if x <= 9.5e+76:
        		tmp = 0.5
        	else:
        		tmp = (1.0 - 1.0) * ((-1.0 / x) / x)
        	return tmp
        
        function code(x)
        	tmp = 0.0
        	if (x <= 9.5e+76)
        		tmp = 0.5;
        	else
        		tmp = Float64(Float64(1.0 - 1.0) * Float64(Float64(-1.0 / x) / x));
        	end
        	return tmp
        end
        
        function tmp_2 = code(x)
        	tmp = 0.0;
        	if (x <= 9.5e+76)
        		tmp = 0.5;
        	else
        		tmp = (1.0 - 1.0) * ((-1.0 / x) / x);
        	end
        	tmp_2 = tmp;
        end
        
        code[x_] := If[LessEqual[x, 9.5e+76], 0.5, N[(N[(1.0 - 1.0), $MachinePrecision] * N[(N[(-1.0 / x), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x \leq 9.5 \cdot 10^{+76}:\\
        \;\;\;\;0.5\\
        
        \mathbf{else}:\\
        \;\;\;\;\left(1 - 1\right) \cdot \frac{\frac{-1}{x}}{x}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < 9.5000000000000003e76

          1. Initial program 50.4%

            \[\frac{1 - \cos x}{x \cdot x} \]
          2. Step-by-step derivation
            1. lift-/.f64N/A

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

              \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
            3. flip--N/A

              \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
            4. associate-/l/N/A

              \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
            5. lower-/.f64N/A

              \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
            6. metadata-evalN/A

              \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
            7. lower--.f64N/A

              \[\leadsto \frac{\color{blue}{1 - \cos x \cdot \cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
            8. lift-cos.f64N/A

              \[\leadsto \frac{1 - \color{blue}{\cos x} \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
            9. lift-cos.f64N/A

              \[\leadsto \frac{1 - \cos x \cdot \color{blue}{\cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
            10. sqr-cos-aN/A

              \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
            11. lower-+.f64N/A

              \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
            12. lower-*.f64N/A

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

              \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \color{blue}{\cos \left(2 \cdot x\right)}\right)}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
            14. lower-*.f64N/A

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

              \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
            16. +-commutativeN/A

              \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
            17. lower-+.f6450.1

              \[\leadsto \frac{1 - \left(0.5 + 0.5 \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
          3. Applied rewrites50.1%

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

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

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

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

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

              \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \color{blue}{\left(2 \cdot x\right)}\right)}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
            6. sqr-cos-a-revN/A

              \[\leadsto \frac{1 - \color{blue}{\cos x \cdot \cos x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
            7. 1-sub-cosN/A

              \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
            8. pow2N/A

              \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
            9. lower-pow.f64N/A

              \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
            10. lower-sin.f6475.3

              \[\leadsto \frac{{\color{blue}{\sin x}}^{2}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
          5. Applied rewrites75.3%

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

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

              \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
            3. unpow2N/A

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

              \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)}} \]
            5. lift-*.f64N/A

              \[\leadsto \frac{\sin x \cdot \sin x}{\left(\cos x + 1\right) \cdot \color{blue}{\left(x \cdot x\right)}} \]
            6. associate-*r*N/A

              \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\left(\cos x + 1\right) \cdot x\right) \cdot x}} \]
            7. times-fracN/A

              \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
            8. lower-*.f64N/A

              \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
            9. lift-+.f64N/A

              \[\leadsto \frac{\sin x}{\color{blue}{\left(\cos x + 1\right)} \cdot x} \cdot \frac{\sin x}{x} \]
            10. distribute-rgt1-inN/A

              \[\leadsto \frac{\sin x}{\color{blue}{x + \cos x \cdot x}} \cdot \frac{\sin x}{x} \]
            11. *-lft-identityN/A

              \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
            12. lift-*.f64N/A

              \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
            13. *-commutativeN/A

              \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
            14. lift-*.f64N/A

              \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
            15. lower-/.f64N/A

              \[\leadsto \color{blue}{\frac{\sin x}{1 \cdot x + x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
            16. lift-*.f64N/A

              \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
            17. *-lft-identityN/A

              \[\leadsto \frac{\sin x}{\color{blue}{x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
            18. +-commutativeN/A

              \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x + x}} \cdot \frac{\sin x}{x} \]
            19. lift-*.f64N/A

              \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x} + x} \cdot \frac{\sin x}{x} \]
            20. *-commutativeN/A

              \[\leadsto \frac{\sin x}{\color{blue}{\cos x \cdot x} + x} \cdot \frac{\sin x}{x} \]
            21. lower-fma.f64N/A

              \[\leadsto \frac{\sin x}{\color{blue}{\mathsf{fma}\left(\cos x, x, x\right)}} \cdot \frac{\sin x}{x} \]
            22. lower-/.f6499.5

              \[\leadsto \frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \color{blue}{\frac{\sin x}{x}} \]
          7. Applied rewrites99.5%

            \[\leadsto \color{blue}{\frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \frac{\sin x}{x}} \]
          8. Taylor expanded in x around 0

            \[\leadsto \color{blue}{\frac{1}{2}} \]
          9. Step-by-step derivation
            1. Applied rewrites52.0%

              \[\leadsto \color{blue}{0.5} \]

            if 9.5000000000000003e76 < x

            1. Initial program 50.4%

              \[\frac{1 - \cos x}{x \cdot x} \]
            2. Step-by-step derivation
              1. lift-/.f64N/A

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

                \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
              3. flip--N/A

                \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
              4. associate-/l/N/A

                \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
              5. lower-/.f64N/A

                \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
              6. metadata-evalN/A

                \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              7. lower--.f64N/A

                \[\leadsto \frac{\color{blue}{1 - \cos x \cdot \cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              8. lift-cos.f64N/A

                \[\leadsto \frac{1 - \color{blue}{\cos x} \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              9. lift-cos.f64N/A

                \[\leadsto \frac{1 - \cos x \cdot \color{blue}{\cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              10. sqr-cos-aN/A

                \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              11. lower-+.f64N/A

                \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              12. lower-*.f64N/A

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

                \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \color{blue}{\cos \left(2 \cdot x\right)}\right)}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              14. lower-*.f64N/A

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

                \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
              16. +-commutativeN/A

                \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
              17. lower-+.f6450.1

                \[\leadsto \frac{1 - \left(0.5 + 0.5 \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
            3. Applied rewrites50.1%

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

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

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

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

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

                \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \color{blue}{\left(2 \cdot x\right)}\right)}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
              6. sqr-cos-a-revN/A

                \[\leadsto \frac{1 - \color{blue}{\cos x \cdot \cos x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
              7. 1-sub-cosN/A

                \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
              8. pow2N/A

                \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
              9. lower-pow.f64N/A

                \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
              10. lower-sin.f6475.3

                \[\leadsto \frac{{\color{blue}{\sin x}}^{2}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
            5. Applied rewrites75.3%

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

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

                \[\leadsto \frac{{\sin x}^{2}}{\color{blue}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)}} \]
              3. associate-/r*N/A

                \[\leadsto \color{blue}{\frac{\frac{{\sin x}^{2}}{\cos x + 1}}{x \cdot x}} \]
              4. lift-pow.f64N/A

                \[\leadsto \frac{\frac{\color{blue}{{\sin x}^{2}}}{\cos x + 1}}{x \cdot x} \]
              5. unpow2N/A

                \[\leadsto \frac{\frac{\color{blue}{\sin x \cdot \sin x}}{\cos x + 1}}{x \cdot x} \]
              6. lift-sin.f64N/A

                \[\leadsto \frac{\frac{\color{blue}{\sin x} \cdot \sin x}{\cos x + 1}}{x \cdot x} \]
              7. lift-sin.f64N/A

                \[\leadsto \frac{\frac{\sin x \cdot \color{blue}{\sin x}}{\cos x + 1}}{x \cdot x} \]
              8. 1-sub-cosN/A

                \[\leadsto \frac{\frac{\color{blue}{1 - \cos x \cdot \cos x}}{\cos x + 1}}{x \cdot x} \]
              9. metadata-evalN/A

                \[\leadsto \frac{\frac{\color{blue}{1 \cdot 1} - \cos x \cdot \cos x}{\cos x + 1}}{x \cdot x} \]
              10. lift-cos.f64N/A

                \[\leadsto \frac{\frac{1 \cdot 1 - \color{blue}{\cos x} \cdot \cos x}{\cos x + 1}}{x \cdot x} \]
              11. lift-cos.f64N/A

                \[\leadsto \frac{\frac{1 \cdot 1 - \cos x \cdot \color{blue}{\cos x}}{\cos x + 1}}{x \cdot x} \]
              12. lift-+.f64N/A

                \[\leadsto \frac{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\color{blue}{\cos x + 1}}}{x \cdot x} \]
              13. +-commutativeN/A

                \[\leadsto \frac{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\color{blue}{1 + \cos x}}}{x \cdot x} \]
              14. flip--N/A

                \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
              15. lift--.f64N/A

                \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
              16. lift-*.f64N/A

                \[\leadsto \frac{1 - \cos x}{\color{blue}{x \cdot x}} \]
              17. sqr-neg-revN/A

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

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

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

                \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{-x}}{-x}} \]
            7. Applied rewrites50.7%

              \[\leadsto \color{blue}{\left(\cos x - 1\right) \cdot \frac{\frac{-1}{x}}{x}} \]
            8. Taylor expanded in x around 0

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

                \[\leadsto \left(\color{blue}{1} - 1\right) \cdot \frac{\frac{-1}{x}}{x} \]
            10. Recombined 2 regimes into one program.
            11. Add Preprocessing

            Alternative 8: 52.0% accurate, 41.8× speedup?

            \[\begin{array}{l} \\ 0.5 \end{array} \]
            (FPCore (x) :precision binary64 0.5)
            double code(double x) {
            	return 0.5;
            }
            
            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)
            use fmin_fmax_functions
                real(8), intent (in) :: x
                code = 0.5d0
            end function
            
            public static double code(double x) {
            	return 0.5;
            }
            
            def code(x):
            	return 0.5
            
            function code(x)
            	return 0.5
            end
            
            function tmp = code(x)
            	tmp = 0.5;
            end
            
            code[x_] := 0.5
            
            \begin{array}{l}
            
            \\
            0.5
            \end{array}
            
            Derivation
            1. Initial program 50.4%

              \[\frac{1 - \cos x}{x \cdot x} \]
            2. Step-by-step derivation
              1. lift-/.f64N/A

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

                \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x} \]
              3. flip--N/A

                \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
              4. associate-/l/N/A

                \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
              5. lower-/.f64N/A

                \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
              6. metadata-evalN/A

                \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              7. lower--.f64N/A

                \[\leadsto \frac{\color{blue}{1 - \cos x \cdot \cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              8. lift-cos.f64N/A

                \[\leadsto \frac{1 - \color{blue}{\cos x} \cdot \cos x}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              9. lift-cos.f64N/A

                \[\leadsto \frac{1 - \cos x \cdot \color{blue}{\cos x}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              10. sqr-cos-aN/A

                \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              11. lower-+.f64N/A

                \[\leadsto \frac{1 - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              12. lower-*.f64N/A

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

                \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \color{blue}{\cos \left(2 \cdot x\right)}\right)}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)} \]
              14. lower-*.f64N/A

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

                \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(1 + \cos x\right) \cdot \left(x \cdot x\right)}} \]
              16. +-commutativeN/A

                \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
              17. lower-+.f6450.1

                \[\leadsto \frac{1 - \left(0.5 + 0.5 \cdot \cos \left(2 \cdot x\right)\right)}{\color{blue}{\left(\cos x + 1\right)} \cdot \left(x \cdot x\right)} \]
            3. Applied rewrites50.1%

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

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

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

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

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

                \[\leadsto \frac{1 - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \color{blue}{\left(2 \cdot x\right)}\right)}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
              6. sqr-cos-a-revN/A

                \[\leadsto \frac{1 - \color{blue}{\cos x \cdot \cos x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
              7. 1-sub-cosN/A

                \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
              8. pow2N/A

                \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
              9. lower-pow.f64N/A

                \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
              10. lower-sin.f6475.3

                \[\leadsto \frac{{\color{blue}{\sin x}}^{2}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
            5. Applied rewrites75.3%

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

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

                \[\leadsto \frac{\color{blue}{{\sin x}^{2}}}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)} \]
              3. unpow2N/A

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

                \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\cos x + 1\right) \cdot \left(x \cdot x\right)}} \]
              5. lift-*.f64N/A

                \[\leadsto \frac{\sin x \cdot \sin x}{\left(\cos x + 1\right) \cdot \color{blue}{\left(x \cdot x\right)}} \]
              6. associate-*r*N/A

                \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\left(\left(\cos x + 1\right) \cdot x\right) \cdot x}} \]
              7. times-fracN/A

                \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
              8. lower-*.f64N/A

                \[\leadsto \color{blue}{\frac{\sin x}{\left(\cos x + 1\right) \cdot x} \cdot \frac{\sin x}{x}} \]
              9. lift-+.f64N/A

                \[\leadsto \frac{\sin x}{\color{blue}{\left(\cos x + 1\right)} \cdot x} \cdot \frac{\sin x}{x} \]
              10. distribute-rgt1-inN/A

                \[\leadsto \frac{\sin x}{\color{blue}{x + \cos x \cdot x}} \cdot \frac{\sin x}{x} \]
              11. *-lft-identityN/A

                \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
              12. lift-*.f64N/A

                \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + \cos x \cdot x} \cdot \frac{\sin x}{x} \]
              13. *-commutativeN/A

                \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
              14. lift-*.f64N/A

                \[\leadsto \frac{\sin x}{1 \cdot x + \color{blue}{x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
              15. lower-/.f64N/A

                \[\leadsto \color{blue}{\frac{\sin x}{1 \cdot x + x \cdot \cos x}} \cdot \frac{\sin x}{x} \]
              16. lift-*.f64N/A

                \[\leadsto \frac{\sin x}{\color{blue}{1 \cdot x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
              17. *-lft-identityN/A

                \[\leadsto \frac{\sin x}{\color{blue}{x} + x \cdot \cos x} \cdot \frac{\sin x}{x} \]
              18. +-commutativeN/A

                \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x + x}} \cdot \frac{\sin x}{x} \]
              19. lift-*.f64N/A

                \[\leadsto \frac{\sin x}{\color{blue}{x \cdot \cos x} + x} \cdot \frac{\sin x}{x} \]
              20. *-commutativeN/A

                \[\leadsto \frac{\sin x}{\color{blue}{\cos x \cdot x} + x} \cdot \frac{\sin x}{x} \]
              21. lower-fma.f64N/A

                \[\leadsto \frac{\sin x}{\color{blue}{\mathsf{fma}\left(\cos x, x, x\right)}} \cdot \frac{\sin x}{x} \]
              22. lower-/.f6499.5

                \[\leadsto \frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \color{blue}{\frac{\sin x}{x}} \]
            7. Applied rewrites99.5%

              \[\leadsto \color{blue}{\frac{\sin x}{\mathsf{fma}\left(\cos x, x, x\right)} \cdot \frac{\sin x}{x}} \]
            8. Taylor expanded in x around 0

              \[\leadsto \color{blue}{\frac{1}{2}} \]
            9. Step-by-step derivation
              1. Applied rewrites52.0%

                \[\leadsto \color{blue}{0.5} \]
              2. Add Preprocessing

              Reproduce

              ?
              herbie shell --seed 2025136 
              (FPCore (x)
                :name "cos2 (problem 3.4.1)"
                :precision binary64
                (/ (- 1.0 (cos x)) (* x x)))