2sin (example 3.3)

Percentage Accurate: 62.4% → 99.7%
Time: 11.8s
Alternatives: 10
Speedup: 207.0×

Specification

?
\[\left(\left(-10000 \leq x \land x \leq 10000\right) \land 10^{-16} \cdot \left|x\right| < \varepsilon\right) \land \varepsilon < \left|x\right|\]
\[\begin{array}{l} \\ \sin \left(x + \varepsilon\right) - \sin x \end{array} \]
(FPCore (x eps) :precision binary64 (- (sin (+ x eps)) (sin x)))
double code(double x, double eps) {
	return sin((x + eps)) - sin(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, eps)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = sin((x + eps)) - sin(x)
end function
public static double code(double x, double eps) {
	return Math.sin((x + eps)) - Math.sin(x);
}
def code(x, eps):
	return math.sin((x + eps)) - math.sin(x)
function code(x, eps)
	return Float64(sin(Float64(x + eps)) - sin(x))
end
function tmp = code(x, eps)
	tmp = sin((x + eps)) - sin(x);
end
code[x_, eps_] := N[(N[Sin[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sin \left(x + \varepsilon\right) - \sin x
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 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: 62.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sin \left(x + \varepsilon\right) - \sin x \end{array} \]
(FPCore (x eps) :precision binary64 (- (sin (+ x eps)) (sin x)))
double code(double x, double eps) {
	return sin((x + eps)) - sin(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, eps)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = sin((x + eps)) - sin(x)
end function
public static double code(double x, double eps) {
	return Math.sin((x + eps)) - Math.sin(x);
}
def code(x, eps):
	return math.sin((x + eps)) - math.sin(x)
function code(x, eps)
	return Float64(sin(Float64(x + eps)) - sin(x))
end
function tmp = code(x, eps)
	tmp = sin((x + eps)) - sin(x);
end
code[x_, eps_] := N[(N[Sin[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sin \left(x + \varepsilon\right) - \sin x
\end{array}

Alternative 1: 99.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \left(\left(\mathsf{fma}\left(-0.020833333333333332, \varepsilon \cdot \varepsilon, 0.5\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \sin \left(\mathsf{fma}\left(\mathsf{PI}\left(\right) + \varepsilon, 0.5, x\right)\right) \end{array} \]
(FPCore (x eps)
 :precision binary64
 (*
  (* (* (fma -0.020833333333333332 (* eps eps) 0.5) eps) 2.0)
  (sin (fma (+ (PI) eps) 0.5 x))))
\begin{array}{l}

\\
\left(\left(\mathsf{fma}\left(-0.020833333333333332, \varepsilon \cdot \varepsilon, 0.5\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \sin \left(\mathsf{fma}\left(\mathsf{PI}\left(\right) + \varepsilon, 0.5, x\right)\right)
\end{array}
Derivation
  1. Initial program 62.1%

    \[\sin \left(x + \varepsilon\right) - \sin x \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\sin \left(x + \varepsilon\right) - \sin x} \]
    2. lift-sin.f64N/A

      \[\leadsto \color{blue}{\sin \left(x + \varepsilon\right)} - \sin x \]
    3. lift-sin.f64N/A

      \[\leadsto \sin \left(x + \varepsilon\right) - \color{blue}{\sin x} \]
    4. diff-sinN/A

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

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

      \[\leadsto \color{blue}{\left(2 \cdot \sin \left(\frac{\left(x + \varepsilon\right) - x}{2}\right)\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right)} \]
    7. *-commutativeN/A

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

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

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

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

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

      \[\leadsto \left(\sin \left(\frac{\color{blue}{\left(\varepsilon + x\right)} - x}{2}\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
    13. associate--l+N/A

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

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

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

      \[\leadsto \left(\sin \left(\frac{\color{blue}{0} + \varepsilon}{2}\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
    17. cos-neg-revN/A

      \[\leadsto \left(\sin \left(\frac{0 + \varepsilon}{2}\right) \cdot 2\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right)} \]
    18. lower-cos.f64N/A

      \[\leadsto \left(\sin \left(\frac{0 + \varepsilon}{2}\right) \cdot 2\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right)} \]
    19. distribute-neg-frac2N/A

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

      \[\leadsto \left(\sin \left(\frac{0 + \varepsilon}{2}\right) \cdot 2\right) \cdot \cos \color{blue}{\left(\frac{\left(x + \varepsilon\right) + x}{\mathsf{neg}\left(2\right)}\right)} \]
  4. Applied rewrites100.0%

    \[\leadsto \color{blue}{\left(\sin \left(\frac{0 + \varepsilon}{2}\right) \cdot 2\right) \cdot \cos \left(\frac{\mathsf{fma}\left(2, x, \varepsilon\right)}{-2}\right)} \]
  5. Taylor expanded in eps around 0

    \[\leadsto \left(\color{blue}{\left(\varepsilon \cdot \left(\frac{1}{2} + \frac{-1}{48} \cdot {\varepsilon}^{2}\right)\right)} \cdot 2\right) \cdot \cos \left(\frac{\mathsf{fma}\left(2, x, \varepsilon\right)}{-2}\right) \]
  6. Step-by-step derivation
    1. Applied rewrites100.0%

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

        \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \color{blue}{\cos \left(\frac{\mathsf{fma}\left(2, x, \varepsilon\right)}{-2}\right)} \]
      2. cos-neg-revN/A

        \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\frac{\mathsf{fma}\left(2, x, \varepsilon\right)}{-2}\right)\right)} \]
      3. sin-+PI/2-revN/A

        \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \color{blue}{\sin \left(\left(\mathsf{neg}\left(\frac{\mathsf{fma}\left(2, x, \varepsilon\right)}{-2}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
      4. lift-/.f64N/A

        \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \sin \left(\left(\mathsf{neg}\left(\color{blue}{\frac{\mathsf{fma}\left(2, x, \varepsilon\right)}{-2}}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      5. lift-fma.f64N/A

        \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \sin \left(\left(\mathsf{neg}\left(\frac{\color{blue}{2 \cdot x + \varepsilon}}{-2}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      6. count-2-revN/A

        \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \sin \left(\left(\mathsf{neg}\left(\frac{\color{blue}{\left(x + x\right)} + \varepsilon}{-2}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      7. associate-+l+N/A

        \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \sin \left(\left(\mathsf{neg}\left(\frac{\color{blue}{x + \left(x + \varepsilon\right)}}{-2}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      8. lift-+.f64N/A

        \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \sin \left(\left(\mathsf{neg}\left(\frac{x + \color{blue}{\left(x + \varepsilon\right)}}{-2}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      9. +-commutativeN/A

        \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \sin \left(\left(\mathsf{neg}\left(\frac{\color{blue}{\left(x + \varepsilon\right) + x}}{-2}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      10. distribute-frac-neg2N/A

        \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \sin \left(\color{blue}{\frac{\left(x + \varepsilon\right) + x}{\mathsf{neg}\left(-2\right)}} + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      11. metadata-evalN/A

        \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \sin \left(\frac{\left(x + \varepsilon\right) + x}{\color{blue}{2}} + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      12. lower-sin.f64N/A

        \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \color{blue}{\sin \left(\frac{\left(x + \varepsilon\right) + x}{2} + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
      13. lower-+.f64N/A

        \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \sin \color{blue}{\left(\frac{\left(x + \varepsilon\right) + x}{2} + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
    3. Applied rewrites100.0%

      \[\leadsto \left(\left(\mathsf{fma}\left(-0.020833333333333332, \varepsilon \cdot \varepsilon, 0.5\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \color{blue}{\sin \left(\frac{\mathsf{fma}\left(x, 2, \varepsilon\right)}{2} + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
    4. Taylor expanded in x around 0

      \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \sin \color{blue}{\left(x + \left(\frac{1}{2} \cdot \varepsilon + \frac{1}{2} \cdot \mathsf{PI}\left(\right)\right)\right)} \]
    5. Step-by-step derivation
      1. Applied rewrites100.0%

        \[\leadsto \left(\left(\mathsf{fma}\left(-0.020833333333333332, \varepsilon \cdot \varepsilon, 0.5\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \sin \color{blue}{\left(\mathsf{fma}\left(\mathsf{PI}\left(\right) + \varepsilon, 0.5, x\right)\right)} \]
      2. Add Preprocessing

      Alternative 2: 99.7% accurate, 1.6× speedup?

      \[\begin{array}{l} \\ \left(\left(\mathsf{fma}\left(-0.020833333333333332, \varepsilon \cdot \varepsilon, 0.5\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \cos \left(\mathsf{fma}\left(0.5, \varepsilon, x\right)\right) \end{array} \]
      (FPCore (x eps)
       :precision binary64
       (*
        (* (* (fma -0.020833333333333332 (* eps eps) 0.5) eps) 2.0)
        (cos (fma 0.5 eps x))))
      double code(double x, double eps) {
      	return ((fma(-0.020833333333333332, (eps * eps), 0.5) * eps) * 2.0) * cos(fma(0.5, eps, x));
      }
      
      function code(x, eps)
      	return Float64(Float64(Float64(fma(-0.020833333333333332, Float64(eps * eps), 0.5) * eps) * 2.0) * cos(fma(0.5, eps, x)))
      end
      
      code[x_, eps_] := N[(N[(N[(N[(-0.020833333333333332 * N[(eps * eps), $MachinePrecision] + 0.5), $MachinePrecision] * eps), $MachinePrecision] * 2.0), $MachinePrecision] * N[Cos[N[(0.5 * eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \left(\left(\mathsf{fma}\left(-0.020833333333333332, \varepsilon \cdot \varepsilon, 0.5\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \cos \left(\mathsf{fma}\left(0.5, \varepsilon, x\right)\right)
      \end{array}
      
      Derivation
      1. Initial program 62.1%

        \[\sin \left(x + \varepsilon\right) - \sin x \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto \color{blue}{\sin \left(x + \varepsilon\right) - \sin x} \]
        2. lift-sin.f64N/A

          \[\leadsto \color{blue}{\sin \left(x + \varepsilon\right)} - \sin x \]
        3. lift-sin.f64N/A

          \[\leadsto \sin \left(x + \varepsilon\right) - \color{blue}{\sin x} \]
        4. diff-sinN/A

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

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

          \[\leadsto \color{blue}{\left(2 \cdot \sin \left(\frac{\left(x + \varepsilon\right) - x}{2}\right)\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right)} \]
        7. *-commutativeN/A

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

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

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

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

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

          \[\leadsto \left(\sin \left(\frac{\color{blue}{\left(\varepsilon + x\right)} - x}{2}\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
        13. associate--l+N/A

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

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

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

          \[\leadsto \left(\sin \left(\frac{\color{blue}{0} + \varepsilon}{2}\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
        17. cos-neg-revN/A

          \[\leadsto \left(\sin \left(\frac{0 + \varepsilon}{2}\right) \cdot 2\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right)} \]
        18. lower-cos.f64N/A

          \[\leadsto \left(\sin \left(\frac{0 + \varepsilon}{2}\right) \cdot 2\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right)} \]
        19. distribute-neg-frac2N/A

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

          \[\leadsto \left(\sin \left(\frac{0 + \varepsilon}{2}\right) \cdot 2\right) \cdot \cos \color{blue}{\left(\frac{\left(x + \varepsilon\right) + x}{\mathsf{neg}\left(2\right)}\right)} \]
      4. Applied rewrites100.0%

        \[\leadsto \color{blue}{\left(\sin \left(\frac{0 + \varepsilon}{2}\right) \cdot 2\right) \cdot \cos \left(\frac{\mathsf{fma}\left(2, x, \varepsilon\right)}{-2}\right)} \]
      5. Taylor expanded in eps around 0

        \[\leadsto \left(\color{blue}{\left(\varepsilon \cdot \left(\frac{1}{2} + \frac{-1}{48} \cdot {\varepsilon}^{2}\right)\right)} \cdot 2\right) \cdot \cos \left(\frac{\mathsf{fma}\left(2, x, \varepsilon\right)}{-2}\right) \]
      6. Step-by-step derivation
        1. Applied rewrites100.0%

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

          \[\leadsto \left(\left(\mathsf{fma}\left(\frac{-1}{48}, \varepsilon \cdot \varepsilon, \frac{1}{2}\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \color{blue}{\cos \left(\frac{-1}{2} \cdot \left(\varepsilon + 2 \cdot x\right)\right)} \]
        3. Step-by-step derivation
          1. Applied rewrites100.0%

            \[\leadsto \left(\left(\mathsf{fma}\left(-0.020833333333333332, \varepsilon \cdot \varepsilon, 0.5\right) \cdot \varepsilon\right) \cdot 2\right) \cdot \color{blue}{\cos \left(\mathsf{fma}\left(0.5, \varepsilon, x\right)\right)} \]
          2. Add Preprocessing

          Alternative 3: 99.5% accurate, 1.7× speedup?

          \[\begin{array}{l} \\ \varepsilon \cdot \cos \left(\frac{\mathsf{fma}\left(2, x, \varepsilon\right)}{-2}\right) \end{array} \]
          (FPCore (x eps) :precision binary64 (* eps (cos (/ (fma 2.0 x eps) -2.0))))
          double code(double x, double eps) {
          	return eps * cos((fma(2.0, x, eps) / -2.0));
          }
          
          function code(x, eps)
          	return Float64(eps * cos(Float64(fma(2.0, x, eps) / -2.0)))
          end
          
          code[x_, eps_] := N[(eps * N[Cos[N[(N[(2.0 * x + eps), $MachinePrecision] / -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          \varepsilon \cdot \cos \left(\frac{\mathsf{fma}\left(2, x, \varepsilon\right)}{-2}\right)
          \end{array}
          
          Derivation
          1. Initial program 62.1%

            \[\sin \left(x + \varepsilon\right) - \sin x \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift--.f64N/A

              \[\leadsto \color{blue}{\sin \left(x + \varepsilon\right) - \sin x} \]
            2. lift-sin.f64N/A

              \[\leadsto \color{blue}{\sin \left(x + \varepsilon\right)} - \sin x \]
            3. lift-sin.f64N/A

              \[\leadsto \sin \left(x + \varepsilon\right) - \color{blue}{\sin x} \]
            4. diff-sinN/A

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

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

              \[\leadsto \color{blue}{\left(2 \cdot \sin \left(\frac{\left(x + \varepsilon\right) - x}{2}\right)\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right)} \]
            7. *-commutativeN/A

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

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

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

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

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

              \[\leadsto \left(\sin \left(\frac{\color{blue}{\left(\varepsilon + x\right)} - x}{2}\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
            13. associate--l+N/A

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

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

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

              \[\leadsto \left(\sin \left(\frac{\color{blue}{0} + \varepsilon}{2}\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
            17. cos-neg-revN/A

              \[\leadsto \left(\sin \left(\frac{0 + \varepsilon}{2}\right) \cdot 2\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right)} \]
            18. lower-cos.f64N/A

              \[\leadsto \left(\sin \left(\frac{0 + \varepsilon}{2}\right) \cdot 2\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right)} \]
            19. distribute-neg-frac2N/A

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

              \[\leadsto \left(\sin \left(\frac{0 + \varepsilon}{2}\right) \cdot 2\right) \cdot \cos \color{blue}{\left(\frac{\left(x + \varepsilon\right) + x}{\mathsf{neg}\left(2\right)}\right)} \]
          4. Applied rewrites100.0%

            \[\leadsto \color{blue}{\left(\sin \left(\frac{0 + \varepsilon}{2}\right) \cdot 2\right) \cdot \cos \left(\frac{\mathsf{fma}\left(2, x, \varepsilon\right)}{-2}\right)} \]
          5. Taylor expanded in eps around 0

            \[\leadsto \color{blue}{\varepsilon} \cdot \cos \left(\frac{\mathsf{fma}\left(2, x, \varepsilon\right)}{-2}\right) \]
          6. Step-by-step derivation
            1. Applied rewrites100.0%

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

            Alternative 4: 99.1% accurate, 1.8× speedup?

            \[\begin{array}{l} \\ \mathsf{fma}\left(x \cdot \varepsilon, -0.5, \cos x\right) \cdot \varepsilon \end{array} \]
            (FPCore (x eps) :precision binary64 (* (fma (* x eps) -0.5 (cos x)) eps))
            double code(double x, double eps) {
            	return fma((x * eps), -0.5, cos(x)) * eps;
            }
            
            function code(x, eps)
            	return Float64(fma(Float64(x * eps), -0.5, cos(x)) * eps)
            end
            
            code[x_, eps_] := N[(N[(N[(x * eps), $MachinePrecision] * -0.5 + N[Cos[x], $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision]
            
            \begin{array}{l}
            
            \\
            \mathsf{fma}\left(x \cdot \varepsilon, -0.5, \cos x\right) \cdot \varepsilon
            \end{array}
            
            Derivation
            1. Initial program 62.1%

              \[\sin \left(x + \varepsilon\right) - \sin x \]
            2. Add Preprocessing
            3. Taylor expanded in eps around 0

              \[\leadsto \color{blue}{\varepsilon \cdot \left(\cos x + \frac{-1}{2} \cdot \left(\varepsilon \cdot \sin x\right)\right)} \]
            4. Step-by-step derivation
              1. Applied rewrites100.0%

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

                \[\leadsto \mathsf{fma}\left(\varepsilon \cdot x, \frac{-1}{2}, \cos x\right) \cdot \varepsilon \]
              3. Step-by-step derivation
                1. Applied rewrites99.9%

                  \[\leadsto \mathsf{fma}\left(x \cdot \varepsilon, -0.5, \cos x\right) \cdot \varepsilon \]
                2. Add Preprocessing

                Alternative 5: 99.1% accurate, 2.0× speedup?

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

                  \[\sin \left(x + \varepsilon\right) - \sin x \]
                2. Add Preprocessing
                3. Taylor expanded in eps around 0

                  \[\leadsto \color{blue}{\varepsilon \cdot \cos x} \]
                4. Step-by-step derivation
                  1. Applied rewrites99.7%

                    \[\leadsto \color{blue}{\cos x \cdot \varepsilon} \]
                  2. Add Preprocessing

                  Alternative 6: 98.5% accurate, 5.3× speedup?

                  \[\begin{array}{l} \\ \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, -0.5\right) \cdot x, x, 1\right) \cdot \varepsilon \end{array} \]
                  (FPCore (x eps)
                   :precision binary64
                   (*
                    (fma
                     (*
                      (fma (fma -0.001388888888888889 (* x x) 0.041666666666666664) (* x x) -0.5)
                      x)
                     x
                     1.0)
                    eps))
                  double code(double x, double eps) {
                  	return fma((fma(fma(-0.001388888888888889, (x * x), 0.041666666666666664), (x * x), -0.5) * x), x, 1.0) * eps;
                  }
                  
                  function code(x, eps)
                  	return Float64(fma(Float64(fma(fma(-0.001388888888888889, Float64(x * x), 0.041666666666666664), Float64(x * x), -0.5) * x), x, 1.0) * eps)
                  end
                  
                  code[x_, eps_] := N[(N[(N[(N[(N[(-0.001388888888888889 * N[(x * x), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision] * x), $MachinePrecision] * x + 1.0), $MachinePrecision] * eps), $MachinePrecision]
                  
                  \begin{array}{l}
                  
                  \\
                  \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, -0.5\right) \cdot x, x, 1\right) \cdot \varepsilon
                  \end{array}
                  
                  Derivation
                  1. Initial program 62.1%

                    \[\sin \left(x + \varepsilon\right) - \sin x \]
                  2. Add Preprocessing
                  3. Taylor expanded in eps around 0

                    \[\leadsto \color{blue}{\varepsilon \cdot \cos x} \]
                  4. Step-by-step derivation
                    1. Applied rewrites99.7%

                      \[\leadsto \color{blue}{\cos x \cdot \varepsilon} \]
                    2. Taylor expanded in x around 0

                      \[\leadsto \left(1 + {x}^{2} \cdot \left(\frac{1}{24} \cdot {x}^{2} - \frac{1}{2}\right)\right) \cdot \varepsilon \]
                    3. Step-by-step derivation
                      1. Applied rewrites99.2%

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

                        \[\leadsto \left(1 + {x}^{2} \cdot \left({x}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {x}^{2}\right) - \frac{1}{2}\right)\right) \cdot \varepsilon \]
                      3. Step-by-step derivation
                        1. Applied rewrites99.4%

                          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, -0.5\right), x \cdot x, 1\right) \cdot \varepsilon \]
                        2. Step-by-step derivation
                          1. Applied rewrites99.4%

                            \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, -0.5\right) \cdot x, x, 1\right) \cdot \varepsilon \]
                          2. Add Preprocessing

                          Alternative 7: 98.4% accurate, 7.4× speedup?

                          \[\begin{array}{l} \\ \mathsf{fma}\left(\left(\varepsilon \cdot \mathsf{fma}\left(x \cdot x, 0.041666666666666664, -0.5\right)\right) \cdot x, x, \varepsilon\right) \end{array} \]
                          (FPCore (x eps)
                           :precision binary64
                           (fma (* (* eps (fma (* x x) 0.041666666666666664 -0.5)) x) x eps))
                          double code(double x, double eps) {
                          	return fma(((eps * fma((x * x), 0.041666666666666664, -0.5)) * x), x, eps);
                          }
                          
                          function code(x, eps)
                          	return fma(Float64(Float64(eps * fma(Float64(x * x), 0.041666666666666664, -0.5)) * x), x, eps)
                          end
                          
                          code[x_, eps_] := N[(N[(N[(eps * N[(N[(x * x), $MachinePrecision] * 0.041666666666666664 + -0.5), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x + eps), $MachinePrecision]
                          
                          \begin{array}{l}
                          
                          \\
                          \mathsf{fma}\left(\left(\varepsilon \cdot \mathsf{fma}\left(x \cdot x, 0.041666666666666664, -0.5\right)\right) \cdot x, x, \varepsilon\right)
                          \end{array}
                          
                          Derivation
                          1. Initial program 62.1%

                            \[\sin \left(x + \varepsilon\right) - \sin x \]
                          2. Add Preprocessing
                          3. Taylor expanded in eps around 0

                            \[\leadsto \color{blue}{\varepsilon \cdot \cos x} \]
                          4. Step-by-step derivation
                            1. Applied rewrites99.7%

                              \[\leadsto \color{blue}{\cos x \cdot \varepsilon} \]
                            2. Taylor expanded in x around 0

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

                                \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, \left(x \cdot x\right) \cdot \varepsilon, -0.5 \cdot \varepsilon\right), \color{blue}{x \cdot x}, \varepsilon\right) \]
                              2. Step-by-step derivation
                                1. Applied rewrites99.2%

                                  \[\leadsto \mathsf{fma}\left(\left(\varepsilon \cdot \mathsf{fma}\left(x \cdot x, 0.041666666666666664, -0.5\right)\right) \cdot x, x, \varepsilon\right) \]
                                2. Add Preprocessing

                                Alternative 8: 98.4% accurate, 10.4× speedup?

                                \[\begin{array}{l} \\ \mathsf{fma}\left(-0.5 \cdot x, \varepsilon \cdot \left(x + \varepsilon\right), \varepsilon\right) \end{array} \]
                                (FPCore (x eps) :precision binary64 (fma (* -0.5 x) (* eps (+ x eps)) eps))
                                double code(double x, double eps) {
                                	return fma((-0.5 * x), (eps * (x + eps)), eps);
                                }
                                
                                function code(x, eps)
                                	return fma(Float64(-0.5 * x), Float64(eps * Float64(x + eps)), eps)
                                end
                                
                                code[x_, eps_] := N[(N[(-0.5 * x), $MachinePrecision] * N[(eps * N[(x + eps), $MachinePrecision]), $MachinePrecision] + eps), $MachinePrecision]
                                
                                \begin{array}{l}
                                
                                \\
                                \mathsf{fma}\left(-0.5 \cdot x, \varepsilon \cdot \left(x + \varepsilon\right), \varepsilon\right)
                                \end{array}
                                
                                Derivation
                                1. Initial program 62.1%

                                  \[\sin \left(x + \varepsilon\right) - \sin x \]
                                2. Add Preprocessing
                                3. Taylor expanded in eps around 0

                                  \[\leadsto \color{blue}{\varepsilon \cdot \left(\cos x + \frac{-1}{2} \cdot \left(\varepsilon \cdot \sin x\right)\right)} \]
                                4. Step-by-step derivation
                                  1. Applied rewrites100.0%

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

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

                                      \[\leadsto \mathsf{fma}\left(-0.5 \cdot x, \color{blue}{\varepsilon \cdot \left(x + \varepsilon\right)}, \varepsilon\right) \]
                                    2. Add Preprocessing

                                    Alternative 9: 98.3% accurate, 12.2× speedup?

                                    \[\begin{array}{l} \\ \mathsf{fma}\left(-0.5 \cdot x, \varepsilon \cdot x, \varepsilon\right) \end{array} \]
                                    (FPCore (x eps) :precision binary64 (fma (* -0.5 x) (* eps x) eps))
                                    double code(double x, double eps) {
                                    	return fma((-0.5 * x), (eps * x), eps);
                                    }
                                    
                                    function code(x, eps)
                                    	return fma(Float64(-0.5 * x), Float64(eps * x), eps)
                                    end
                                    
                                    code[x_, eps_] := N[(N[(-0.5 * x), $MachinePrecision] * N[(eps * x), $MachinePrecision] + eps), $MachinePrecision]
                                    
                                    \begin{array}{l}
                                    
                                    \\
                                    \mathsf{fma}\left(-0.5 \cdot x, \varepsilon \cdot x, \varepsilon\right)
                                    \end{array}
                                    
                                    Derivation
                                    1. Initial program 62.1%

                                      \[\sin \left(x + \varepsilon\right) - \sin x \]
                                    2. Add Preprocessing
                                    3. Taylor expanded in eps around 0

                                      \[\leadsto \color{blue}{\varepsilon \cdot \left(\cos x + \frac{-1}{2} \cdot \left(\varepsilon \cdot \sin x\right)\right)} \]
                                    4. Step-by-step derivation
                                      1. Applied rewrites100.0%

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

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

                                          \[\leadsto \mathsf{fma}\left(-0.5 \cdot x, \color{blue}{\varepsilon \cdot \left(x + \varepsilon\right)}, \varepsilon\right) \]
                                        2. Taylor expanded in x around inf

                                          \[\leadsto \mathsf{fma}\left(\frac{-1}{2} \cdot x, \varepsilon \cdot x, \varepsilon\right) \]
                                        3. Step-by-step derivation
                                          1. Applied rewrites99.0%

                                            \[\leadsto \mathsf{fma}\left(-0.5 \cdot x, \varepsilon \cdot x, \varepsilon\right) \]
                                          2. Add Preprocessing

                                          Alternative 10: 97.8% accurate, 207.0× speedup?

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

                                            \[\sin \left(x + \varepsilon\right) - \sin x \]
                                          2. Add Preprocessing
                                          3. Taylor expanded in eps around 0

                                            \[\leadsto \color{blue}{\varepsilon \cdot \left(\cos x + \frac{-1}{2} \cdot \left(\varepsilon \cdot \sin x\right)\right)} \]
                                          4. Step-by-step derivation
                                            1. Applied rewrites100.0%

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

                                              \[\leadsto \varepsilon \]
                                            3. Step-by-step derivation
                                              1. Applied rewrites98.4%

                                                \[\leadsto \varepsilon \]
                                              2. Add Preprocessing

                                              Developer Target 1: 99.9% accurate, 0.9× speedup?

                                              \[\begin{array}{l} \\ \left(\cos \left(0.5 \cdot \left(\varepsilon - -2 \cdot x\right)\right) \cdot \sin \left(0.5 \cdot \varepsilon\right)\right) \cdot 2 \end{array} \]
                                              (FPCore (x eps)
                                               :precision binary64
                                               (* (* (cos (* 0.5 (- eps (* -2.0 x)))) (sin (* 0.5 eps))) 2.0))
                                              double code(double x, double eps) {
                                              	return (cos((0.5 * (eps - (-2.0 * x)))) * sin((0.5 * eps))) * 2.0;
                                              }
                                              
                                              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, eps)
                                              use fmin_fmax_functions
                                                  real(8), intent (in) :: x
                                                  real(8), intent (in) :: eps
                                                  code = (cos((0.5d0 * (eps - ((-2.0d0) * x)))) * sin((0.5d0 * eps))) * 2.0d0
                                              end function
                                              
                                              public static double code(double x, double eps) {
                                              	return (Math.cos((0.5 * (eps - (-2.0 * x)))) * Math.sin((0.5 * eps))) * 2.0;
                                              }
                                              
                                              def code(x, eps):
                                              	return (math.cos((0.5 * (eps - (-2.0 * x)))) * math.sin((0.5 * eps))) * 2.0
                                              
                                              function code(x, eps)
                                              	return Float64(Float64(cos(Float64(0.5 * Float64(eps - Float64(-2.0 * x)))) * sin(Float64(0.5 * eps))) * 2.0)
                                              end
                                              
                                              function tmp = code(x, eps)
                                              	tmp = (cos((0.5 * (eps - (-2.0 * x)))) * sin((0.5 * eps))) * 2.0;
                                              end
                                              
                                              code[x_, eps_] := N[(N[(N[Cos[N[(0.5 * N[(eps - N[(-2.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
                                              
                                              \begin{array}{l}
                                              
                                              \\
                                              \left(\cos \left(0.5 \cdot \left(\varepsilon - -2 \cdot x\right)\right) \cdot \sin \left(0.5 \cdot \varepsilon\right)\right) \cdot 2
                                              \end{array}
                                              

                                              Reproduce

                                              ?
                                              herbie shell --seed 2025019 
                                              (FPCore (x eps)
                                                :name "2sin (example 3.3)"
                                                :precision binary64
                                                :pre (and (and (and (<= -10000.0 x) (<= x 10000.0)) (< (* 1e-16 (fabs x)) eps)) (< eps (fabs x)))
                                              
                                                :alt
                                                (! :herbie-platform default (* (cos (* 1/2 (- eps (* -2 x)))) (sin (* 1/2 eps)) 2))
                                              
                                                (- (sin (+ x eps)) (sin x)))