invcot (example 3.9)

Percentage Accurate: 6.6% → 99.6%
Time: 19.5s
Alternatives: 9
Speedup: 35.7×

Specification

?
\[-0.026 < x \land x < 0.026\]
\[\begin{array}{l} \\ \frac{1}{x} - \frac{1}{\tan x} \end{array} \]
(FPCore (x) :precision binary64 (- (/ 1.0 x) (/ 1.0 (tan x))))
double code(double x) {
	return (1.0 / x) - (1.0 / tan(x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 / x) - (1.0d0 / tan(x))
end function
public static double code(double x) {
	return (1.0 / x) - (1.0 / Math.tan(x));
}
def code(x):
	return (1.0 / x) - (1.0 / math.tan(x))
function code(x)
	return Float64(Float64(1.0 / x) - Float64(1.0 / tan(x)))
end
function tmp = code(x)
	tmp = (1.0 / x) - (1.0 / tan(x));
end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] - N[(1.0 / N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{x} - \frac{1}{\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 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: 6.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{x} - \frac{1}{\tan x} \end{array} \]
(FPCore (x) :precision binary64 (- (/ 1.0 x) (/ 1.0 (tan x))))
double code(double x) {
	return (1.0 / x) - (1.0 / tan(x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 / x) - (1.0d0 / tan(x))
end function
public static double code(double x) {
	return (1.0 / x) - (1.0 / Math.tan(x));
}
def code(x):
	return (1.0 / x) - (1.0 / math.tan(x))
function code(x)
	return Float64(Float64(1.0 / x) - Float64(1.0 / tan(x)))
end
function tmp = code(x)
	tmp = (1.0 / x) - (1.0 / tan(x));
end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] - N[(1.0 / N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{x} - \frac{1}{\tan x}
\end{array}

Alternative 1: 99.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left({x}^{2}, 0.0021164021164021165, 0.022222222222222223\right)\\ t_1 := {x}^{2} \cdot t\_0\\ \frac{x \cdot \left(0.037037037037037035 + {x}^{6} \cdot {t\_0}^{3}\right)}{0.1111111111111111 + t\_1 \cdot \left(t\_1 - 0.3333333333333333\right)} \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (fma (pow x 2.0) 0.0021164021164021165 0.022222222222222223))
        (t_1 (* (pow x 2.0) t_0)))
   (/
    (* x (+ 0.037037037037037035 (* (pow x 6.0) (pow t_0 3.0))))
    (+ 0.1111111111111111 (* t_1 (- t_1 0.3333333333333333))))))
double code(double x) {
	double t_0 = fma(pow(x, 2.0), 0.0021164021164021165, 0.022222222222222223);
	double t_1 = pow(x, 2.0) * t_0;
	return (x * (0.037037037037037035 + (pow(x, 6.0) * pow(t_0, 3.0)))) / (0.1111111111111111 + (t_1 * (t_1 - 0.3333333333333333)));
}
function code(x)
	t_0 = fma((x ^ 2.0), 0.0021164021164021165, 0.022222222222222223)
	t_1 = Float64((x ^ 2.0) * t_0)
	return Float64(Float64(x * Float64(0.037037037037037035 + Float64((x ^ 6.0) * (t_0 ^ 3.0)))) / Float64(0.1111111111111111 + Float64(t_1 * Float64(t_1 - 0.3333333333333333))))
end
code[x_] := Block[{t$95$0 = N[(N[Power[x, 2.0], $MachinePrecision] * 0.0021164021164021165 + 0.022222222222222223), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[x, 2.0], $MachinePrecision] * t$95$0), $MachinePrecision]}, N[(N[(x * N[(0.037037037037037035 + N[(N[Power[x, 6.0], $MachinePrecision] * N[Power[t$95$0, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(0.1111111111111111 + N[(t$95$1 * N[(t$95$1 - 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left({x}^{2}, 0.0021164021164021165, 0.022222222222222223\right)\\
t_1 := {x}^{2} \cdot t\_0\\
\frac{x \cdot \left(0.037037037037037035 + {x}^{6} \cdot {t\_0}^{3}\right)}{0.1111111111111111 + t\_1 \cdot \left(t\_1 - 0.3333333333333333\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 6.9%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.4%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + 0.0021164021164021165 \cdot {x}^{2}\right)\right)} \]
  4. Step-by-step derivation
    1. *-commutative99.4%

      \[\leadsto x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + \color{blue}{{x}^{2} \cdot 0.0021164021164021165}\right)\right) \]
  5. Simplified99.4%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot 0.0021164021164021165\right)\right)} \]
  6. Step-by-step derivation
    1. flip3-+98.0%

      \[\leadsto x \cdot \color{blue}{\frac{{0.3333333333333333}^{3} + {\left({x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot 0.0021164021164021165\right)\right)}^{3}}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left({x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot 0.0021164021164021165\right)\right) \cdot \left({x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot 0.0021164021164021165\right)\right) - 0.3333333333333333 \cdot \left({x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot 0.0021164021164021165\right)\right)\right)}} \]
    2. associate-*r/98.2%

      \[\leadsto \color{blue}{\frac{x \cdot \left({0.3333333333333333}^{3} + {\left({x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot 0.0021164021164021165\right)\right)}^{3}\right)}{0.3333333333333333 \cdot 0.3333333333333333 + \left(\left({x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot 0.0021164021164021165\right)\right) \cdot \left({x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot 0.0021164021164021165\right)\right) - 0.3333333333333333 \cdot \left({x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot 0.0021164021164021165\right)\right)\right)}} \]
  7. Applied egg-rr99.5%

    \[\leadsto \color{blue}{\frac{x \cdot \left(0.037037037037037035 + {x}^{6} \cdot {\left(\mathsf{fma}\left({x}^{2}, 0.0021164021164021165, 0.022222222222222223\right)\right)}^{3}\right)}{0.1111111111111111 + \left({x}^{2} \cdot \mathsf{fma}\left({x}^{2}, 0.0021164021164021165, 0.022222222222222223\right)\right) \cdot \left({x}^{2} \cdot \mathsf{fma}\left({x}^{2}, 0.0021164021164021165, 0.022222222222222223\right) - 0.3333333333333333\right)}} \]
  8. Final simplification99.5%

    \[\leadsto \frac{x \cdot \left(0.037037037037037035 + {x}^{6} \cdot {\left(\mathsf{fma}\left({x}^{2}, 0.0021164021164021165, 0.022222222222222223\right)\right)}^{3}\right)}{0.1111111111111111 + \left({x}^{2} \cdot \mathsf{fma}\left({x}^{2}, 0.0021164021164021165, 0.022222222222222223\right)\right) \cdot \left({x}^{2} \cdot \mathsf{fma}\left({x}^{2}, 0.0021164021164021165, 0.022222222222222223\right) - 0.3333333333333333\right)} \]
  9. Add Preprocessing

Alternative 2: 99.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left({x}^{4}, -0.0004938271604938272, 0.1111111111111111\right) \cdot \frac{x}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)} \end{array} \]
(FPCore (x)
 :precision binary64
 (*
  (fma (pow x 4.0) -0.0004938271604938272 0.1111111111111111)
  (/ x (fma (pow x 2.0) -0.022222222222222223 0.3333333333333333))))
double code(double x) {
	return fma(pow(x, 4.0), -0.0004938271604938272, 0.1111111111111111) * (x / fma(pow(x, 2.0), -0.022222222222222223, 0.3333333333333333));
}
function code(x)
	return Float64(fma((x ^ 4.0), -0.0004938271604938272, 0.1111111111111111) * Float64(x / fma((x ^ 2.0), -0.022222222222222223, 0.3333333333333333)))
end
code[x_] := N[(N[(N[Power[x, 4.0], $MachinePrecision] * -0.0004938271604938272 + 0.1111111111111111), $MachinePrecision] * N[(x / N[(N[Power[x, 2.0], $MachinePrecision] * -0.022222222222222223 + 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left({x}^{4}, -0.0004938271604938272, 0.1111111111111111\right) \cdot \frac{x}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)}
\end{array}
Derivation
  1. Initial program 6.9%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.2%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + 0.022222222222222223 \cdot {x}^{2}\right)} \]
  4. Step-by-step derivation
    1. distribute-rgt-in99.2%

      \[\leadsto \color{blue}{0.3333333333333333 \cdot x + \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x} \]
    2. flip-+55.0%

      \[\leadsto \color{blue}{\frac{\left(0.3333333333333333 \cdot x\right) \cdot \left(0.3333333333333333 \cdot x\right) - \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x\right) \cdot \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x\right)}{0.3333333333333333 \cdot x - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x}} \]
    3. *-commutative55.0%

      \[\leadsto \frac{\color{blue}{\left(x \cdot 0.3333333333333333\right)} \cdot \left(0.3333333333333333 \cdot x\right) - \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x\right) \cdot \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x\right)}{0.3333333333333333 \cdot x - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x} \]
    4. *-commutative55.0%

      \[\leadsto \frac{\left(x \cdot 0.3333333333333333\right) \cdot \color{blue}{\left(x \cdot 0.3333333333333333\right)} - \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x\right) \cdot \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x\right)}{0.3333333333333333 \cdot x - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x} \]
    5. swap-sqr55.0%

      \[\leadsto \frac{\color{blue}{\left(x \cdot x\right) \cdot \left(0.3333333333333333 \cdot 0.3333333333333333\right)} - \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x\right) \cdot \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x\right)}{0.3333333333333333 \cdot x - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x} \]
    6. unpow255.0%

      \[\leadsto \frac{\color{blue}{{x}^{2}} \cdot \left(0.3333333333333333 \cdot 0.3333333333333333\right) - \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x\right) \cdot \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x\right)}{0.3333333333333333 \cdot x - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x} \]
    7. metadata-eval55.0%

      \[\leadsto \frac{{x}^{2} \cdot \color{blue}{0.1111111111111111} - \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x\right) \cdot \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x\right)}{0.3333333333333333 \cdot x - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x} \]
    8. *-commutative55.0%

      \[\leadsto \frac{{x}^{2} \cdot 0.1111111111111111 - \left(\color{blue}{\left({x}^{2} \cdot 0.022222222222222223\right)} \cdot x\right) \cdot \left(\left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x\right)}{0.3333333333333333 \cdot x - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x} \]
    9. *-commutative55.0%

      \[\leadsto \frac{{x}^{2} \cdot 0.1111111111111111 - \left(\left({x}^{2} \cdot 0.022222222222222223\right) \cdot x\right) \cdot \left(\color{blue}{\left({x}^{2} \cdot 0.022222222222222223\right)} \cdot x\right)}{0.3333333333333333 \cdot x - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x} \]
    10. *-commutative55.0%

      \[\leadsto \frac{{x}^{2} \cdot 0.1111111111111111 - \left(\left({x}^{2} \cdot 0.022222222222222223\right) \cdot x\right) \cdot \left(\left({x}^{2} \cdot 0.022222222222222223\right) \cdot x\right)}{\color{blue}{x \cdot 0.3333333333333333} - \left(0.022222222222222223 \cdot {x}^{2}\right) \cdot x} \]
    11. *-commutative55.0%

      \[\leadsto \frac{{x}^{2} \cdot 0.1111111111111111 - \left(\left({x}^{2} \cdot 0.022222222222222223\right) \cdot x\right) \cdot \left(\left({x}^{2} \cdot 0.022222222222222223\right) \cdot x\right)}{x \cdot 0.3333333333333333 - \color{blue}{\left({x}^{2} \cdot 0.022222222222222223\right)} \cdot x} \]
  5. Applied egg-rr55.0%

    \[\leadsto \color{blue}{\frac{{x}^{2} \cdot 0.1111111111111111 - \left(\left({x}^{2} \cdot 0.022222222222222223\right) \cdot x\right) \cdot \left(\left({x}^{2} \cdot 0.022222222222222223\right) \cdot x\right)}{x \cdot 0.3333333333333333 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot x}} \]
  6. Step-by-step derivation
    1. *-commutative55.0%

      \[\leadsto \frac{\color{blue}{0.1111111111111111 \cdot {x}^{2}} - \left(\left({x}^{2} \cdot 0.022222222222222223\right) \cdot x\right) \cdot \left(\left({x}^{2} \cdot 0.022222222222222223\right) \cdot x\right)}{x \cdot 0.3333333333333333 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot x} \]
    2. swap-sqr55.0%

      \[\leadsto \frac{0.1111111111111111 \cdot {x}^{2} - \color{blue}{\left(\left({x}^{2} \cdot 0.022222222222222223\right) \cdot \left({x}^{2} \cdot 0.022222222222222223\right)\right) \cdot \left(x \cdot x\right)}}{x \cdot 0.3333333333333333 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot x} \]
    3. unpow255.0%

      \[\leadsto \frac{0.1111111111111111 \cdot {x}^{2} - \left(\left({x}^{2} \cdot 0.022222222222222223\right) \cdot \left({x}^{2} \cdot 0.022222222222222223\right)\right) \cdot \color{blue}{{x}^{2}}}{x \cdot 0.3333333333333333 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot x} \]
    4. distribute-rgt-out--55.0%

      \[\leadsto \frac{\color{blue}{{x}^{2} \cdot \left(0.1111111111111111 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot \left({x}^{2} \cdot 0.022222222222222223\right)\right)}}{x \cdot 0.3333333333333333 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot x} \]
    5. swap-sqr55.0%

      \[\leadsto \frac{{x}^{2} \cdot \left(0.1111111111111111 - \color{blue}{\left({x}^{2} \cdot {x}^{2}\right) \cdot \left(0.022222222222222223 \cdot 0.022222222222222223\right)}\right)}{x \cdot 0.3333333333333333 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot x} \]
    6. pow-sqr55.0%

      \[\leadsto \frac{{x}^{2} \cdot \left(0.1111111111111111 - \color{blue}{{x}^{\left(2 \cdot 2\right)}} \cdot \left(0.022222222222222223 \cdot 0.022222222222222223\right)\right)}{x \cdot 0.3333333333333333 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot x} \]
    7. metadata-eval55.0%

      \[\leadsto \frac{{x}^{2} \cdot \left(0.1111111111111111 - {x}^{\color{blue}{4}} \cdot \left(0.022222222222222223 \cdot 0.022222222222222223\right)\right)}{x \cdot 0.3333333333333333 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot x} \]
    8. metadata-eval55.0%

      \[\leadsto \frac{{x}^{2} \cdot \left(0.1111111111111111 - {x}^{4} \cdot \color{blue}{0.0004938271604938272}\right)}{x \cdot 0.3333333333333333 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot x} \]
    9. sub-neg55.0%

      \[\leadsto \frac{{x}^{2} \cdot \color{blue}{\left(0.1111111111111111 + \left(-{x}^{4} \cdot 0.0004938271604938272\right)\right)}}{x \cdot 0.3333333333333333 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot x} \]
    10. distribute-rgt-neg-in55.0%

      \[\leadsto \frac{{x}^{2} \cdot \left(0.1111111111111111 + \color{blue}{{x}^{4} \cdot \left(-0.0004938271604938272\right)}\right)}{x \cdot 0.3333333333333333 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot x} \]
    11. metadata-eval55.0%

      \[\leadsto \frac{{x}^{2} \cdot \left(0.1111111111111111 + {x}^{4} \cdot \color{blue}{-0.0004938271604938272}\right)}{x \cdot 0.3333333333333333 - \left({x}^{2} \cdot 0.022222222222222223\right) \cdot x} \]
    12. cancel-sign-sub-inv55.0%

      \[\leadsto \frac{{x}^{2} \cdot \left(0.1111111111111111 + {x}^{4} \cdot -0.0004938271604938272\right)}{\color{blue}{x \cdot 0.3333333333333333 + \left(-{x}^{2} \cdot 0.022222222222222223\right) \cdot x}} \]
    13. *-commutative55.0%

      \[\leadsto \frac{{x}^{2} \cdot \left(0.1111111111111111 + {x}^{4} \cdot -0.0004938271604938272\right)}{\color{blue}{0.3333333333333333 \cdot x} + \left(-{x}^{2} \cdot 0.022222222222222223\right) \cdot x} \]
    14. distribute-rgt-out55.0%

      \[\leadsto \frac{{x}^{2} \cdot \left(0.1111111111111111 + {x}^{4} \cdot -0.0004938271604938272\right)}{\color{blue}{x \cdot \left(0.3333333333333333 + \left(-{x}^{2} \cdot 0.022222222222222223\right)\right)}} \]
  7. Simplified55.0%

    \[\leadsto \color{blue}{\frac{{x}^{2} \cdot \left(0.1111111111111111 + {x}^{4} \cdot -0.0004938271604938272\right)}{x \cdot \mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)}} \]
  8. Step-by-step derivation
    1. times-frac55.1%

      \[\leadsto \color{blue}{\frac{{x}^{2}}{x} \cdot \frac{0.1111111111111111 + {x}^{4} \cdot -0.0004938271604938272}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)}} \]
    2. pow155.1%

      \[\leadsto \frac{{x}^{2}}{\color{blue}{{x}^{1}}} \cdot \frac{0.1111111111111111 + {x}^{4} \cdot -0.0004938271604938272}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)} \]
    3. pow-div99.2%

      \[\leadsto \color{blue}{{x}^{\left(2 - 1\right)}} \cdot \frac{0.1111111111111111 + {x}^{4} \cdot -0.0004938271604938272}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)} \]
    4. metadata-eval99.2%

      \[\leadsto {x}^{\color{blue}{1}} \cdot \frac{0.1111111111111111 + {x}^{4} \cdot -0.0004938271604938272}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)} \]
    5. pow199.2%

      \[\leadsto \color{blue}{x} \cdot \frac{0.1111111111111111 + {x}^{4} \cdot -0.0004938271604938272}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)} \]
    6. +-commutative99.2%

      \[\leadsto x \cdot \frac{\color{blue}{{x}^{4} \cdot -0.0004938271604938272 + 0.1111111111111111}}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)} \]
    7. fma-define99.2%

      \[\leadsto x \cdot \frac{\color{blue}{\mathsf{fma}\left({x}^{4}, -0.0004938271604938272, 0.1111111111111111\right)}}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)} \]
  9. Applied egg-rr99.2%

    \[\leadsto \color{blue}{x \cdot \frac{\mathsf{fma}\left({x}^{4}, -0.0004938271604938272, 0.1111111111111111\right)}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)}} \]
  10. Step-by-step derivation
    1. associate-*r/99.4%

      \[\leadsto \color{blue}{\frac{x \cdot \mathsf{fma}\left({x}^{4}, -0.0004938271604938272, 0.1111111111111111\right)}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)}} \]
  11. Simplified99.4%

    \[\leadsto \color{blue}{\frac{x \cdot \mathsf{fma}\left({x}^{4}, -0.0004938271604938272, 0.1111111111111111\right)}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)}} \]
  12. Step-by-step derivation
    1. *-commutative99.4%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({x}^{4}, -0.0004938271604938272, 0.1111111111111111\right) \cdot x}}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)} \]
    2. *-un-lft-identity99.4%

      \[\leadsto \frac{\mathsf{fma}\left({x}^{4}, -0.0004938271604938272, 0.1111111111111111\right) \cdot x}{\color{blue}{1 \cdot \mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)}} \]
    3. times-frac99.5%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left({x}^{4}, -0.0004938271604938272, 0.1111111111111111\right)}{1} \cdot \frac{x}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)}} \]
  13. Applied egg-rr99.5%

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left({x}^{4}, -0.0004938271604938272, 0.1111111111111111\right)}{1} \cdot \frac{x}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)}} \]
  14. Final simplification99.5%

    \[\leadsto \mathsf{fma}\left({x}^{4}, -0.0004938271604938272, 0.1111111111111111\right) \cdot \frac{x}{\mathsf{fma}\left({x}^{2}, -0.022222222222222223, 0.3333333333333333\right)} \]
  15. Add Preprocessing

Alternative 3: 99.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot \left(0.0021164021164021165 + {x}^{2} \cdot 0.00021164021164021165\right)\right)\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (*
  x
  (+
   0.3333333333333333
   (*
    (pow x 2.0)
    (+
     0.022222222222222223
     (*
      (pow x 2.0)
      (+ 0.0021164021164021165 (* (pow x 2.0) 0.00021164021164021165))))))))
double code(double x) {
	return x * (0.3333333333333333 + (pow(x, 2.0) * (0.022222222222222223 + (pow(x, 2.0) * (0.0021164021164021165 + (pow(x, 2.0) * 0.00021164021164021165))))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x * (0.3333333333333333d0 + ((x ** 2.0d0) * (0.022222222222222223d0 + ((x ** 2.0d0) * (0.0021164021164021165d0 + ((x ** 2.0d0) * 0.00021164021164021165d0))))))
end function
public static double code(double x) {
	return x * (0.3333333333333333 + (Math.pow(x, 2.0) * (0.022222222222222223 + (Math.pow(x, 2.0) * (0.0021164021164021165 + (Math.pow(x, 2.0) * 0.00021164021164021165))))));
}
def code(x):
	return x * (0.3333333333333333 + (math.pow(x, 2.0) * (0.022222222222222223 + (math.pow(x, 2.0) * (0.0021164021164021165 + (math.pow(x, 2.0) * 0.00021164021164021165))))))
function code(x)
	return Float64(x * Float64(0.3333333333333333 + Float64((x ^ 2.0) * Float64(0.022222222222222223 + Float64((x ^ 2.0) * Float64(0.0021164021164021165 + Float64((x ^ 2.0) * 0.00021164021164021165)))))))
end
function tmp = code(x)
	tmp = x * (0.3333333333333333 + ((x ^ 2.0) * (0.022222222222222223 + ((x ^ 2.0) * (0.0021164021164021165 + ((x ^ 2.0) * 0.00021164021164021165))))));
end
code[x_] := N[(x * N[(0.3333333333333333 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(0.022222222222222223 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(0.0021164021164021165 + N[(N[Power[x, 2.0], $MachinePrecision] * 0.00021164021164021165), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot \left(0.0021164021164021165 + {x}^{2} \cdot 0.00021164021164021165\right)\right)\right)
\end{array}
Derivation
  1. Initial program 6.9%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.4%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot \left(0.0021164021164021165 + 0.00021164021164021165 \cdot {x}^{2}\right)\right)\right)} \]
  4. Step-by-step derivation
    1. *-commutative99.4%

      \[\leadsto x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot \left(0.0021164021164021165 + \color{blue}{{x}^{2} \cdot 0.00021164021164021165}\right)\right)\right) \]
  5. Simplified99.4%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot \left(0.0021164021164021165 + {x}^{2} \cdot 0.00021164021164021165\right)\right)\right)} \]
  6. Final simplification99.4%

    \[\leadsto x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot \left(0.0021164021164021165 + {x}^{2} \cdot 0.00021164021164021165\right)\right)\right) \]
  7. Add Preprocessing

Alternative 4: 99.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot 0.0021164021164021165\right)\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (*
  x
  (+
   0.3333333333333333
   (*
    (pow x 2.0)
    (+ 0.022222222222222223 (* (pow x 2.0) 0.0021164021164021165))))))
double code(double x) {
	return x * (0.3333333333333333 + (pow(x, 2.0) * (0.022222222222222223 + (pow(x, 2.0) * 0.0021164021164021165))));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x * (0.3333333333333333d0 + ((x ** 2.0d0) * (0.022222222222222223d0 + ((x ** 2.0d0) * 0.0021164021164021165d0))))
end function
public static double code(double x) {
	return x * (0.3333333333333333 + (Math.pow(x, 2.0) * (0.022222222222222223 + (Math.pow(x, 2.0) * 0.0021164021164021165))));
}
def code(x):
	return x * (0.3333333333333333 + (math.pow(x, 2.0) * (0.022222222222222223 + (math.pow(x, 2.0) * 0.0021164021164021165))))
function code(x)
	return Float64(x * Float64(0.3333333333333333 + Float64((x ^ 2.0) * Float64(0.022222222222222223 + Float64((x ^ 2.0) * 0.0021164021164021165)))))
end
function tmp = code(x)
	tmp = x * (0.3333333333333333 + ((x ^ 2.0) * (0.022222222222222223 + ((x ^ 2.0) * 0.0021164021164021165))));
end
code[x_] := N[(x * N[(0.3333333333333333 + N[(N[Power[x, 2.0], $MachinePrecision] * N[(0.022222222222222223 + N[(N[Power[x, 2.0], $MachinePrecision] * 0.0021164021164021165), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot 0.0021164021164021165\right)\right)
\end{array}
Derivation
  1. Initial program 6.9%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.4%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + 0.0021164021164021165 \cdot {x}^{2}\right)\right)} \]
  4. Step-by-step derivation
    1. *-commutative99.4%

      \[\leadsto x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + \color{blue}{{x}^{2} \cdot 0.0021164021164021165}\right)\right) \]
  5. Simplified99.4%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot 0.0021164021164021165\right)\right)} \]
  6. Final simplification99.4%

    \[\leadsto x \cdot \left(0.3333333333333333 + {x}^{2} \cdot \left(0.022222222222222223 + {x}^{2} \cdot 0.0021164021164021165\right)\right) \]
  7. Add Preprocessing

Alternative 5: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot \left(0.3333333333333333 + {x}^{2} \cdot 0.022222222222222223\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (* x (+ 0.3333333333333333 (* (pow x 2.0) 0.022222222222222223))))
double code(double x) {
	return x * (0.3333333333333333 + (pow(x, 2.0) * 0.022222222222222223));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x * (0.3333333333333333d0 + ((x ** 2.0d0) * 0.022222222222222223d0))
end function
public static double code(double x) {
	return x * (0.3333333333333333 + (Math.pow(x, 2.0) * 0.022222222222222223));
}
def code(x):
	return x * (0.3333333333333333 + (math.pow(x, 2.0) * 0.022222222222222223))
function code(x)
	return Float64(x * Float64(0.3333333333333333 + Float64((x ^ 2.0) * 0.022222222222222223)))
end
function tmp = code(x)
	tmp = x * (0.3333333333333333 + ((x ^ 2.0) * 0.022222222222222223));
end
code[x_] := N[(x * N[(0.3333333333333333 + N[(N[Power[x, 2.0], $MachinePrecision] * 0.022222222222222223), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(0.3333333333333333 + {x}^{2} \cdot 0.022222222222222223\right)
\end{array}
Derivation
  1. Initial program 6.9%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.2%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + 0.022222222222222223 \cdot {x}^{2}\right)} \]
  4. Final simplification99.2%

    \[\leadsto x \cdot \left(0.3333333333333333 + {x}^{2} \cdot 0.022222222222222223\right) \]
  5. Add Preprocessing

Alternative 6: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 0.022222222222222223 \cdot {x}^{3} + x \cdot 0.3333333333333333 \end{array} \]
(FPCore (x)
 :precision binary64
 (+ (* 0.022222222222222223 (pow x 3.0)) (* x 0.3333333333333333)))
double code(double x) {
	return (0.022222222222222223 * pow(x, 3.0)) + (x * 0.3333333333333333);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (0.022222222222222223d0 * (x ** 3.0d0)) + (x * 0.3333333333333333d0)
end function
public static double code(double x) {
	return (0.022222222222222223 * Math.pow(x, 3.0)) + (x * 0.3333333333333333);
}
def code(x):
	return (0.022222222222222223 * math.pow(x, 3.0)) + (x * 0.3333333333333333)
function code(x)
	return Float64(Float64(0.022222222222222223 * (x ^ 3.0)) + Float64(x * 0.3333333333333333))
end
function tmp = code(x)
	tmp = (0.022222222222222223 * (x ^ 3.0)) + (x * 0.3333333333333333);
end
code[x_] := N[(N[(0.022222222222222223 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(x * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.022222222222222223 \cdot {x}^{3} + x \cdot 0.3333333333333333
\end{array}
Derivation
  1. Initial program 6.9%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.2%

    \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 + 0.022222222222222223 \cdot {x}^{2}\right)} \]
  4. Step-by-step derivation
    1. +-commutative99.2%

      \[\leadsto x \cdot \color{blue}{\left(0.022222222222222223 \cdot {x}^{2} + 0.3333333333333333\right)} \]
    2. distribute-lft-in99.2%

      \[\leadsto \color{blue}{x \cdot \left(0.022222222222222223 \cdot {x}^{2}\right) + x \cdot 0.3333333333333333} \]
    3. *-commutative99.2%

      \[\leadsto x \cdot \color{blue}{\left({x}^{2} \cdot 0.022222222222222223\right)} + x \cdot 0.3333333333333333 \]
    4. associate-*r*99.2%

      \[\leadsto \color{blue}{\left(x \cdot {x}^{2}\right) \cdot 0.022222222222222223} + x \cdot 0.3333333333333333 \]
    5. unpow299.2%

      \[\leadsto \left(x \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot 0.022222222222222223 + x \cdot 0.3333333333333333 \]
    6. cube-mult99.2%

      \[\leadsto \color{blue}{{x}^{3}} \cdot 0.022222222222222223 + x \cdot 0.3333333333333333 \]
  5. Applied egg-rr99.2%

    \[\leadsto \color{blue}{{x}^{3} \cdot 0.022222222222222223 + x \cdot 0.3333333333333333} \]
  6. Final simplification99.2%

    \[\leadsto 0.022222222222222223 \cdot {x}^{3} + x \cdot 0.3333333333333333 \]
  7. Add Preprocessing

Alternative 7: 98.8% accurate, 15.3× speedup?

\[\begin{array}{l} \\ \frac{1}{3 \cdot \frac{1}{x}} \end{array} \]
(FPCore (x) :precision binary64 (/ 1.0 (* 3.0 (/ 1.0 x))))
double code(double x) {
	return 1.0 / (3.0 * (1.0 / x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 / (3.0d0 * (1.0d0 / x))
end function
public static double code(double x) {
	return 1.0 / (3.0 * (1.0 / x));
}
def code(x):
	return 1.0 / (3.0 * (1.0 / x))
function code(x)
	return Float64(1.0 / Float64(3.0 * Float64(1.0 / x)))
end
function tmp = code(x)
	tmp = 1.0 / (3.0 * (1.0 / x));
end
code[x_] := N[(1.0 / N[(3.0 * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{3 \cdot \frac{1}{x}}
\end{array}
Derivation
  1. Initial program 6.9%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. frac-sub3.4%

      \[\leadsto \color{blue}{\frac{1 \cdot \tan x - x \cdot 1}{x \cdot \tan x}} \]
    2. *-rgt-identity3.4%

      \[\leadsto \frac{1 \cdot \tan x - x \cdot 1}{\color{blue}{\left(x \cdot 1\right)} \cdot \tan x} \]
    3. metadata-eval3.4%

      \[\leadsto \frac{1 \cdot \tan x - x \cdot 1}{\left(x \cdot \color{blue}{\frac{1}{1}}\right) \cdot \tan x} \]
    4. div-inv3.4%

      \[\leadsto \frac{1 \cdot \tan x - x \cdot 1}{\color{blue}{\frac{x}{1}} \cdot \tan x} \]
    5. associate-/r*6.9%

      \[\leadsto \color{blue}{\frac{\frac{1 \cdot \tan x - x \cdot 1}{\frac{x}{1}}}{\tan x}} \]
    6. *-un-lft-identity6.9%

      \[\leadsto \frac{\frac{\color{blue}{\tan x} - x \cdot 1}{\frac{x}{1}}}{\tan x} \]
    7. *-rgt-identity6.9%

      \[\leadsto \frac{\frac{\tan x - \color{blue}{x}}{\frac{x}{1}}}{\tan x} \]
    8. div-inv6.9%

      \[\leadsto \frac{\frac{\tan x - x}{\color{blue}{x \cdot \frac{1}{1}}}}{\tan x} \]
    9. metadata-eval6.9%

      \[\leadsto \frac{\frac{\tan x - x}{x \cdot \color{blue}{1}}}{\tan x} \]
    10. *-rgt-identity6.9%

      \[\leadsto \frac{\frac{\tan x - x}{\color{blue}{x}}}{\tan x} \]
  4. Applied egg-rr6.9%

    \[\leadsto \color{blue}{\frac{\frac{\tan x - x}{x}}{\tan x}} \]
  5. Taylor expanded in x around 0 36.3%

    \[\leadsto \frac{\frac{\color{blue}{0.3333333333333333 \cdot {x}^{3}}}{x}}{\tan x} \]
  6. Step-by-step derivation
    1. clear-num36.3%

      \[\leadsto \color{blue}{\frac{1}{\frac{\tan x}{\frac{0.3333333333333333 \cdot {x}^{3}}{x}}}} \]
    2. inv-pow36.3%

      \[\leadsto \color{blue}{{\left(\frac{\tan x}{\frac{0.3333333333333333 \cdot {x}^{3}}{x}}\right)}^{-1}} \]
    3. *-un-lft-identity36.3%

      \[\leadsto {\left(\frac{\color{blue}{1 \cdot \tan x}}{\frac{0.3333333333333333 \cdot {x}^{3}}{x}}\right)}^{-1} \]
    4. associate-/l*36.3%

      \[\leadsto {\left(\frac{1 \cdot \tan x}{\color{blue}{0.3333333333333333 \cdot \frac{{x}^{3}}{x}}}\right)}^{-1} \]
    5. pow136.3%

      \[\leadsto {\left(\frac{1 \cdot \tan x}{0.3333333333333333 \cdot \frac{{x}^{3}}{\color{blue}{{x}^{1}}}}\right)}^{-1} \]
    6. pow-div54.2%

      \[\leadsto {\left(\frac{1 \cdot \tan x}{0.3333333333333333 \cdot \color{blue}{{x}^{\left(3 - 1\right)}}}\right)}^{-1} \]
    7. metadata-eval54.2%

      \[\leadsto {\left(\frac{1 \cdot \tan x}{0.3333333333333333 \cdot {x}^{\color{blue}{2}}}\right)}^{-1} \]
    8. times-frac54.3%

      \[\leadsto {\color{blue}{\left(\frac{1}{0.3333333333333333} \cdot \frac{\tan x}{{x}^{2}}\right)}}^{-1} \]
    9. metadata-eval54.3%

      \[\leadsto {\left(\color{blue}{3} \cdot \frac{\tan x}{{x}^{2}}\right)}^{-1} \]
  7. Applied egg-rr54.3%

    \[\leadsto \color{blue}{{\left(3 \cdot \frac{\tan x}{{x}^{2}}\right)}^{-1}} \]
  8. Step-by-step derivation
    1. unpow-154.3%

      \[\leadsto \color{blue}{\frac{1}{3 \cdot \frac{\tan x}{{x}^{2}}}} \]
  9. Simplified54.3%

    \[\leadsto \color{blue}{\frac{1}{3 \cdot \frac{\tan x}{{x}^{2}}}} \]
  10. Taylor expanded in x around 0 98.6%

    \[\leadsto \frac{1}{3 \cdot \color{blue}{\frac{1}{x}}} \]
  11. Final simplification98.6%

    \[\leadsto \frac{1}{3 \cdot \frac{1}{x}} \]
  12. Add Preprocessing

Alternative 8: 98.9% accurate, 21.4× speedup?

\[\begin{array}{l} \\ \frac{1}{\frac{3}{x}} \end{array} \]
(FPCore (x) :precision binary64 (/ 1.0 (/ 3.0 x)))
double code(double x) {
	return 1.0 / (3.0 / x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 / (3.0d0 / x)
end function
public static double code(double x) {
	return 1.0 / (3.0 / x);
}
def code(x):
	return 1.0 / (3.0 / x)
function code(x)
	return Float64(1.0 / Float64(3.0 / x))
end
function tmp = code(x)
	tmp = 1.0 / (3.0 / x);
end
code[x_] := N[(1.0 / N[(3.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{\frac{3}{x}}
\end{array}
Derivation
  1. Initial program 6.9%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. frac-sub3.4%

      \[\leadsto \color{blue}{\frac{1 \cdot \tan x - x \cdot 1}{x \cdot \tan x}} \]
    2. *-rgt-identity3.4%

      \[\leadsto \frac{1 \cdot \tan x - x \cdot 1}{\color{blue}{\left(x \cdot 1\right)} \cdot \tan x} \]
    3. metadata-eval3.4%

      \[\leadsto \frac{1 \cdot \tan x - x \cdot 1}{\left(x \cdot \color{blue}{\frac{1}{1}}\right) \cdot \tan x} \]
    4. div-inv3.4%

      \[\leadsto \frac{1 \cdot \tan x - x \cdot 1}{\color{blue}{\frac{x}{1}} \cdot \tan x} \]
    5. associate-/r*6.9%

      \[\leadsto \color{blue}{\frac{\frac{1 \cdot \tan x - x \cdot 1}{\frac{x}{1}}}{\tan x}} \]
    6. *-un-lft-identity6.9%

      \[\leadsto \frac{\frac{\color{blue}{\tan x} - x \cdot 1}{\frac{x}{1}}}{\tan x} \]
    7. *-rgt-identity6.9%

      \[\leadsto \frac{\frac{\tan x - \color{blue}{x}}{\frac{x}{1}}}{\tan x} \]
    8. div-inv6.9%

      \[\leadsto \frac{\frac{\tan x - x}{\color{blue}{x \cdot \frac{1}{1}}}}{\tan x} \]
    9. metadata-eval6.9%

      \[\leadsto \frac{\frac{\tan x - x}{x \cdot \color{blue}{1}}}{\tan x} \]
    10. *-rgt-identity6.9%

      \[\leadsto \frac{\frac{\tan x - x}{\color{blue}{x}}}{\tan x} \]
  4. Applied egg-rr6.9%

    \[\leadsto \color{blue}{\frac{\frac{\tan x - x}{x}}{\tan x}} \]
  5. Taylor expanded in x around 0 36.3%

    \[\leadsto \frac{\frac{\color{blue}{0.3333333333333333 \cdot {x}^{3}}}{x}}{\tan x} \]
  6. Step-by-step derivation
    1. clear-num36.3%

      \[\leadsto \color{blue}{\frac{1}{\frac{\tan x}{\frac{0.3333333333333333 \cdot {x}^{3}}{x}}}} \]
    2. inv-pow36.3%

      \[\leadsto \color{blue}{{\left(\frac{\tan x}{\frac{0.3333333333333333 \cdot {x}^{3}}{x}}\right)}^{-1}} \]
    3. *-un-lft-identity36.3%

      \[\leadsto {\left(\frac{\color{blue}{1 \cdot \tan x}}{\frac{0.3333333333333333 \cdot {x}^{3}}{x}}\right)}^{-1} \]
    4. associate-/l*36.3%

      \[\leadsto {\left(\frac{1 \cdot \tan x}{\color{blue}{0.3333333333333333 \cdot \frac{{x}^{3}}{x}}}\right)}^{-1} \]
    5. pow136.3%

      \[\leadsto {\left(\frac{1 \cdot \tan x}{0.3333333333333333 \cdot \frac{{x}^{3}}{\color{blue}{{x}^{1}}}}\right)}^{-1} \]
    6. pow-div54.2%

      \[\leadsto {\left(\frac{1 \cdot \tan x}{0.3333333333333333 \cdot \color{blue}{{x}^{\left(3 - 1\right)}}}\right)}^{-1} \]
    7. metadata-eval54.2%

      \[\leadsto {\left(\frac{1 \cdot \tan x}{0.3333333333333333 \cdot {x}^{\color{blue}{2}}}\right)}^{-1} \]
    8. times-frac54.3%

      \[\leadsto {\color{blue}{\left(\frac{1}{0.3333333333333333} \cdot \frac{\tan x}{{x}^{2}}\right)}}^{-1} \]
    9. metadata-eval54.3%

      \[\leadsto {\left(\color{blue}{3} \cdot \frac{\tan x}{{x}^{2}}\right)}^{-1} \]
  7. Applied egg-rr54.3%

    \[\leadsto \color{blue}{{\left(3 \cdot \frac{\tan x}{{x}^{2}}\right)}^{-1}} \]
  8. Step-by-step derivation
    1. unpow-154.3%

      \[\leadsto \color{blue}{\frac{1}{3 \cdot \frac{\tan x}{{x}^{2}}}} \]
  9. Simplified54.3%

    \[\leadsto \color{blue}{\frac{1}{3 \cdot \frac{\tan x}{{x}^{2}}}} \]
  10. Taylor expanded in x around 0 98.6%

    \[\leadsto \frac{1}{\color{blue}{\frac{3}{x}}} \]
  11. Final simplification98.6%

    \[\leadsto \frac{1}{\frac{3}{x}} \]
  12. Add Preprocessing

Alternative 9: 98.8% accurate, 35.7× speedup?

\[\begin{array}{l} \\ x \cdot 0.3333333333333333 \end{array} \]
(FPCore (x) :precision binary64 (* x 0.3333333333333333))
double code(double x) {
	return x * 0.3333333333333333;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x * 0.3333333333333333d0
end function
public static double code(double x) {
	return x * 0.3333333333333333;
}
def code(x):
	return x * 0.3333333333333333
function code(x)
	return Float64(x * 0.3333333333333333)
end
function tmp = code(x)
	tmp = x * 0.3333333333333333;
end
code[x_] := N[(x * 0.3333333333333333), $MachinePrecision]
\begin{array}{l}

\\
x \cdot 0.3333333333333333
\end{array}
Derivation
  1. Initial program 6.9%

    \[\frac{1}{x} - \frac{1}{\tan x} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 98.6%

    \[\leadsto \color{blue}{0.3333333333333333 \cdot x} \]
  4. Final simplification98.6%

    \[\leadsto x \cdot 0.3333333333333333 \]
  5. Add Preprocessing

Developer target: 99.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|x\right| < 0.026:\\ \;\;\;\;\frac{x}{3} \cdot \left(1 + \frac{x \cdot x}{15}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} - \frac{1}{\tan x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (< (fabs x) 0.026)
   (* (/ x 3.0) (+ 1.0 (/ (* x x) 15.0)))
   (- (/ 1.0 x) (/ 1.0 (tan x)))))
double code(double x) {
	double tmp;
	if (fabs(x) < 0.026) {
		tmp = (x / 3.0) * (1.0 + ((x * x) / 15.0));
	} else {
		tmp = (1.0 / x) - (1.0 / tan(x));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (abs(x) < 0.026d0) then
        tmp = (x / 3.0d0) * (1.0d0 + ((x * x) / 15.0d0))
    else
        tmp = (1.0d0 / x) - (1.0d0 / tan(x))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (Math.abs(x) < 0.026) {
		tmp = (x / 3.0) * (1.0 + ((x * x) / 15.0));
	} else {
		tmp = (1.0 / x) - (1.0 / Math.tan(x));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if math.fabs(x) < 0.026:
		tmp = (x / 3.0) * (1.0 + ((x * x) / 15.0))
	else:
		tmp = (1.0 / x) - (1.0 / math.tan(x))
	return tmp
function code(x)
	tmp = 0.0
	if (abs(x) < 0.026)
		tmp = Float64(Float64(x / 3.0) * Float64(1.0 + Float64(Float64(x * x) / 15.0)));
	else
		tmp = Float64(Float64(1.0 / x) - Float64(1.0 / tan(x)));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (abs(x) < 0.026)
		tmp = (x / 3.0) * (1.0 + ((x * x) / 15.0));
	else
		tmp = (1.0 / x) - (1.0 / tan(x));
	end
	tmp_2 = tmp;
end
code[x_] := If[Less[N[Abs[x], $MachinePrecision], 0.026], N[(N[(x / 3.0), $MachinePrecision] * N[(1.0 + N[(N[(x * x), $MachinePrecision] / 15.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] - N[(1.0 / N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| < 0.026:\\
\;\;\;\;\frac{x}{3} \cdot \left(1 + \frac{x \cdot x}{15}\right)\\

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024079 
(FPCore (x)
  :name "invcot (example 3.9)"
  :precision binary64
  :pre (and (< -0.026 x) (< x 0.026))

  :alt
  (if (< (fabs x) 0.026) (* (/ x 3.0) (+ 1.0 (/ (* x x) 15.0))) (- (/ 1.0 x) (/ 1.0 (tan x))))

  (- (/ 1.0 x) (/ 1.0 (tan x))))