2sin (example 3.3)

Percentage Accurate: 62.8% → 100.0%
Time: 13.1s
Alternatives: 9
Speedup: 205.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);
}
real(8) function code(x, eps)
    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 9 alternatives:

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

Initial Program: 62.8% 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);
}
real(8) function code(x, eps)
    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: 100.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\ 2 \cdot \left(t\_0 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\varepsilon \cdot 0.5\right) \cdot \cos x - t\_0 \cdot \sin x\right)\right)\right) \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (sin (* eps 0.5))))
   (*
    2.0
    (*
     t_0
     (log1p (expm1 (- (* (cos (* eps 0.5)) (cos x)) (* t_0 (sin x)))))))))
double code(double x, double eps) {
	double t_0 = sin((eps * 0.5));
	return 2.0 * (t_0 * log1p(expm1(((cos((eps * 0.5)) * cos(x)) - (t_0 * sin(x))))));
}
public static double code(double x, double eps) {
	double t_0 = Math.sin((eps * 0.5));
	return 2.0 * (t_0 * Math.log1p(Math.expm1(((Math.cos((eps * 0.5)) * Math.cos(x)) - (t_0 * Math.sin(x))))));
}
def code(x, eps):
	t_0 = math.sin((eps * 0.5))
	return 2.0 * (t_0 * math.log1p(math.expm1(((math.cos((eps * 0.5)) * math.cos(x)) - (t_0 * math.sin(x))))))
function code(x, eps)
	t_0 = sin(Float64(eps * 0.5))
	return Float64(2.0 * Float64(t_0 * log1p(expm1(Float64(Float64(cos(Float64(eps * 0.5)) * cos(x)) - Float64(t_0 * sin(x)))))))
end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(2.0 * N[(t$95$0 * N[Log[1 + N[(Exp[N[(N[(N[Cos[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
2 \cdot \left(t\_0 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\varepsilon \cdot 0.5\right) \cdot \cos x - t\_0 \cdot \sin x\right)\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 62.7%

    \[\sin \left(x + \varepsilon\right) - \sin x \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. diff-sin62.8%

      \[\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)} \]
    2. div-inv62.8%

      \[\leadsto 2 \cdot \left(\sin \color{blue}{\left(\left(\left(x + \varepsilon\right) - x\right) \cdot \frac{1}{2}\right)} \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right) \]
    3. associate--l+62.8%

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

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot \color{blue}{0.5}\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right) \]
    5. div-inv62.8%

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

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\color{blue}{\left(\varepsilon + x\right)} + x\right) \cdot \frac{1}{2}\right)\right) \]
    7. associate-+l+62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot 0.5\right) \cdot \cos \left(\color{blue}{\left(\varepsilon + \left(x + x\right)\right)} \cdot \frac{1}{2}\right)\right) \]
    8. metadata-eval62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot \color{blue}{0.5}\right)\right) \]
  4. Applied egg-rr62.8%

    \[\leadsto \color{blue}{2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right)} \]
  5. Step-by-step derivation
    1. sub-neg62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \color{blue}{\left(\varepsilon + \left(-x\right)\right)}\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    2. mul-1-neg62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon + \color{blue}{-1 \cdot x}\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    3. +-commutative62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \color{blue}{\left(-1 \cdot x + \varepsilon\right)}\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    4. associate-+r+99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\color{blue}{\left(\left(x + -1 \cdot x\right) + \varepsilon\right)} \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    5. mul-1-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(\left(x + \color{blue}{\left(-x\right)}\right) + \varepsilon\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    6. sub-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(\color{blue}{\left(x - x\right)} + \varepsilon\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    7. +-inverses99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(\color{blue}{0} + \varepsilon\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    8. remove-double-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(0 + \color{blue}{\left(-\left(-\varepsilon\right)\right)}\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    9. mul-1-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(0 + \left(-\color{blue}{-1 \cdot \varepsilon}\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    10. sub-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\color{blue}{\left(0 - -1 \cdot \varepsilon\right)} \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    11. neg-sub099.9%

      \[\leadsto 2 \cdot \left(\sin \left(\color{blue}{\left(--1 \cdot \varepsilon\right)} \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    12. mul-1-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(-\color{blue}{\left(-\varepsilon\right)}\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    13. remove-double-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\color{blue}{\varepsilon} \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    14. *-commutative99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \color{blue}{\left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)}\right) \]
    15. +-commutative99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \color{blue}{\left(\left(x + x\right) + \varepsilon\right)}\right)\right) \]
    16. count-299.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \left(\color{blue}{2 \cdot x} + \varepsilon\right)\right)\right) \]
    17. fma-define99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(2, x, \varepsilon\right)}\right)\right) \]
  6. Simplified99.9%

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

    \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \color{blue}{\cos \left(0.5 \cdot \left(\varepsilon - -2 \cdot x\right)\right)}\right) \]
  8. Step-by-step derivation
    1. log1p-expm1-u99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\varepsilon - -2 \cdot x\right)\right)\right)\right)}\right) \]
    2. sub-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \color{blue}{\left(\varepsilon + \left(--2 \cdot x\right)\right)}\right)\right)\right)\right) \]
    3. *-commutative99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\varepsilon + \left(-\color{blue}{x \cdot -2}\right)\right)\right)\right)\right)\right) \]
    4. distribute-rgt-neg-in99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\varepsilon + \color{blue}{x \cdot \left(--2\right)}\right)\right)\right)\right)\right) \]
    5. metadata-eval99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\varepsilon + x \cdot \color{blue}{2}\right)\right)\right)\right)\right) \]
  9. Applied egg-rr99.9%

    \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\varepsilon + x \cdot 2\right)\right)\right)\right)}\right) \]
  10. Step-by-step derivation
    1. distribute-lft-in99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \color{blue}{\left(0.5 \cdot \varepsilon + 0.5 \cdot \left(x \cdot 2\right)\right)}\right)\right)\right) \]
    2. cos-sum100.0%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos \left(0.5 \cdot \varepsilon\right) \cdot \cos \left(0.5 \cdot \left(x \cdot 2\right)\right) - \sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \left(x \cdot 2\right)\right)}\right)\right)\right) \]
    3. *-commutative100.0%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \varepsilon\right) \cdot \cos \left(0.5 \cdot \color{blue}{\left(2 \cdot x\right)}\right) - \sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \left(x \cdot 2\right)\right)\right)\right)\right) \]
    4. associate-*r*100.0%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \varepsilon\right) \cdot \cos \color{blue}{\left(\left(0.5 \cdot 2\right) \cdot x\right)} - \sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \left(x \cdot 2\right)\right)\right)\right)\right) \]
    5. metadata-eval100.0%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \varepsilon\right) \cdot \cos \left(\color{blue}{1} \cdot x\right) - \sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \left(x \cdot 2\right)\right)\right)\right)\right) \]
    6. *-un-lft-identity100.0%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \varepsilon\right) \cdot \cos \color{blue}{x} - \sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \left(x \cdot 2\right)\right)\right)\right)\right) \]
    7. *-commutative100.0%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \varepsilon\right) \cdot \cos x - \sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \color{blue}{\left(2 \cdot x\right)}\right)\right)\right)\right) \]
    8. associate-*r*100.0%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \varepsilon\right) \cdot \cos x - \sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \color{blue}{\left(\left(0.5 \cdot 2\right) \cdot x\right)}\right)\right)\right) \]
    9. metadata-eval100.0%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \varepsilon\right) \cdot \cos x - \sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(\color{blue}{1} \cdot x\right)\right)\right)\right) \]
    10. *-un-lft-identity100.0%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \varepsilon\right) \cdot \cos x - \sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \color{blue}{x}\right)\right)\right) \]
  11. Applied egg-rr100.0%

    \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos \left(0.5 \cdot \varepsilon\right) \cdot \cos x - \sin \left(0.5 \cdot \varepsilon\right) \cdot \sin x}\right)\right)\right) \]
  12. Final simplification100.0%

    \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(\varepsilon \cdot 0.5\right) \cdot \cos x - \sin \left(\varepsilon \cdot 0.5\right) \cdot \sin x\right)\right)\right) \]
  13. Add Preprocessing

Alternative 2: 99.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\varepsilon + 2 \cdot x\right)\right)\right)\right)\right) \end{array} \]
(FPCore (x eps)
 :precision binary64
 (* 2.0 (* (sin (* eps 0.5)) (log1p (expm1 (cos (* 0.5 (+ eps (* 2.0 x)))))))))
double code(double x, double eps) {
	return 2.0 * (sin((eps * 0.5)) * log1p(expm1(cos((0.5 * (eps + (2.0 * x)))))));
}
public static double code(double x, double eps) {
	return 2.0 * (Math.sin((eps * 0.5)) * Math.log1p(Math.expm1(Math.cos((0.5 * (eps + (2.0 * x)))))));
}
def code(x, eps):
	return 2.0 * (math.sin((eps * 0.5)) * math.log1p(math.expm1(math.cos((0.5 * (eps + (2.0 * x)))))))
function code(x, eps)
	return Float64(2.0 * Float64(sin(Float64(eps * 0.5)) * log1p(expm1(cos(Float64(0.5 * Float64(eps + Float64(2.0 * x))))))))
end
code[x_, eps_] := N[(2.0 * N[(N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision] * N[Log[1 + N[(Exp[N[Cos[N[(0.5 * N[(eps + N[(2.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\varepsilon + 2 \cdot x\right)\right)\right)\right)\right)
\end{array}
Derivation
  1. Initial program 62.7%

    \[\sin \left(x + \varepsilon\right) - \sin x \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. diff-sin62.8%

      \[\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)} \]
    2. div-inv62.8%

      \[\leadsto 2 \cdot \left(\sin \color{blue}{\left(\left(\left(x + \varepsilon\right) - x\right) \cdot \frac{1}{2}\right)} \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right) \]
    3. associate--l+62.8%

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

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot \color{blue}{0.5}\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right) \]
    5. div-inv62.8%

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

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\color{blue}{\left(\varepsilon + x\right)} + x\right) \cdot \frac{1}{2}\right)\right) \]
    7. associate-+l+62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot 0.5\right) \cdot \cos \left(\color{blue}{\left(\varepsilon + \left(x + x\right)\right)} \cdot \frac{1}{2}\right)\right) \]
    8. metadata-eval62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot \color{blue}{0.5}\right)\right) \]
  4. Applied egg-rr62.8%

    \[\leadsto \color{blue}{2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right)} \]
  5. Step-by-step derivation
    1. sub-neg62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \color{blue}{\left(\varepsilon + \left(-x\right)\right)}\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    2. mul-1-neg62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon + \color{blue}{-1 \cdot x}\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    3. +-commutative62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \color{blue}{\left(-1 \cdot x + \varepsilon\right)}\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    4. associate-+r+99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\color{blue}{\left(\left(x + -1 \cdot x\right) + \varepsilon\right)} \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    5. mul-1-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(\left(x + \color{blue}{\left(-x\right)}\right) + \varepsilon\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    6. sub-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(\color{blue}{\left(x - x\right)} + \varepsilon\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    7. +-inverses99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(\color{blue}{0} + \varepsilon\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    8. remove-double-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(0 + \color{blue}{\left(-\left(-\varepsilon\right)\right)}\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    9. mul-1-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(0 + \left(-\color{blue}{-1 \cdot \varepsilon}\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    10. sub-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\color{blue}{\left(0 - -1 \cdot \varepsilon\right)} \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    11. neg-sub099.9%

      \[\leadsto 2 \cdot \left(\sin \left(\color{blue}{\left(--1 \cdot \varepsilon\right)} \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    12. mul-1-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(-\color{blue}{\left(-\varepsilon\right)}\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    13. remove-double-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\color{blue}{\varepsilon} \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    14. *-commutative99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \color{blue}{\left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)}\right) \]
    15. +-commutative99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \color{blue}{\left(\left(x + x\right) + \varepsilon\right)}\right)\right) \]
    16. count-299.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \left(\color{blue}{2 \cdot x} + \varepsilon\right)\right)\right) \]
    17. fma-define99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(2, x, \varepsilon\right)}\right)\right) \]
  6. Simplified99.9%

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

    \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \color{blue}{\cos \left(0.5 \cdot \left(\varepsilon - -2 \cdot x\right)\right)}\right) \]
  8. Step-by-step derivation
    1. log1p-expm1-u99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\varepsilon - -2 \cdot x\right)\right)\right)\right)}\right) \]
    2. sub-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \color{blue}{\left(\varepsilon + \left(--2 \cdot x\right)\right)}\right)\right)\right)\right) \]
    3. *-commutative99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\varepsilon + \left(-\color{blue}{x \cdot -2}\right)\right)\right)\right)\right)\right) \]
    4. distribute-rgt-neg-in99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\varepsilon + \color{blue}{x \cdot \left(--2\right)}\right)\right)\right)\right)\right) \]
    5. metadata-eval99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\varepsilon + x \cdot \color{blue}{2}\right)\right)\right)\right)\right) \]
  9. Applied egg-rr99.9%

    \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\varepsilon + x \cdot 2\right)\right)\right)\right)}\right) \]
  10. Final simplification99.9%

    \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(0.5 \cdot \left(\varepsilon + 2 \cdot x\right)\right)\right)\right)\right) \]
  11. Add Preprocessing

Alternative 3: 99.9% accurate, 1.0× speedup?

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

\\
2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right)\right)
\end{array}
Derivation
  1. Initial program 62.7%

    \[\sin \left(x + \varepsilon\right) - \sin x \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. diff-sin62.8%

      \[\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)} \]
    2. div-inv62.8%

      \[\leadsto 2 \cdot \left(\sin \color{blue}{\left(\left(\left(x + \varepsilon\right) - x\right) \cdot \frac{1}{2}\right)} \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right) \]
    3. associate--l+62.8%

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

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot \color{blue}{0.5}\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right) \]
    5. div-inv62.8%

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

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\color{blue}{\left(\varepsilon + x\right)} + x\right) \cdot \frac{1}{2}\right)\right) \]
    7. associate-+l+62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot 0.5\right) \cdot \cos \left(\color{blue}{\left(\varepsilon + \left(x + x\right)\right)} \cdot \frac{1}{2}\right)\right) \]
    8. metadata-eval62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot \color{blue}{0.5}\right)\right) \]
  4. Applied egg-rr62.8%

    \[\leadsto \color{blue}{2 \cdot \left(\sin \left(\left(x + \left(\varepsilon - x\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right)} \]
  5. Step-by-step derivation
    1. sub-neg62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \color{blue}{\left(\varepsilon + \left(-x\right)\right)}\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    2. mul-1-neg62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \left(\varepsilon + \color{blue}{-1 \cdot x}\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    3. +-commutative62.8%

      \[\leadsto 2 \cdot \left(\sin \left(\left(x + \color{blue}{\left(-1 \cdot x + \varepsilon\right)}\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    4. associate-+r+99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\color{blue}{\left(\left(x + -1 \cdot x\right) + \varepsilon\right)} \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    5. mul-1-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(\left(x + \color{blue}{\left(-x\right)}\right) + \varepsilon\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    6. sub-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(\color{blue}{\left(x - x\right)} + \varepsilon\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    7. +-inverses99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(\color{blue}{0} + \varepsilon\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    8. remove-double-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(0 + \color{blue}{\left(-\left(-\varepsilon\right)\right)}\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    9. mul-1-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(0 + \left(-\color{blue}{-1 \cdot \varepsilon}\right)\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    10. sub-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\color{blue}{\left(0 - -1 \cdot \varepsilon\right)} \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    11. neg-sub099.9%

      \[\leadsto 2 \cdot \left(\sin \left(\color{blue}{\left(--1 \cdot \varepsilon\right)} \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    12. mul-1-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\left(-\color{blue}{\left(-\varepsilon\right)}\right) \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    13. remove-double-neg99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\color{blue}{\varepsilon} \cdot 0.5\right) \cdot \cos \left(\left(\varepsilon + \left(x + x\right)\right) \cdot 0.5\right)\right) \]
    14. *-commutative99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \color{blue}{\left(0.5 \cdot \left(\varepsilon + \left(x + x\right)\right)\right)}\right) \]
    15. +-commutative99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \color{blue}{\left(\left(x + x\right) + \varepsilon\right)}\right)\right) \]
    16. count-299.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \left(\color{blue}{2 \cdot x} + \varepsilon\right)\right)\right) \]
    17. fma-define99.9%

      \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(2, x, \varepsilon\right)}\right)\right) \]
  6. Simplified99.9%

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

    \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \color{blue}{\cos \left(0.5 \cdot \left(\varepsilon - -2 \cdot x\right)\right)}\right) \]
  8. Final simplification99.9%

    \[\leadsto 2 \cdot \left(\sin \left(\varepsilon \cdot 0.5\right) \cdot \cos \left(0.5 \cdot \left(\varepsilon - x \cdot -2\right)\right)\right) \]
  9. Add Preprocessing

Alternative 4: 99.5% accurate, 1.0× speedup?

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

\\
\varepsilon \cdot \left(\cos x + \sin x \cdot \left(\varepsilon \cdot -0.5\right)\right)
\end{array}
Derivation
  1. Initial program 62.7%

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

    \[\leadsto \color{blue}{\varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot \sin x\right)\right)} \]
  4. Step-by-step derivation
    1. associate-*r*99.0%

      \[\leadsto \varepsilon \cdot \left(\cos x + \color{blue}{\left(-0.5 \cdot \varepsilon\right) \cdot \sin x}\right) \]
  5. Simplified99.0%

    \[\leadsto \color{blue}{\varepsilon \cdot \left(\cos x + \left(-0.5 \cdot \varepsilon\right) \cdot \sin x\right)} \]
  6. Final simplification99.0%

    \[\leadsto \varepsilon \cdot \left(\cos x + \sin x \cdot \left(\varepsilon \cdot -0.5\right)\right) \]
  7. Add Preprocessing

Alternative 5: 99.1% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \varepsilon \cdot \cos x \end{array} \]
(FPCore (x eps) :precision binary64 (* eps (cos x)))
double code(double x, double eps) {
	return eps * cos(x);
}
real(8) function code(x, eps)
    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]
\begin{array}{l}

\\
\varepsilon \cdot \cos x
\end{array}
Derivation
  1. Initial program 62.7%

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

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

Alternative 6: 98.5% accurate, 10.8× speedup?

\[\begin{array}{l} \\ \varepsilon \cdot \left(1 + x \cdot \left(\varepsilon \cdot -0.5 + x \cdot \left(0.08333333333333333 \cdot \left(\varepsilon \cdot x\right) - 0.5\right)\right)\right) \end{array} \]
(FPCore (x eps)
 :precision binary64
 (*
  eps
  (+
   1.0
   (* x (+ (* eps -0.5) (* x (- (* 0.08333333333333333 (* eps x)) 0.5)))))))
double code(double x, double eps) {
	return eps * (1.0 + (x * ((eps * -0.5) + (x * ((0.08333333333333333 * (eps * x)) - 0.5)))));
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = eps * (1.0d0 + (x * ((eps * (-0.5d0)) + (x * ((0.08333333333333333d0 * (eps * x)) - 0.5d0)))))
end function
public static double code(double x, double eps) {
	return eps * (1.0 + (x * ((eps * -0.5) + (x * ((0.08333333333333333 * (eps * x)) - 0.5)))));
}
def code(x, eps):
	return eps * (1.0 + (x * ((eps * -0.5) + (x * ((0.08333333333333333 * (eps * x)) - 0.5)))))
function code(x, eps)
	return Float64(eps * Float64(1.0 + Float64(x * Float64(Float64(eps * -0.5) + Float64(x * Float64(Float64(0.08333333333333333 * Float64(eps * x)) - 0.5))))))
end
function tmp = code(x, eps)
	tmp = eps * (1.0 + (x * ((eps * -0.5) + (x * ((0.08333333333333333 * (eps * x)) - 0.5)))));
end
code[x_, eps_] := N[(eps * N[(1.0 + N[(x * N[(N[(eps * -0.5), $MachinePrecision] + N[(x * N[(N[(0.08333333333333333 * N[(eps * x), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\varepsilon \cdot \left(1 + x \cdot \left(\varepsilon \cdot -0.5 + x \cdot \left(0.08333333333333333 \cdot \left(\varepsilon \cdot x\right) - 0.5\right)\right)\right)
\end{array}
Derivation
  1. Initial program 62.7%

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

    \[\leadsto \color{blue}{\varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot \sin x\right)\right)} \]
  4. Step-by-step derivation
    1. associate-*r*99.0%

      \[\leadsto \varepsilon \cdot \left(\cos x + \color{blue}{\left(-0.5 \cdot \varepsilon\right) \cdot \sin x}\right) \]
  5. Simplified99.0%

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

    \[\leadsto \varepsilon \cdot \color{blue}{\left(1 + x \cdot \left(-0.5 \cdot \varepsilon + x \cdot \left(0.08333333333333333 \cdot \left(\varepsilon \cdot x\right) - 0.5\right)\right)\right)} \]
  7. Final simplification97.9%

    \[\leadsto \varepsilon \cdot \left(1 + x \cdot \left(\varepsilon \cdot -0.5 + x \cdot \left(0.08333333333333333 \cdot \left(\varepsilon \cdot x\right) - 0.5\right)\right)\right) \]
  8. Add Preprocessing

Alternative 7: 98.5% accurate, 18.6× speedup?

\[\begin{array}{l} \\ \varepsilon \cdot \left(1 + x \cdot \left(-0.5 \cdot \left(\varepsilon + x\right)\right)\right) \end{array} \]
(FPCore (x eps) :precision binary64 (* eps (+ 1.0 (* x (* -0.5 (+ eps x))))))
double code(double x, double eps) {
	return eps * (1.0 + (x * (-0.5 * (eps + x))));
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = eps * (1.0d0 + (x * ((-0.5d0) * (eps + x))))
end function
public static double code(double x, double eps) {
	return eps * (1.0 + (x * (-0.5 * (eps + x))));
}
def code(x, eps):
	return eps * (1.0 + (x * (-0.5 * (eps + x))))
function code(x, eps)
	return Float64(eps * Float64(1.0 + Float64(x * Float64(-0.5 * Float64(eps + x)))))
end
function tmp = code(x, eps)
	tmp = eps * (1.0 + (x * (-0.5 * (eps + x))));
end
code[x_, eps_] := N[(eps * N[(1.0 + N[(x * N[(-0.5 * N[(eps + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\varepsilon \cdot \left(1 + x \cdot \left(-0.5 \cdot \left(\varepsilon + x\right)\right)\right)
\end{array}
Derivation
  1. Initial program 62.7%

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

    \[\leadsto \color{blue}{\varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot \sin x\right)\right)} \]
  4. Step-by-step derivation
    1. associate-*r*99.0%

      \[\leadsto \varepsilon \cdot \left(\cos x + \color{blue}{\left(-0.5 \cdot \varepsilon\right) \cdot \sin x}\right) \]
  5. Simplified99.0%

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

    \[\leadsto \varepsilon \cdot \color{blue}{\left(1 + x \cdot \left(-0.5 \cdot \varepsilon + -0.5 \cdot x\right)\right)} \]
  7. Step-by-step derivation
    1. distribute-lft-out97.8%

      \[\leadsto \varepsilon \cdot \left(1 + x \cdot \color{blue}{\left(-0.5 \cdot \left(\varepsilon + x\right)\right)}\right) \]
  8. Simplified97.8%

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

Alternative 8: 98.5% accurate, 22.8× speedup?

\[\begin{array}{l} \\ \varepsilon \cdot \left(1 + x \cdot \left(x \cdot -0.5\right)\right) \end{array} \]
(FPCore (x eps) :precision binary64 (* eps (+ 1.0 (* x (* x -0.5)))))
double code(double x, double eps) {
	return eps * (1.0 + (x * (x * -0.5)));
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = eps * (1.0d0 + (x * (x * (-0.5d0))))
end function
public static double code(double x, double eps) {
	return eps * (1.0 + (x * (x * -0.5)));
}
def code(x, eps):
	return eps * (1.0 + (x * (x * -0.5)))
function code(x, eps)
	return Float64(eps * Float64(1.0 + Float64(x * Float64(x * -0.5))))
end
function tmp = code(x, eps)
	tmp = eps * (1.0 + (x * (x * -0.5)));
end
code[x_, eps_] := N[(eps * N[(1.0 + N[(x * N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\varepsilon \cdot \left(1 + x \cdot \left(x \cdot -0.5\right)\right)
\end{array}
Derivation
  1. Initial program 62.7%

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

    \[\leadsto \color{blue}{\varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot \sin x\right)\right)} \]
  4. Step-by-step derivation
    1. associate-*r*99.0%

      \[\leadsto \varepsilon \cdot \left(\cos x + \color{blue}{\left(-0.5 \cdot \varepsilon\right) \cdot \sin x}\right) \]
  5. Simplified99.0%

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

    \[\leadsto \varepsilon \cdot \color{blue}{\left(1 + x \cdot \left(-0.5 \cdot \varepsilon + x \cdot \left(0.08333333333333333 \cdot \left(\varepsilon \cdot x\right) - 0.5\right)\right)\right)} \]
  7. Taylor expanded in eps around 0 97.7%

    \[\leadsto \varepsilon \cdot \left(1 + x \cdot \color{blue}{\left(-0.5 \cdot x\right)}\right) \]
  8. Step-by-step derivation
    1. *-commutative97.7%

      \[\leadsto \varepsilon \cdot \left(1 + x \cdot \color{blue}{\left(x \cdot -0.5\right)}\right) \]
  9. Simplified97.7%

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

Alternative 9: 98.1% accurate, 205.0× speedup?

\[\begin{array}{l} \\ \varepsilon \end{array} \]
(FPCore (x eps) :precision binary64 eps)
double code(double x, double eps) {
	return eps;
}
real(8) function code(x, eps)
    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.7%

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

    \[\leadsto \color{blue}{\varepsilon \cdot \left(\cos x + -0.5 \cdot \left(\varepsilon \cdot \sin x\right)\right)} \]
  4. Step-by-step derivation
    1. associate-*r*99.0%

      \[\leadsto \varepsilon \cdot \left(\cos x + \color{blue}{\left(-0.5 \cdot \varepsilon\right) \cdot \sin x}\right) \]
  5. Simplified99.0%

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

    \[\leadsto \varepsilon \cdot \color{blue}{\left(1 + x \cdot \left(-0.5 \cdot \varepsilon + -0.5 \cdot x\right)\right)} \]
  7. Step-by-step derivation
    1. distribute-lft-out97.8%

      \[\leadsto \varepsilon \cdot \left(1 + x \cdot \color{blue}{\left(-0.5 \cdot \left(\varepsilon + x\right)\right)}\right) \]
  8. Simplified97.8%

    \[\leadsto \varepsilon \cdot \color{blue}{\left(1 + x \cdot \left(-0.5 \cdot \left(\varepsilon + x\right)\right)\right)} \]
  9. Taylor expanded in x around 0 97.7%

    \[\leadsto \color{blue}{\varepsilon} \]
  10. Add Preprocessing

Developer target: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(2 \cdot \cos \left(x + \frac{\varepsilon}{2}\right)\right) \cdot \sin \left(\frac{\varepsilon}{2}\right) \end{array} \]
(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));
}
real(8) function code(x, eps)
    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]
\begin{array}{l}

\\
\left(2 \cdot \cos \left(x + \frac{\varepsilon}{2}\right)\right) \cdot \sin \left(\frac{\varepsilon}{2}\right)
\end{array}

Reproduce

?
herbie shell --seed 2024099 
(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
  (* (* 2.0 (cos (+ x (/ eps 2.0)))) (sin (/ eps 2.0)))

  (- (sin (+ x eps)) (sin x)))