expr_51555138

Percentage Accurate: 51.7% → 72.0%
Time: 6.1s
Alternatives: 8
Speedup: 1.5×

Specification

?
\[\begin{array}{l} \\ \tan \left(x + {10}^{\left(-12\right)}\right) - \tan x \end{array} \]
(FPCore (x) :precision binary64 (- (tan (+ x (pow 10.0 (- 12.0)))) (tan x)))
double code(double x) {
	return tan((x + pow(10.0, -12.0))) - tan(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = tan((x + (10.0d0 ** -12.0d0))) - tan(x)
end function
public static double code(double x) {
	return Math.tan((x + Math.pow(10.0, -12.0))) - Math.tan(x);
}
def code(x):
	return math.tan((x + math.pow(10.0, -12.0))) - math.tan(x)
function code(x)
	return Float64(tan(Float64(x + (10.0 ^ Float64(-12.0)))) - tan(x))
end
function tmp = code(x)
	tmp = tan((x + (10.0 ^ -12.0))) - tan(x);
end
code[x_] := N[(N[Tan[N[(x + N[Power[10.0, (-12.0)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\tan \left(x + {10}^{\left(-12\right)}\right) - \tan 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 8 alternatives:

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

Initial Program: 51.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \tan \left(x + {10}^{\left(-12\right)}\right) - \tan x \end{array} \]
(FPCore (x) :precision binary64 (- (tan (+ x (pow 10.0 (- 12.0)))) (tan x)))
double code(double x) {
	return tan((x + pow(10.0, -12.0))) - tan(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = tan((x + (10.0d0 ** -12.0d0))) - tan(x)
end function
public static double code(double x) {
	return Math.tan((x + Math.pow(10.0, -12.0))) - Math.tan(x);
}
def code(x):
	return math.tan((x + math.pow(10.0, -12.0))) - math.tan(x)
function code(x)
	return Float64(tan(Float64(x + (10.0 ^ Float64(-12.0)))) - tan(x))
end
function tmp = code(x)
	tmp = tan((x + (10.0 ^ -12.0))) - tan(x);
end
code[x_] := N[(N[Tan[N[(x + N[Power[10.0, (-12.0)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\tan \left(x + {10}^{\left(-12\right)}\right) - \tan x
\end{array}

Alternative 1: 72.0% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\sin x}{\cos x}\\ t_1 := \mathsf{fma}\left(\frac{-\sin x}{\cos \left( 10^{-12} \right)}, \frac{\sin \left( 10^{-12} \right)}{\cos x}, 1\right)\\ \left(\frac{t\_0}{t\_1} - t\_0\right) + \frac{\frac{\sin \left( 10^{-12} \right)}{\cos \left( 10^{-12} \right)}}{t\_1} \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ (sin x) (cos x)))
        (t_1 (fma (/ (- (sin x)) (cos 1e-12)) (/ (sin 1e-12) (cos x)) 1.0)))
   (+ (- (/ t_0 t_1) t_0) (/ (/ (sin 1e-12) (cos 1e-12)) t_1))))
double code(double x) {
	double t_0 = sin(x) / cos(x);
	double t_1 = fma((-sin(x) / cos(1e-12)), (sin(1e-12) / cos(x)), 1.0);
	return ((t_0 / t_1) - t_0) + ((sin(1e-12) / cos(1e-12)) / t_1);
}
function code(x)
	t_0 = Float64(sin(x) / cos(x))
	t_1 = fma(Float64(Float64(-sin(x)) / cos(1e-12)), Float64(sin(1e-12) / cos(x)), 1.0)
	return Float64(Float64(Float64(t_0 / t_1) - t_0) + Float64(Float64(sin(1e-12) / cos(1e-12)) / t_1))
end
code[x_] := Block[{t$95$0 = N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-N[Sin[x], $MachinePrecision]) / N[Cos[1e-12], $MachinePrecision]), $MachinePrecision] * N[(N[Sin[1e-12], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]}, N[(N[(N[(t$95$0 / t$95$1), $MachinePrecision] - t$95$0), $MachinePrecision] + N[(N[(N[Sin[1e-12], $MachinePrecision] / N[Cos[1e-12], $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\sin x}{\cos x}\\
t_1 := \mathsf{fma}\left(\frac{-\sin x}{\cos \left( 10^{-12} \right)}, \frac{\sin \left( 10^{-12} \right)}{\cos x}, 1\right)\\
\left(\frac{t\_0}{t\_1} - t\_0\right) + \frac{\frac{\sin \left( 10^{-12} \right)}{\cos \left( 10^{-12} \right)}}{t\_1}
\end{array}
\end{array}
Derivation
  1. Initial program 48.1%

    \[\tan \left(x + {10}^{\left(-12\right)}\right) - \tan x \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-tan.f64N/A

      \[\leadsto \color{blue}{\tan \left(x + {10}^{\left(-12\right)}\right)} - \tan x \]
    2. lift-+.f64N/A

      \[\leadsto \tan \color{blue}{\left(x + {10}^{\left(-12\right)}\right)} - \tan x \]
    3. tan-sumN/A

      \[\leadsto \color{blue}{\frac{\tan x + \tan \left({10}^{\left(-12\right)}\right)}{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)}} - \tan x \]
    4. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)}{\tan x + \tan \left({10}^{\left(-12\right)}\right)}}} - \tan x \]
    5. inv-powN/A

      \[\leadsto \color{blue}{{\left(\frac{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)}{\tan x + \tan \left({10}^{\left(-12\right)}\right)}\right)}^{-1}} - \tan x \]
    6. div-invN/A

      \[\leadsto {\color{blue}{\left(\left(1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right) \cdot \frac{1}{\tan x + \tan \left({10}^{\left(-12\right)}\right)}\right)}}^{-1} - \tan x \]
    7. unpow-prod-downN/A

      \[\leadsto \color{blue}{{\left(1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right)}^{-1} \cdot {\left(\frac{1}{\tan x + \tan \left({10}^{\left(-12\right)}\right)}\right)}^{-1}} - \tan x \]
    8. inv-powN/A

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

      \[\leadsto \color{blue}{\frac{1}{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)} \cdot {\left(\frac{1}{\tan x + \tan \left({10}^{\left(-12\right)}\right)}\right)}^{-1}} - \tan x \]
  4. Applied rewrites68.9%

    \[\leadsto \color{blue}{{\left(\mathsf{fma}\left(-\tan \left( 10^{-12} \right), \tan x, 1\right)\right)}^{-1} \cdot {\left(\frac{1}{\tan \left( 10^{-12} \right) + \tan x}\right)}^{-1}} - \tan x \]
  5. Taylor expanded in x around inf

    \[\leadsto \color{blue}{\left(\frac{\sin \frac{1}{1000000000000}}{\cos \frac{1}{1000000000000} \cdot \left(1 + -1 \cdot \frac{\sin \frac{1}{1000000000000} \cdot \sin x}{\cos \frac{1}{1000000000000} \cdot \cos x}\right)} + \frac{\sin x}{\cos x \cdot \left(1 + -1 \cdot \frac{\sin \frac{1}{1000000000000} \cdot \sin x}{\cos \frac{1}{1000000000000} \cdot \cos x}\right)}\right) - \frac{\sin x}{\cos x}} \]
  6. Step-by-step derivation
    1. associate--l+N/A

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

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

      \[\leadsto \color{blue}{\left(\frac{\sin x}{\cos x \cdot \left(1 + -1 \cdot \frac{\sin \frac{1}{1000000000000} \cdot \sin x}{\cos \frac{1}{1000000000000} \cdot \cos x}\right)} - \frac{\sin x}{\cos x}\right) + \frac{\sin \frac{1}{1000000000000}}{\cos \frac{1}{1000000000000} \cdot \left(1 + -1 \cdot \frac{\sin \frac{1}{1000000000000} \cdot \sin x}{\cos \frac{1}{1000000000000} \cdot \cos x}\right)}} \]
  7. Applied rewrites69.9%

    \[\leadsto \color{blue}{\left(\frac{\frac{\sin x}{\cos x}}{\mathsf{fma}\left(\frac{-\sin x}{\cos \left( 10^{-12} \right)}, \frac{\sin \left( 10^{-12} \right)}{\cos x}, 1\right)} - \frac{\sin x}{\cos x}\right) + \frac{\frac{\sin \left( 10^{-12} \right)}{\cos \left( 10^{-12} \right)}}{\mathsf{fma}\left(\frac{-\sin x}{\cos \left( 10^{-12} \right)}, \frac{\sin \left( 10^{-12} \right)}{\cos x}, 1\right)}} \]
  8. Add Preprocessing

Alternative 2: 71.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\frac{\tan \left( 10^{-12} \right) + \tan x}{1 - {\left(\tan \left( 10^{-12} \right) \cdot \tan x\right)}^{2}}, \mathsf{fma}\left(\tan \left( 10^{-12} \right), \tan x, 1\right), -\tan x\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (fma
  (/ (+ (tan 1e-12) (tan x)) (- 1.0 (pow (* (tan 1e-12) (tan x)) 2.0)))
  (fma (tan 1e-12) (tan x) 1.0)
  (- (tan x))))
double code(double x) {
	return fma(((tan(1e-12) + tan(x)) / (1.0 - pow((tan(1e-12) * tan(x)), 2.0))), fma(tan(1e-12), tan(x), 1.0), -tan(x));
}
function code(x)
	return fma(Float64(Float64(tan(1e-12) + tan(x)) / Float64(1.0 - (Float64(tan(1e-12) * tan(x)) ^ 2.0))), fma(tan(1e-12), tan(x), 1.0), Float64(-tan(x)))
end
code[x_] := N[(N[(N[(N[Tan[1e-12], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[Power[N[(N[Tan[1e-12], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Tan[1e-12], $MachinePrecision] * N[Tan[x], $MachinePrecision] + 1.0), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\frac{\tan \left( 10^{-12} \right) + \tan x}{1 - {\left(\tan \left( 10^{-12} \right) \cdot \tan x\right)}^{2}}, \mathsf{fma}\left(\tan \left( 10^{-12} \right), \tan x, 1\right), -\tan x\right)
\end{array}
Derivation
  1. Initial program 48.1%

    \[\tan \left(x + {10}^{\left(-12\right)}\right) - \tan x \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{\tan \left(x + {10}^{\left(-12\right)}\right) - \tan x} \]
    2. sub-negN/A

      \[\leadsto \color{blue}{\tan \left(x + {10}^{\left(-12\right)}\right) + \left(\mathsf{neg}\left(\tan x\right)\right)} \]
    3. lift-tan.f64N/A

      \[\leadsto \color{blue}{\tan \left(x + {10}^{\left(-12\right)}\right)} + \left(\mathsf{neg}\left(\tan x\right)\right) \]
    4. lift-+.f64N/A

      \[\leadsto \tan \color{blue}{\left(x + {10}^{\left(-12\right)}\right)} + \left(\mathsf{neg}\left(\tan x\right)\right) \]
    5. tan-sumN/A

      \[\leadsto \color{blue}{\frac{\tan x + \tan \left({10}^{\left(-12\right)}\right)}{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)}} + \left(\mathsf{neg}\left(\tan x\right)\right) \]
    6. flip--N/A

      \[\leadsto \frac{\tan x + \tan \left({10}^{\left(-12\right)}\right)}{\color{blue}{\frac{1 \cdot 1 - \left(\tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right) \cdot \left(\tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right)}{1 + \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)}}} + \left(\mathsf{neg}\left(\tan x\right)\right) \]
    7. associate-/r/N/A

      \[\leadsto \color{blue}{\frac{\tan x + \tan \left({10}^{\left(-12\right)}\right)}{1 \cdot 1 - \left(\tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right) \cdot \left(\tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right)} \cdot \left(1 + \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right)} + \left(\mathsf{neg}\left(\tan x\right)\right) \]
    8. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\tan x + \tan \left({10}^{\left(-12\right)}\right)}{1 \cdot 1 - \left(\tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right) \cdot \left(\tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right)}, 1 + \tan x \cdot \tan \left({10}^{\left(-12\right)}\right), \mathsf{neg}\left(\tan x\right)\right)} \]
  4. Applied rewrites69.7%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\tan \left( 10^{-12} \right) + \tan x}{1 - {\left(\tan \left( 10^{-12} \right) \cdot \tan x\right)}^{2}}, \mathsf{fma}\left(\tan \left( 10^{-12} \right), \tan x, 1\right), -\tan x\right)} \]
  5. Add Preprocessing

Alternative 3: 71.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \frac{\tan \left( 10^{-12} \right) + \tan x}{1 - {\left(\tan \left( 10^{-12} \right) \cdot \tan x\right)}^{2}} \cdot \mathsf{fma}\left(\tan \left( 10^{-12} \right), \tan x, 1\right) - \tan x \end{array} \]
(FPCore (x)
 :precision binary64
 (-
  (*
   (/ (+ (tan 1e-12) (tan x)) (- 1.0 (pow (* (tan 1e-12) (tan x)) 2.0)))
   (fma (tan 1e-12) (tan x) 1.0))
  (tan x)))
double code(double x) {
	return (((tan(1e-12) + tan(x)) / (1.0 - pow((tan(1e-12) * tan(x)), 2.0))) * fma(tan(1e-12), tan(x), 1.0)) - tan(x);
}
function code(x)
	return Float64(Float64(Float64(Float64(tan(1e-12) + tan(x)) / Float64(1.0 - (Float64(tan(1e-12) * tan(x)) ^ 2.0))) * fma(tan(1e-12), tan(x), 1.0)) - tan(x))
end
code[x_] := N[(N[(N[(N[(N[Tan[1e-12], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[Power[N[(N[Tan[1e-12], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Tan[1e-12], $MachinePrecision] * N[Tan[x], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\tan \left( 10^{-12} \right) + \tan x}{1 - {\left(\tan \left( 10^{-12} \right) \cdot \tan x\right)}^{2}} \cdot \mathsf{fma}\left(\tan \left( 10^{-12} \right), \tan x, 1\right) - \tan x
\end{array}
Derivation
  1. Initial program 48.1%

    \[\tan \left(x + {10}^{\left(-12\right)}\right) - \tan x \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-tan.f64N/A

      \[\leadsto \color{blue}{\tan \left(x + {10}^{\left(-12\right)}\right)} - \tan x \]
    2. lift-+.f64N/A

      \[\leadsto \tan \color{blue}{\left(x + {10}^{\left(-12\right)}\right)} - \tan x \]
    3. tan-sumN/A

      \[\leadsto \color{blue}{\frac{\tan x + \tan \left({10}^{\left(-12\right)}\right)}{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)}} - \tan x \]
    4. flip--N/A

      \[\leadsto \frac{\tan x + \tan \left({10}^{\left(-12\right)}\right)}{\color{blue}{\frac{1 \cdot 1 - \left(\tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right) \cdot \left(\tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right)}{1 + \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)}}} - \tan x \]
    5. associate-/r/N/A

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

      \[\leadsto \color{blue}{\frac{\tan x + \tan \left({10}^{\left(-12\right)}\right)}{1 \cdot 1 - \left(\tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right) \cdot \left(\tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right)} \cdot \left(1 + \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right)} - \tan x \]
  4. Applied rewrites69.3%

    \[\leadsto \color{blue}{\frac{\tan \left( 10^{-12} \right) + \tan x}{1 - {\left(\tan \left( 10^{-12} \right) \cdot \tan x\right)}^{2}} \cdot \mathsf{fma}\left(\tan \left( 10^{-12} \right), \tan x, 1\right)} - \tan x \]
  5. Add Preprocessing

Alternative 4: 71.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ {\left({\left(\frac{\tan x + \tan \left( 10^{-12} \right)}{\mathsf{fma}\left(-\tan \left( 10^{-12} \right), \tan x, 1\right)} - \tan x\right)}^{-1}\right)}^{-1} \end{array} \]
(FPCore (x)
 :precision binary64
 (pow
  (pow
   (- (/ (+ (tan x) (tan 1e-12)) (fma (- (tan 1e-12)) (tan x) 1.0)) (tan x))
   -1.0)
  -1.0))
double code(double x) {
	return pow(pow((((tan(x) + tan(1e-12)) / fma(-tan(1e-12), tan(x), 1.0)) - tan(x)), -1.0), -1.0);
}
function code(x)
	return (Float64(Float64(Float64(tan(x) + tan(1e-12)) / fma(Float64(-tan(1e-12)), tan(x), 1.0)) - tan(x)) ^ -1.0) ^ -1.0
end
code[x_] := N[Power[N[Power[N[(N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[1e-12], $MachinePrecision]), $MachinePrecision] / N[((-N[Tan[1e-12], $MachinePrecision]) * N[Tan[x], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision], -1.0], $MachinePrecision]
\begin{array}{l}

\\
{\left({\left(\frac{\tan x + \tan \left( 10^{-12} \right)}{\mathsf{fma}\left(-\tan \left( 10^{-12} \right), \tan x, 1\right)} - \tan x\right)}^{-1}\right)}^{-1}
\end{array}
Derivation
  1. Initial program 48.1%

    \[\tan \left(x + {10}^{\left(-12\right)}\right) - \tan x \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-tan.f64N/A

      \[\leadsto \color{blue}{\tan \left(x + {10}^{\left(-12\right)}\right)} - \tan x \]
    2. lift-+.f64N/A

      \[\leadsto \tan \color{blue}{\left(x + {10}^{\left(-12\right)}\right)} - \tan x \]
    3. tan-sumN/A

      \[\leadsto \color{blue}{\frac{\tan x + \tan \left({10}^{\left(-12\right)}\right)}{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)}} - \tan x \]
    4. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)}{\tan x + \tan \left({10}^{\left(-12\right)}\right)}}} - \tan x \]
    5. inv-powN/A

      \[\leadsto \color{blue}{{\left(\frac{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)}{\tan x + \tan \left({10}^{\left(-12\right)}\right)}\right)}^{-1}} - \tan x \]
    6. div-invN/A

      \[\leadsto {\color{blue}{\left(\left(1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right) \cdot \frac{1}{\tan x + \tan \left({10}^{\left(-12\right)}\right)}\right)}}^{-1} - \tan x \]
    7. unpow-prod-downN/A

      \[\leadsto \color{blue}{{\left(1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right)}^{-1} \cdot {\left(\frac{1}{\tan x + \tan \left({10}^{\left(-12\right)}\right)}\right)}^{-1}} - \tan x \]
    8. inv-powN/A

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

      \[\leadsto \color{blue}{\frac{1}{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)} \cdot {\left(\frac{1}{\tan x + \tan \left({10}^{\left(-12\right)}\right)}\right)}^{-1}} - \tan x \]
  4. Applied rewrites68.9%

    \[\leadsto \color{blue}{{\left(\mathsf{fma}\left(-\tan \left( 10^{-12} \right), \tan x, 1\right)\right)}^{-1} \cdot {\left(\frac{1}{\tan \left( 10^{-12} \right) + \tan x}\right)}^{-1}} - \tan x \]
  5. Applied rewrites69.3%

    \[\leadsto \color{blue}{\frac{1}{{\left(\frac{\tan x + \tan \left( 10^{-12} \right)}{\mathsf{fma}\left(-\tan \left( 10^{-12} \right), \tan x, 1\right)} - \tan x\right)}^{-1}}} \]
  6. Final simplification69.3%

    \[\leadsto {\left({\left(\frac{\tan x + \tan \left( 10^{-12} \right)}{\mathsf{fma}\left(-\tan \left( 10^{-12} \right), \tan x, 1\right)} - \tan x\right)}^{-1}\right)}^{-1} \]
  7. Add Preprocessing

Alternative 5: 71.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \frac{\tan \left( 10^{-12} \right) + \tan x}{\mathsf{fma}\left(-\tan \left( 10^{-12} \right), \tan x, 1\right)} - \tan x \end{array} \]
(FPCore (x)
 :precision binary64
 (- (/ (+ (tan 1e-12) (tan x)) (fma (- (tan 1e-12)) (tan x) 1.0)) (tan x)))
double code(double x) {
	return ((tan(1e-12) + tan(x)) / fma(-tan(1e-12), tan(x), 1.0)) - tan(x);
}
function code(x)
	return Float64(Float64(Float64(tan(1e-12) + tan(x)) / fma(Float64(-tan(1e-12)), tan(x), 1.0)) - tan(x))
end
code[x_] := N[(N[(N[(N[Tan[1e-12], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision] / N[((-N[Tan[1e-12], $MachinePrecision]) * N[Tan[x], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\tan \left( 10^{-12} \right) + \tan x}{\mathsf{fma}\left(-\tan \left( 10^{-12} \right), \tan x, 1\right)} - \tan x
\end{array}
Derivation
  1. Initial program 48.1%

    \[\tan \left(x + {10}^{\left(-12\right)}\right) - \tan x \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-tan.f64N/A

      \[\leadsto \color{blue}{\tan \left(x + {10}^{\left(-12\right)}\right)} - \tan x \]
    2. lift-+.f64N/A

      \[\leadsto \tan \color{blue}{\left(x + {10}^{\left(-12\right)}\right)} - \tan x \]
    3. tan-sumN/A

      \[\leadsto \color{blue}{\frac{\tan x + \tan \left({10}^{\left(-12\right)}\right)}{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)}} - \tan x \]
    4. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{\tan x + \tan \left({10}^{\left(-12\right)}\right)}{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)}} - \tan x \]
    5. lift-tan.f64N/A

      \[\leadsto \frac{\color{blue}{\tan x} + \tan \left({10}^{\left(-12\right)}\right)}{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)} - \tan x \]
    6. +-commutativeN/A

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

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

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

      \[\leadsto \frac{\tan \color{blue}{\left({10}^{\left(-12\right)}\right)} + \tan x}{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)} - \tan x \]
    10. lift-neg.f64N/A

      \[\leadsto \frac{\tan \left({10}^{\color{blue}{\left(\mathsf{neg}\left(12\right)\right)}}\right) + \tan x}{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)} - \tan x \]
    11. metadata-evalN/A

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

      \[\leadsto \frac{\tan \color{blue}{\frac{1}{1000000000000}} + \tan x}{1 - \tan x \cdot \tan \left({10}^{\left(-12\right)}\right)} - \tan x \]
    13. sub-negN/A

      \[\leadsto \frac{\tan \frac{1}{1000000000000} + \tan x}{\color{blue}{1 + \left(\mathsf{neg}\left(\tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right)\right)}} - \tan x \]
    14. +-commutativeN/A

      \[\leadsto \frac{\tan \frac{1}{1000000000000} + \tan x}{\color{blue}{\left(\mathsf{neg}\left(\tan x \cdot \tan \left({10}^{\left(-12\right)}\right)\right)\right) + 1}} - \tan x \]
    15. lift-tan.f64N/A

      \[\leadsto \frac{\tan \frac{1}{1000000000000} + \tan x}{\left(\mathsf{neg}\left(\color{blue}{\tan x} \cdot \tan \left({10}^{\left(-12\right)}\right)\right)\right) + 1} - \tan x \]
    16. *-commutativeN/A

      \[\leadsto \frac{\tan \frac{1}{1000000000000} + \tan x}{\left(\mathsf{neg}\left(\color{blue}{\tan \left({10}^{\left(-12\right)}\right) \cdot \tan x}\right)\right) + 1} - \tan x \]
    17. distribute-lft-neg-inN/A

      \[\leadsto \frac{\tan \frac{1}{1000000000000} + \tan x}{\color{blue}{\left(\mathsf{neg}\left(\tan \left({10}^{\left(-12\right)}\right)\right)\right) \cdot \tan x} + 1} - \tan x \]
    18. lower-fma.f64N/A

      \[\leadsto \frac{\tan \frac{1}{1000000000000} + \tan x}{\color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\tan \left({10}^{\left(-12\right)}\right)\right), \tan x, 1\right)}} - \tan x \]
  4. Applied rewrites69.3%

    \[\leadsto \color{blue}{\frac{\tan \left( 10^{-12} \right) + \tan x}{\mathsf{fma}\left(-\tan \left( 10^{-12} \right), \tan x, 1\right)}} - \tan x \]
  5. Add Preprocessing

Alternative 6: 53.1% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\tan \left(x + {10}^{-12}\right) - \tan x \leq 0:\\ \;\;\;\;\tan \left( 10^{-12} \right) - \tan x\\ \mathbf{else}:\\ \;\;\;\;\tan \left(x + 10^{-12}\right) - \tan x\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (- (tan (+ x (pow 10.0 -12.0))) (tan x)) 0.0)
   (- (tan 1e-12) (tan x))
   (- (tan (+ x 1e-12)) (tan x))))
double code(double x) {
	double tmp;
	if ((tan((x + pow(10.0, -12.0))) - tan(x)) <= 0.0) {
		tmp = tan(1e-12) - tan(x);
	} else {
		tmp = tan((x + 1e-12)) - tan(x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((tan((x + (10.0d0 ** (-12.0d0)))) - tan(x)) <= 0.0d0) then
        tmp = tan(1d-12) - tan(x)
    else
        tmp = tan((x + 1d-12)) - tan(x)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if ((Math.tan((x + Math.pow(10.0, -12.0))) - Math.tan(x)) <= 0.0) {
		tmp = Math.tan(1e-12) - Math.tan(x);
	} else {
		tmp = Math.tan((x + 1e-12)) - Math.tan(x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (math.tan((x + math.pow(10.0, -12.0))) - math.tan(x)) <= 0.0:
		tmp = math.tan(1e-12) - math.tan(x)
	else:
		tmp = math.tan((x + 1e-12)) - math.tan(x)
	return tmp
function code(x)
	tmp = 0.0
	if (Float64(tan(Float64(x + (10.0 ^ -12.0))) - tan(x)) <= 0.0)
		tmp = Float64(tan(1e-12) - tan(x));
	else
		tmp = Float64(tan(Float64(x + 1e-12)) - tan(x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if ((tan((x + (10.0 ^ -12.0))) - tan(x)) <= 0.0)
		tmp = tan(1e-12) - tan(x);
	else
		tmp = tan((x + 1e-12)) - tan(x);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[N[(N[Tan[N[(x + N[Power[10.0, -12.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], 0.0], N[(N[Tan[1e-12], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(N[Tan[N[(x + 1e-12), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\tan \left(x + {10}^{-12}\right) - \tan x \leq 0:\\
\;\;\;\;\tan \left( 10^{-12} \right) - \tan x\\

\mathbf{else}:\\
\;\;\;\;\tan \left(x + 10^{-12}\right) - \tan x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (tan.f64 (+.f64 x (pow.f64 #s(literal 10 binary64) (neg.f64 #s(literal 12 binary64))))) (tan.f64 x)) < 0.0

    1. Initial program 3.2%

      \[\tan \left(x + {10}^{\left(-12\right)}\right) - \tan x \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \tan \color{blue}{\frac{1}{1000000000000}} - \tan x \]
    4. Step-by-step derivation
      1. Applied rewrites6.2%

        \[\leadsto \tan \color{blue}{\left( 10^{-12} \right)} - \tan x \]

      if 0.0 < (-.f64 (tan.f64 (+.f64 x (pow.f64 #s(literal 10 binary64) (neg.f64 #s(literal 12 binary64))))) (tan.f64 x))

      1. Initial program 97.4%

        \[\tan \left(x + {10}^{\left(-12\right)}\right) - \tan x \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-pow.f64N/A

          \[\leadsto \tan \left(x + \color{blue}{{10}^{\left(-12\right)}}\right) - \tan x \]
        2. lift-neg.f64N/A

          \[\leadsto \tan \left(x + {10}^{\color{blue}{\left(\mathsf{neg}\left(12\right)\right)}}\right) - \tan x \]
        3. metadata-evalN/A

          \[\leadsto \tan \left(x + {10}^{\color{blue}{-12}}\right) - \tan x \]
        4. metadata-eval97.4

          \[\leadsto \tan \left(x + \color{blue}{10^{-12}}\right) - \tan x \]
      4. Applied rewrites97.4%

        \[\leadsto \tan \left(x + \color{blue}{10^{-12}}\right) - \tan x \]
    5. Recombined 2 regimes into one program.
    6. Final simplification49.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\tan \left(x + {10}^{-12}\right) - \tan x \leq 0:\\ \;\;\;\;\tan \left( 10^{-12} \right) - \tan x\\ \mathbf{else}:\\ \;\;\;\;\tan \left(x + 10^{-12}\right) - \tan x\\ \end{array} \]
    7. Add Preprocessing

    Alternative 7: 59.9% accurate, 1.5× speedup?

    \[\begin{array}{l} \\ \frac{\sin \left( 10^{-12} \right)}{\cos \left( 10^{-12} \right)} \end{array} \]
    (FPCore (x) :precision binary64 (/ (sin 1e-12) (cos 1e-12)))
    double code(double x) {
    	return sin(1e-12) / cos(1e-12);
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        code = sin(1d-12) / cos(1d-12)
    end function
    
    public static double code(double x) {
    	return Math.sin(1e-12) / Math.cos(1e-12);
    }
    
    def code(x):
    	return math.sin(1e-12) / math.cos(1e-12)
    
    function code(x)
    	return Float64(sin(1e-12) / cos(1e-12))
    end
    
    function tmp = code(x)
    	tmp = sin(1e-12) / cos(1e-12);
    end
    
    code[x_] := N[(N[Sin[1e-12], $MachinePrecision] / N[Cos[1e-12], $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{\sin \left( 10^{-12} \right)}{\cos \left( 10^{-12} \right)}
    \end{array}
    
    Derivation
    1. Initial program 48.1%

      \[\tan \left(x + {10}^{\left(-12\right)}\right) - \tan x \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

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

        \[\leadsto \color{blue}{\frac{\sin \frac{1}{1000000000000}}{\cos \frac{1}{1000000000000}}} \]
      2. lower-sin.f64N/A

        \[\leadsto \frac{\color{blue}{\sin \frac{1}{1000000000000}}}{\cos \frac{1}{1000000000000}} \]
      3. lower-cos.f6457.1

        \[\leadsto \frac{\sin \left( 10^{-12} \right)}{\color{blue}{\cos \left( 10^{-12} \right)}} \]
    5. Applied rewrites57.1%

      \[\leadsto \color{blue}{\frac{\sin \left( 10^{-12} \right)}{\cos \left( 10^{-12} \right)}} \]
    6. Add Preprocessing

    Alternative 8: 50.4% accurate, 1.5× speedup?

    \[\begin{array}{l} \\ \tan \left( 10^{-12} \right) - \tan x \end{array} \]
    (FPCore (x) :precision binary64 (- (tan 1e-12) (tan x)))
    double code(double x) {
    	return tan(1e-12) - tan(x);
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        code = tan(1d-12) - tan(x)
    end function
    
    public static double code(double x) {
    	return Math.tan(1e-12) - Math.tan(x);
    }
    
    def code(x):
    	return math.tan(1e-12) - math.tan(x)
    
    function code(x)
    	return Float64(tan(1e-12) - tan(x))
    end
    
    function tmp = code(x)
    	tmp = tan(1e-12) - tan(x);
    end
    
    code[x_] := N[(N[Tan[1e-12], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \tan \left( 10^{-12} \right) - \tan x
    \end{array}
    
    Derivation
    1. Initial program 48.1%

      \[\tan \left(x + {10}^{\left(-12\right)}\right) - \tan x \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \tan \color{blue}{\frac{1}{1000000000000}} - \tan x \]
    4. Step-by-step derivation
      1. Applied rewrites46.6%

        \[\leadsto \tan \color{blue}{\left( 10^{-12} \right)} - \tan x \]
      2. Add Preprocessing

      Reproduce

      ?
      herbie shell --seed 1 
      (FPCore (x)
        :name "expr_51555138"
        :precision binary64
        (- (tan (+ x (pow 10.0 (- 12.0)))) (tan x)))