2sin (example 3.3)

Percentage Accurate: 62.6% → 100.0%
Time: 6.0s
Alternatives: 10
Speedup: 69.8×

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|\]
\[\sin \left(x + \varepsilon\right) - \sin x \]
(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]
\sin \left(x + \varepsilon\right) - \sin x

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.6% accurate, 1.0× speedup?

\[\sin \left(x + \varepsilon\right) - \sin x \]
(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]
\sin \left(x + \varepsilon\right) - \sin x

Alternative 1: 100.0% accurate, 0.4× speedup?

\[\begin{array}{l} t_0 := \left(x + x\right) \cdot -0.5\\ \left(\sin \left(0.5 \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \left(\cos t\_0 \cdot \cos \left(-0.5 \cdot \varepsilon\right) - \sin t\_0 \cdot \sin \left(-0.5 \cdot \varepsilon\right)\right) \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (* (+ x x) -0.5)))
   (*
    (* (sin (* 0.5 (- eps 0.0))) 2.0)
    (- (* (cos t_0) (cos (* -0.5 eps))) (* (sin t_0) (sin (* -0.5 eps)))))))
double code(double x, double eps) {
	double t_0 = (x + x) * -0.5;
	return (sin((0.5 * (eps - 0.0))) * 2.0) * ((cos(t_0) * cos((-0.5 * eps))) - (sin(t_0) * sin((-0.5 * 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
    real(8) :: t_0
    t_0 = (x + x) * (-0.5d0)
    code = (sin((0.5d0 * (eps - 0.0d0))) * 2.0d0) * ((cos(t_0) * cos(((-0.5d0) * eps))) - (sin(t_0) * sin(((-0.5d0) * eps))))
end function
public static double code(double x, double eps) {
	double t_0 = (x + x) * -0.5;
	return (Math.sin((0.5 * (eps - 0.0))) * 2.0) * ((Math.cos(t_0) * Math.cos((-0.5 * eps))) - (Math.sin(t_0) * Math.sin((-0.5 * eps))));
}
def code(x, eps):
	t_0 = (x + x) * -0.5
	return (math.sin((0.5 * (eps - 0.0))) * 2.0) * ((math.cos(t_0) * math.cos((-0.5 * eps))) - (math.sin(t_0) * math.sin((-0.5 * eps))))
function code(x, eps)
	t_0 = Float64(Float64(x + x) * -0.5)
	return Float64(Float64(sin(Float64(0.5 * Float64(eps - 0.0))) * 2.0) * Float64(Float64(cos(t_0) * cos(Float64(-0.5 * eps))) - Float64(sin(t_0) * sin(Float64(-0.5 * eps)))))
end
function tmp = code(x, eps)
	t_0 = (x + x) * -0.5;
	tmp = (sin((0.5 * (eps - 0.0))) * 2.0) * ((cos(t_0) * cos((-0.5 * eps))) - (sin(t_0) * sin((-0.5 * eps))));
end
code[x_, eps_] := Block[{t$95$0 = N[(N[(x + x), $MachinePrecision] * -0.5), $MachinePrecision]}, N[(N[(N[Sin[N[(0.5 * N[(eps - 0.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * N[(N[(N[Cos[t$95$0], $MachinePrecision] * N[Cos[N[(-0.5 * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[t$95$0], $MachinePrecision] * N[Sin[N[(-0.5 * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left(x + x\right) \cdot -0.5\\
\left(\sin \left(0.5 \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \left(\cos t\_0 \cdot \cos \left(-0.5 \cdot \varepsilon\right) - \sin t\_0 \cdot \sin \left(-0.5 \cdot \varepsilon\right)\right)
\end{array}
Derivation
  1. Initial program 62.6%

    \[\sin \left(x + \varepsilon\right) - \sin x \]
  2. 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. mult-flipN/A

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

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

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

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

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

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \color{blue}{\left(\varepsilon - \left(\mathsf{neg}\left(\left(x - x\right)\right)\right)\right)}\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
    18. sub-negate-revN/A

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - \color{blue}{0}\right)\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
  3. Applied rewrites99.9%

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \color{blue}{\cos \left(\mathsf{fma}\left(2, x, \varepsilon\right) \cdot \frac{-1}{2}\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \cos \color{blue}{\left(\mathsf{fma}\left(2, x, \varepsilon\right) \cdot \frac{-1}{2}\right)} \]
    3. *-commutativeN/A

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \cos \left(\frac{-1}{2} \cdot \color{blue}{\left(2 \cdot x + \varepsilon\right)}\right) \]
    5. distribute-rgt-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \left(\sin \left(0.5 \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \color{blue}{\left(\cos \left(\left(x + x\right) \cdot -0.5\right) \cdot \cos \left(-0.5 \cdot \varepsilon\right) - \sin \left(\left(x + x\right) \cdot -0.5\right) \cdot \sin \left(-0.5 \cdot \varepsilon\right)\right)} \]
  6. Add Preprocessing

Alternative 2: 99.9% accurate, 0.8× speedup?

\[\left(\sin \left(0.5 \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \sin \left(x + 0.5 \cdot \left(\varepsilon + \pi\right)\right) \]
(FPCore (x eps)
 :precision binary64
 (* (* (sin (* 0.5 (- eps 0.0))) 2.0) (sin (+ x (* 0.5 (+ eps PI))))))
double code(double x, double eps) {
	return (sin((0.5 * (eps - 0.0))) * 2.0) * sin((x + (0.5 * (eps + ((double) M_PI)))));
}
public static double code(double x, double eps) {
	return (Math.sin((0.5 * (eps - 0.0))) * 2.0) * Math.sin((x + (0.5 * (eps + Math.PI))));
}
def code(x, eps):
	return (math.sin((0.5 * (eps - 0.0))) * 2.0) * math.sin((x + (0.5 * (eps + math.pi))))
function code(x, eps)
	return Float64(Float64(sin(Float64(0.5 * Float64(eps - 0.0))) * 2.0) * sin(Float64(x + Float64(0.5 * Float64(eps + pi)))))
end
function tmp = code(x, eps)
	tmp = (sin((0.5 * (eps - 0.0))) * 2.0) * sin((x + (0.5 * (eps + pi))));
end
code[x_, eps_] := N[(N[(N[Sin[N[(0.5 * N[(eps - 0.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] * N[Sin[N[(x + N[(0.5 * N[(eps + Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\left(\sin \left(0.5 \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \sin \left(x + 0.5 \cdot \left(\varepsilon + \pi\right)\right)
Derivation
  1. Initial program 62.6%

    \[\sin \left(x + \varepsilon\right) - \sin x \]
  2. 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. mult-flipN/A

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

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

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

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

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

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \color{blue}{\left(\varepsilon - \left(\mathsf{neg}\left(\left(x - x\right)\right)\right)\right)}\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
    18. sub-negate-revN/A

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - \color{blue}{0}\right)\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
  3. Applied rewrites99.9%

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\mathsf{fma}\left(2, x, \varepsilon\right) \cdot \frac{-1}{2}\right)\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\mathsf{fma}\left(2, x, \varepsilon\right) \cdot \frac{-1}{2}}\right)\right) \]
    4. distribute-rgt-neg-inN/A

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

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

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \cos \left(\color{blue}{\left(\left(x + \varepsilon\right) + x\right)} \cdot \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right) \]
    9. metadata-evalN/A

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

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - 0\right)\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-sin.f64N/A

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

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

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

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \sin \left(\frac{\mathsf{fma}\left(2, x, \varepsilon\right)}{2} + \frac{\color{blue}{\pi}}{2}\right) \]
    19. div-add-revN/A

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \sin \color{blue}{\left(\frac{\mathsf{fma}\left(2, x, \varepsilon\right) + \pi}{2}\right)} \]
  5. Applied rewrites99.9%

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

    \[\leadsto \left(\sin \left(0.5 \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \sin \color{blue}{\left(x + \frac{1}{2} \cdot \left(\varepsilon + \pi\right)\right)} \]
  7. Step-by-step derivation
    1. lower-+.f64N/A

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \sin \left(x + \frac{1}{2} \cdot \left(\varepsilon + \color{blue}{\mathsf{PI}\left(\right)}\right)\right) \]
    4. lower-PI.f6499.9%

      \[\leadsto \left(\sin \left(0.5 \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \sin \left(x + 0.5 \cdot \left(\varepsilon + \pi\right)\right) \]
  8. Applied rewrites99.9%

    \[\leadsto \left(\sin \left(0.5 \cdot \left(\varepsilon - 0\right)\right) \cdot 2\right) \cdot \sin \color{blue}{\left(x + 0.5 \cdot \left(\varepsilon + \pi\right)\right)} \]
  9. Add Preprocessing

Alternative 3: 99.9% accurate, 0.8× speedup?

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

    \[\sin \left(x + \varepsilon\right) - \sin x \]
  2. 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. mult-flipN/A

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

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

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

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

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

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \color{blue}{\left(\varepsilon - \left(\mathsf{neg}\left(\left(x - x\right)\right)\right)\right)}\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
    18. sub-negate-revN/A

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - \color{blue}{0}\right)\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
  3. Applied rewrites99.9%

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

Alternative 4: 99.7% accurate, 1.3× speedup?

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

    \[\sin \left(x + \varepsilon\right) - \sin x \]
  2. 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. mult-flipN/A

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

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

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

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

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

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \color{blue}{\left(\varepsilon - \left(\mathsf{neg}\left(\left(x - x\right)\right)\right)\right)}\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
    18. sub-negate-revN/A

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - \color{blue}{0}\right)\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
  3. Applied rewrites99.9%

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

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

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

      \[\leadsto \left(\varepsilon \cdot \left(1 + \color{blue}{\frac{-1}{24} \cdot {\varepsilon}^{2}}\right)\right) \cdot \cos \left(\mathsf{fma}\left(2, x, \varepsilon\right) \cdot \frac{-1}{2}\right) \]
    3. lower-*.f64N/A

      \[\leadsto \left(\varepsilon \cdot \left(1 + \frac{-1}{24} \cdot \color{blue}{{\varepsilon}^{2}}\right)\right) \cdot \cos \left(\mathsf{fma}\left(2, x, \varepsilon\right) \cdot \frac{-1}{2}\right) \]
    4. lower-pow.f6499.7%

      \[\leadsto \left(\varepsilon \cdot \left(1 + -0.041666666666666664 \cdot {\varepsilon}^{\color{blue}{2}}\right)\right) \cdot \cos \left(\mathsf{fma}\left(2, x, \varepsilon\right) \cdot -0.5\right) \]
  6. Applied rewrites99.7%

    \[\leadsto \color{blue}{\left(\varepsilon \cdot \left(1 + -0.041666666666666664 \cdot {\varepsilon}^{2}\right)\right)} \cdot \cos \left(\mathsf{fma}\left(2, x, \varepsilon\right) \cdot -0.5\right) \]
  7. Applied rewrites99.7%

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

Alternative 5: 99.4% accurate, 1.4× speedup?

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

    \[\sin \left(x + \varepsilon\right) - \sin x \]
  2. 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. mult-flipN/A

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

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

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

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

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

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \color{blue}{\left(\varepsilon - \left(\mathsf{neg}\left(\left(x - x\right)\right)\right)\right)}\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
    18. sub-negate-revN/A

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

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

      \[\leadsto \left(\sin \left(\frac{1}{2} \cdot \left(\varepsilon - \color{blue}{0}\right)\right) \cdot 2\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right) \]
  3. Applied rewrites99.9%

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

    \[\leadsto \left(\color{blue}{\left(\frac{1}{2} \cdot \varepsilon\right)} \cdot 2\right) \cdot \cos \left(\mathsf{fma}\left(2, x, \varepsilon\right) \cdot -0.5\right) \]
  5. Step-by-step derivation
    1. lower-*.f6499.4%

      \[\leadsto \left(\left(0.5 \cdot \color{blue}{\varepsilon}\right) \cdot 2\right) \cdot \cos \left(\mathsf{fma}\left(2, x, \varepsilon\right) \cdot -0.5\right) \]
  6. Applied rewrites99.4%

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

Alternative 6: 98.9% accurate, 1.6× speedup?

\[\varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot x\right)\right) \]
(FPCore (x eps) :precision binary64 (* eps (+ (cos x) (* -0.5 (* eps x)))))
double code(double x, double eps) {
	return eps * (cos(x) + (-0.5 * (eps * 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 = eps * (cos(x) + ((-0.5d0) * (eps * x)))
end function
public static double code(double x, double eps) {
	return eps * (Math.cos(x) + (-0.5 * (eps * x)));
}
def code(x, eps):
	return eps * (math.cos(x) + (-0.5 * (eps * x)))
function code(x, eps)
	return Float64(eps * Float64(cos(x) + Float64(-0.5 * Float64(eps * x))))
end
function tmp = code(x, eps)
	tmp = eps * (cos(x) + (-0.5 * (eps * x)));
end
code[x_, eps_] := N[(eps * N[(N[Cos[x], $MachinePrecision] + N[(-0.5 * N[(eps * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot x\right)\right)
Derivation
  1. Initial program 62.6%

    \[\sin \left(x + \varepsilon\right) - \sin x \]
  2. 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)} \]
  3. Step-by-step derivation
    1. lower-*.f64N/A

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

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

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

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

      \[\leadsto \varepsilon \cdot \left(\cos x + \frac{-1}{2} \cdot \left(\varepsilon \cdot \color{blue}{\sin x}\right)\right) \]
    6. lower-sin.f6499.4%

      \[\leadsto \varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot \sin x\right)\right) \]
  4. Applied rewrites99.4%

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

    \[\leadsto \varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot \color{blue}{x}\right)\right) \]
  6. Step-by-step derivation
    1. lower-*.f6498.9%

      \[\leadsto \varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot x\right)\right) \]
  7. Applied rewrites98.9%

    \[\leadsto \varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot \color{blue}{x}\right)\right) \]
  8. Add Preprocessing

Alternative 7: 98.9% accurate, 1.9× speedup?

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

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

    \[\leadsto \color{blue}{\varepsilon \cdot \cos x} \]
  3. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto \varepsilon \cdot \color{blue}{\cos x} \]
    2. lower-cos.f6498.9%

      \[\leadsto \varepsilon \cdot \cos x \]
  4. Applied rewrites98.9%

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

Alternative 8: 98.3% accurate, 2.1× speedup?

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

    \[\sin \left(x + \varepsilon\right) - \sin x \]
  2. 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)} \]
  3. Step-by-step derivation
    1. lower-*.f64N/A

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

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

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

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

      \[\leadsto \varepsilon \cdot \left(\cos x + \frac{-1}{2} \cdot \left(\varepsilon \cdot \color{blue}{\sin x}\right)\right) \]
    6. lower-sin.f6499.4%

      \[\leadsto \varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot \sin x\right)\right) \]
  4. Applied rewrites99.4%

    \[\leadsto \color{blue}{\varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot \sin x\right)\right)} \]
  5. 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)} \]
  6. Step-by-step derivation
    1. lower-+.f64N/A

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

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

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

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

      \[\leadsto \varepsilon + x \cdot \mathsf{fma}\left(\frac{-1}{2}, \varepsilon \cdot x, \frac{-1}{2} \cdot {\varepsilon}^{2}\right) \]
    6. lower-pow.f6498.3%

      \[\leadsto \varepsilon + x \cdot \mathsf{fma}\left(-0.5, \varepsilon \cdot x, -0.5 \cdot {\varepsilon}^{2}\right) \]
  7. Applied rewrites98.3%

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

Alternative 9: 98.2% accurate, 5.6× speedup?

\[\left(\left(-0.5 \cdot x\right) \cdot x - -1\right) \cdot \varepsilon \]
(FPCore (x eps) :precision binary64 (* (- (* (* -0.5 x) x) -1.0) eps))
double code(double x, double eps) {
	return (((-0.5 * x) * x) - -1.0) * 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 = ((((-0.5d0) * x) * x) - (-1.0d0)) * eps
end function
public static double code(double x, double eps) {
	return (((-0.5 * x) * x) - -1.0) * eps;
}
def code(x, eps):
	return (((-0.5 * x) * x) - -1.0) * eps
function code(x, eps)
	return Float64(Float64(Float64(Float64(-0.5 * x) * x) - -1.0) * eps)
end
function tmp = code(x, eps)
	tmp = (((-0.5 * x) * x) - -1.0) * eps;
end
code[x_, eps_] := N[(N[(N[(N[(-0.5 * x), $MachinePrecision] * x), $MachinePrecision] - -1.0), $MachinePrecision] * eps), $MachinePrecision]
\left(\left(-0.5 \cdot x\right) \cdot x - -1\right) \cdot \varepsilon
Derivation
  1. Initial program 62.6%

    \[\sin \left(x + \varepsilon\right) - \sin x \]
  2. 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)} \]
  3. Step-by-step derivation
    1. lower-*.f64N/A

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

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

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

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

      \[\leadsto \varepsilon \cdot \left(\cos x + \frac{-1}{2} \cdot \left(\varepsilon \cdot \color{blue}{\sin x}\right)\right) \]
    6. lower-sin.f6499.4%

      \[\leadsto \varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot \sin x\right)\right) \]
  4. Applied rewrites99.4%

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

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

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

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

      \[\leadsto \varepsilon \cdot \left(1 + x \cdot \mathsf{fma}\left(\frac{-1}{2}, \varepsilon, x \cdot \left(\frac{1}{12} \cdot \left(\varepsilon \cdot x\right) - \frac{1}{2}\right)\right)\right) \]
    4. lower-*.f64N/A

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

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

      \[\leadsto \varepsilon \cdot \left(1 + x \cdot \mathsf{fma}\left(\frac{-1}{2}, \varepsilon, x \cdot \left(\frac{1}{12} \cdot \left(\varepsilon \cdot x\right) - \frac{1}{2}\right)\right)\right) \]
    7. lower-*.f6498.2%

      \[\leadsto \varepsilon \cdot \left(1 + x \cdot \mathsf{fma}\left(-0.5, \varepsilon, x \cdot \left(0.08333333333333333 \cdot \left(\varepsilon \cdot x\right) - 0.5\right)\right)\right) \]
  7. Applied rewrites98.2%

    \[\leadsto \varepsilon \cdot \left(1 + \color{blue}{x \cdot \mathsf{fma}\left(-0.5, \varepsilon, x \cdot \left(0.08333333333333333 \cdot \left(\varepsilon \cdot x\right) - 0.5\right)\right)}\right) \]
  8. Taylor expanded in eps around 0

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

      \[\leadsto \varepsilon \cdot \left(1 + \frac{-1}{2} \cdot {x}^{2}\right) \]
    2. lower-pow.f6498.2%

      \[\leadsto \varepsilon \cdot \left(1 + -0.5 \cdot {x}^{2}\right) \]
  10. Applied rewrites98.2%

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

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

      \[\leadsto \left(1 + \frac{-1}{2} \cdot {x}^{2}\right) \cdot \color{blue}{\varepsilon} \]
    3. lower-*.f6498.2%

      \[\leadsto \left(1 + -0.5 \cdot {x}^{2}\right) \cdot \color{blue}{\varepsilon} \]
  12. Applied rewrites98.2%

    \[\leadsto \left(\left(-0.5 \cdot x\right) \cdot x - -1\right) \cdot \color{blue}{\varepsilon} \]
  13. Add Preprocessing

Alternative 10: 97.8% accurate, 69.8× speedup?

\[\varepsilon \]
(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
\varepsilon
Derivation
  1. Initial program 62.6%

    \[\sin \left(x + \varepsilon\right) - \sin x \]
  2. 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)} \]
  3. Step-by-step derivation
    1. lower-*.f64N/A

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

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

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

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

      \[\leadsto \varepsilon \cdot \left(\cos x + \frac{-1}{2} \cdot \left(\varepsilon \cdot \color{blue}{\sin x}\right)\right) \]
    6. lower-sin.f6499.4%

      \[\leadsto \varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot \sin x\right)\right) \]
  4. Applied rewrites99.4%

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

    \[\leadsto \varepsilon \cdot 1 \]
  6. Step-by-step derivation
    1. Applied rewrites97.8%

      \[\leadsto \varepsilon \cdot 1 \]
    2. Taylor expanded in x around 0

      \[\leadsto \varepsilon \]
    3. Step-by-step derivation
      1. Applied rewrites97.8%

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

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

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

      Developer Target 2: 99.6% accurate, 0.5× speedup?

      \[\sin x \cdot \left(\cos \varepsilon - 1\right) + \cos x \cdot \sin \varepsilon \]
      (FPCore (x eps)
       :precision binary64
       (+ (* (sin x) (- (cos eps) 1.0)) (* (cos x) (sin eps))))
      double code(double x, double eps) {
      	return (sin(x) * (cos(eps) - 1.0)) + (cos(x) * sin(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 = (sin(x) * (cos(eps) - 1.0d0)) + (cos(x) * sin(eps))
      end function
      
      public static double code(double x, double eps) {
      	return (Math.sin(x) * (Math.cos(eps) - 1.0)) + (Math.cos(x) * Math.sin(eps));
      }
      
      def code(x, eps):
      	return (math.sin(x) * (math.cos(eps) - 1.0)) + (math.cos(x) * math.sin(eps))
      
      function code(x, eps)
      	return Float64(Float64(sin(x) * Float64(cos(eps) - 1.0)) + Float64(cos(x) * sin(eps)))
      end
      
      function tmp = code(x, eps)
      	tmp = (sin(x) * (cos(eps) - 1.0)) + (cos(x) * sin(eps));
      end
      
      code[x_, eps_] := N[(N[(N[Sin[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
      
      \sin x \cdot \left(\cos \varepsilon - 1\right) + \cos x \cdot \sin \varepsilon
      

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

      \[\left(\cos \left(0.5 \cdot \left(\varepsilon - -2 \cdot x\right)\right) \cdot \sin \left(0.5 \cdot \varepsilon\right)\right) \cdot 2 \]
      (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]
      
      \left(\cos \left(0.5 \cdot \left(\varepsilon - -2 \cdot x\right)\right) \cdot \sin \left(0.5 \cdot \varepsilon\right)\right) \cdot 2
      

      Reproduce

      ?
      herbie shell --seed 2025191 
      (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 c (* 2 (cos (+ x (/ eps 2))) (sin (/ eps 2))))
      
        :alt
        (! :herbie-platform c (+ (* (sin x) (- (cos eps) 1)) (* (cos x) (sin eps))))
      
        :alt
        (! :herbie-platform c (* (cos (* 1/2 (- eps (* -2 x)))) (sin (* 1/2 eps)) 2))
      
        (- (sin (+ x eps)) (sin x)))